Results 1 to 6 of 6

Thread: for loop

  1. #1
    Join Date
    Sep 2005
    Posts
    313

    Unanswered: for loop

    Hi,

    I have a question

    email1 = "......@hotmail.com"
    email2 = ".......@yahoo.com"
    email3..
    ...

    For i = 1 to num
    msgbox email & i
    next i

    I run like this code, but it only show the numbers, it cannot be shown the email address.

    For i = 1 to num
    msgbox email & cstr(i)
    next i

    I tried it, but it's still NOT work

    For i = 1 to num
    msgbox cstr(email & cstr(i))
    next i

    Not work, too.

    What's wrong with it?

    Please let me know, thanks.

  2. #2
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Lookup arrays in the help text.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  3. #3
    Join Date
    Feb 2004
    Posts
    533
    Use an array:
    Code:
    emailArray  = ("......@hotmail.com",".......@yahoo.com","someemail@aol.com")
    
    for i = 0 to ubound(emailArray) -1
     debug.print emailArray(i)
    Next
    ~

    Bill

  4. #4
    Join Date
    Sep 2005
    Posts
    313
    For example,

    I tried this,

    Dim email_array As String
    ReDim Preserve email_array(UBound(email_array) + 10)
    email_array = ("Sunny","mon")

    But, there is error of the email_array = ("Sunny","mon")

    how do I declare it?
    Thanks.

  5. #5
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    F1 -> "Using Arrays" -> Read
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  6. #6
    Join Date
    Feb 2004
    Posts
    533
    Quote Originally Posted by accessman2
    how do I declare it?
    Thanks.
    It depends on how your going to set the array. The way you have it will only work if you define the variable as a Variant data type or leave it undefined. Do not dim the array size or use redim prior to setting it using this method.

    email_array = ("Sunny","mon")

    Like Teddy suggested - take a look at the Access VB Help on Arrays. It has all the details.
    ~

    Bill

Posting Permissions

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