|
|
(61 versioni intermedie di uno stesso utente non sono mostrate) |
Riga 1: |
Riga 1: |
− | Esporremo qui il caso in cui l'array non è dimensionato a priori, ma lo sia successivamente in modo esplicito o in modo dinamico.
| + | #REDIRECT [[Array:_creazione,_modifica_e_riempimento]] |
− | | |
− | | |
− | ==Array senza alcun dimensionamento==
| |
− | | |
− | '''Public''' Sub Button1_Click()
| |
− |
| |
− | Dim nu As Byte
| |
− | Dim multdimArr As New Byte[] <FONT color=#006400>' ''dichiara l'array, ma senza dimensionarlo''</font>
| |
− |
| |
− | For nu = 0 To 37
| |
− | multdimArr.Add(nu)
| |
− | Next
| |
− |
| |
− | <FONT color=#006400>' ''verifica:</font>
| |
− | For nu = 0 To 37
| |
− | Print multdimArr[nu]
| |
− | Next
| |
− |
| |
− | '''End'''
| |
− | | |
− | o anche:
| |
− | | |
− | '''Public''' Sub Button1_Click()
| |
− |
| |
− | Dim nu As Byte
| |
− | Dim multdimArr As Byte[] <FONT color=#006400>' ''dichiara l'array, ma senza dimensionarlo''</font>
| |
− |
| |
− | For nu = 0 To 37
| |
− | multdimArr = New Byte[nu]
| |
− | multdimArr.Add(nu)
| |
− | Next
| |
− |
| |
− |
| |
− | For nu = 0 To 37
| |
− | Print multdimArr[nu]
| |
− | Next
| |
− |
| |
− | '''End'''
| |
− | | |
− | | |
− | | |
− | ==Array con dimensionamento successivo<font>==
| |
− | | |
− | <FONT color=#006400>' ''Gambas class file''</font>
| |
− |
| |
− |
| |
− | '''Public''' Sub Button1_Click()
| |
− |
| |
− | Dim ind1 As Integer = 38
| |
− | Dim nu As Integer
| |
− | Dim multdimArr As Integer[] <FONT color=#006400>' ''dichiara l'array, ma senza dimensionarlo''</font>
| |
− |
| |
− | <FONT color=#006400>' ''dimensiona "ora" l'array:''</font>
| |
− | multdimArr = New Integer[ind1]
| |
− |
| |
− | For nu = 0 To multdimArr.Max
| |
− | <FONT color=#006400>' '' riempie ogni elemento dell'array:''</font>
| |
− | multdimArr[nu] = nu
| |
− | Print multdimArr[nu]
| |
− | Next
| |
− |
| |
− | '''End'''
| |
− | | |
− | | |
− | Esempio con un array multidimensionale:
| |
− | '''Public''' Sub Button1_Click()
| |
− |
| |
− | <FONT color=#B22222>Dim multdimArr As Integer[]</font>
| |
− | Dim rig, col As Integer
| |
− | Dim nuR, nuC As Integer
| |
− |
| |
− | <FONT color=#006400>' ''dimensiona "ora" l'array:''</font>
| |
− | rig = InputBox("Inserisci tu la dimensione delle righe dell'array:")
| |
− | col = InputBox("Inserisci tu la dimensione delle colonne dell'array:")
| |
− |
| |
− | <FONT color=#B22222>multdimArr = New Integer[rig, col]</font>
| |
− |
| |
− |
| |
− | For nuR = 0 to rig - 1
| |
− | For nuC = 0 To col - 1
| |
− | multdimArr[nuR, nuC] = nuC
| |
− | Print multdimArr[nuR, nuC]
| |
− | Next
| |
− | Next
| |
− |
| |
− | '''End'''
| |