Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dim statement in loop 1

Status
Not open for further replies.

GP

IS-IT--Management
Jan 14, 2002
61
GB
I need to declare a variable number of strings to use in some coding and wanted to declare them in a loop - how can i do this.

I tried:

intImagesWide = 3

Do Until i = intImagesWide
strimage = "strImage" & i
pthimage = "pthImage" & i
Dim strimage
Dim pthimage
i = i + 1
Loop

But it does not work. Any help please.
 
Could you use an array to hold your strings? Not sure of your question. What are the purpose of the strings?
 
GP,

Try using arrays...
Code:
Option Base 1
Sub test()
    Dim intImagesWide As Integer, strimage(3) As String, pthimage(3) As String
    intImagesWide = 3
    For i = 1 To intImagesWide
        strimage(i) = "strImage" & i
        pthimage(i) = "pthImage" & i
    Next
End Sub
:)



Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884

Skip,
 
Thanks for this, I have never used an array before.

I understand the concept of setting them up (although you have to define the size of the array with adim statement - do I just set this to a silly number strimage(100)??).

I just need to check how to use the array contents.

My original coding was going to take the strimage&i and create some text around it:

do until i = intimageswide
strHTML = strHTML & &quot; <td width='25%'></td>&quot;
strHTML = strHTML & &quot; <td><A HREF=&quot;& strImage1 & &quot;>
loop

Would I now use this as:

do until i = intimageswide
strHTML = strHTML & &quot; <td width='25%'></td>&quot;
strHTML = strHTML & &quot; <td><A HREF=&quot;& strImage(i) & &quot;>
loop
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top