Results 1 to 4 of 4
  1. #1
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Passing Variable i (XP; SP3)

    I am having an issue passing the variable "i" in the FOR statement. In essence each time the message box appears it should display "one, two, three and etc".

    I have tried numerous combinations but have come up blank.

    Sub Test_One()
    Dim i As Integer
    oFile1 = "One"
    oFile2 = "Two"
    oFile3 = "Three"
    oFile4 = "Four"
    oFile5 = "Five"

    For i = 1 To 5
    MsgBox "oFile" & i
    Next i
    End Sub

    Thanks,
    John

  2. #2
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Passing Variable i (XP; SP3)

    What you are doing is concatenating the value of the variable i with the string "oFile" and displaying the result of the concatenation. To do what you want you would need to use an array, like this:

    <code>
    Dim I As Long
    Dim oFile(1 To 5) As String
    oFile(1) = "One"
    oFile(2) = "Two"
    oFile(3) = "Three"
    oFile(4) = "Four"
    oFile(5) = "Five"
    For I = 1 To 5
    MsgBox oFile(I)
    Next I
    </code>
    Legare Coleman

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Passing Variable i (XP; SP3)

    You could use an array variable:

    Sub Test_One()
    Dim i As Integer
    Dim oFile(1 To 5) As String

    oFile(1) = "One"
    oFile(2) = "Two"
    oFile(3) = "Three"
    oFile(4) = "Four"
    oFile(5) = "Five"

    For i = 1 To 5
    MsgBox oFile(i)
    Next i
    End Sub

  4. #4
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Passing Variable i (XP; SP3)

    Legare/Hans,

    Thank you very much. I had a thought the solution would be some type of an array. I just didn't know how to go about it.

    Regards,
    John

Posting Permissions

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