if i got a variable MyServer , MyStatus , MyQuitMsg ...
how do i use 'for each' to see if it's NULL ?
Printable View
if i got a variable MyServer , MyStatus , MyQuitMsg ...
how do i use 'for each' to see if it's NULL ?
When you use the For Each statement, I don't there is a easy way to check variables of different names as the For Each statement will be looping back to the same name everytime, but it can easily be done with variable arrays.
Sunny
ey... can u give me a sample? cause it's not just 3 variables... i'm trying to check lots of vars..
The code will go through all 100 variables (0 - 99) checking each one to see if it is empty.Code:Private Sub Form_Load()
Dim var(99) As String
Dim i, count As Integer
For i = 0 To 99
If var(i) = "" Then
count = count + 1
End If
Next i
MsgBox count & " variables were empty"
End Sub
Sunny
thanks
Code:'using a collection for storing variables
Public myVar As Collection
Private Sub Form_Load()
Set myVar = New Collection
myVar.Add ""
myVar.Add "Wayne"
myVar.Add "Jim"
myVar.Add ""
myVar.Add "Juillet"
myVar.Add "Rosie"
End Sub
Private Sub Command1_Click()
'are any of the variables empty
Dim i As Integer
For i = 1 To myVar.Count
If myVar(i) = "" Then
MsgBox "myVar " & i & "= nothing!"
End If
Next i
End Sub
Using a collection would a better choice for ease of use, unless you really wanted to use the For Each statement ("how do i use for each"?).