Results 1 to 7 of 7

Thread: how do i use for each

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2000
    Location
    Phils
    Posts
    4
    if i got a variable MyServer , MyStatus , MyQuitMsg ...
    how do i use 'for each' to see if it's NULL ?
    --
    it's really hard to be a man in a world that's full of beauty.

  2. #2
    Guest
    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

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2000
    Location
    Phils
    Posts
    4

    can you give me a sample?

    ey... can u give me a sample? cause it's not just 3 variables... i'm trying to check lots of vars..
    --
    it's really hard to be a man in a world that's full of beauty.

  4. #4
    Guest
    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
    The code will go through all 100 variables (0 - 99) checking each one to see if it is empty.


    Sunny

  5. #5

    Thread Starter
    New Member
    Join Date
    Sep 2000
    Location
    Phils
    Posts
    4
    thanks
    --
    it's really hard to be a man in a world that's full of beauty.

  6. #6
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    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
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  7. #7
    Guest

    Smile

    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"?).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width