Ciao a tutti ho diverse applicazioni che usano la seguente procedura:
Private hControl As Object
Private Px As New Integer[]
Private Py As New Integer[]
Private Pw As New Integer[]
Private Ph As New Integer[]
Private Fs As New Integer[]
Private Mw As Integer
Private Mh As Integer
Private ctrx As Boolean
Private codute As Integer
Private codmis As Integer
Private xlab As Integer
Private xdate As String
Public mydir As String = Application.Path & "/" & "Out"
Public trimestre As Integer
Public progres As String
Public Sub Form_Open()
For Each hControl In Me.Controls
Px.Add(hControl.x)
Py.Add(hControl.y)
Pw.Add(hControl.w)
Ph.Add(hControl.h)
Fs.Add(hControl.Font.size)
Next
Mw = Me.W
Mh = Me.h
Mod_Open.controlla_db()
carica_utenti
End
Public Sub Form_Resize()
Dim cx, cy As Float
Dim Nw, Nh, i As Integer
Nw = Me.W
Nh = Me.h
Cx = Nw / Mw
Cy = Nh / Mh
i = 0
For Each hControl In Me.Controls
hControl.x = Px[i] * Cx
hControl.y = Py[i] * Cy
hControl.w = Pw[i] * Cx
hControl.h = Ph[i] * Cy
hControl.Font.size = Fs[i] * Cx
Inc i
Next
End
ha sempre funzionato alla perfezione ma da oggi alla riga ' For Each hControl In Me.Controls' mi restituisce "Loop variable cannot be global" , avete idea cosa sia successo? Grazie :ciao:
Usare una globale per quello non era una buona pratica già da prima.
Comunque ora è vietata perché sono avvenuti importanti cambiamenti.
Ad esempio adesso puoi definire le variabili dove vuoi e non solo all'inizio della procedura.
Nel tuo caso puoi scrivere una cosa come questa:
For Each hcontrol As Control In Me.Controls
Print hcontrol.Name
Next
Si ho letto qualcosa qualche giorno fa', quindi da oggi va dichiarata la anche in questo modo su tutte le procedure ? se ho capito bene
Public Sub Form_Open()
dim hControl As Object
For Each hControl In Me.Controls
print hcontrol.name
Next
End
Public Sub Form_Resize()
dim hControl As Object
For Each hControl In Me.Controls
print hcontrol.name
Next
End
Si ho letto qualcosa qualche giorno fa', quindi da oggi va dichiarata la anche in questo modo su tutte le procedure ? se ho capito bene
Public Sub Form_Open()
dim hControl As Object
For Each hControl In Me.Controls
print hcontrol.name
Next
End
Public Sub Form_Resize()
dim hControl As Object
For Each hControl In Me.Controls
print hcontrol.name
Next
End
Così è come è sempre stato :-\
Per i loop non è obbligatorio il dim, puoi dichiarare come ti ho scritto sopra, e cioè:
For Each hcontrol As Object In Me.Controls
Print hcontrol.Name
Next
Visto che preferisci l'object...
Tanto per essere più chiaro possibile circa le dichiarazioni delle variabili locali:
Public Sub Form_Open()
Dim s As String = "10" ' Prima era possibile dichiarare solo in questo luogo (inizio routine) '
' Solo per i loop '
For Each hcontrol As Control In Me.Controls ' Ora si può fare anche così... '
Print hcontrol.Name
Next
' In ogni dove '
Dim i As Integer = CInt(s) '...è così '
If i = 10 Then Print "ALLELUIA"
End