Variabilized Variable

A

Al

is there a way for me to make the following procedure work?
As I go through the loop each time, i'd like the
messagebox to pop up with the value denoted by
the variable. So the first time i go through,
the message TWO should pop up in the messagebox.
Thanks in advance.


SUB TEST
DIM M1,M2,M3 AS STRING
dim x as integer

M1="TWO"
M2="THREE"
M3="FOUR"

FOR X = 1 TO 3
MSGBOX "M"& X

NEXT X

END SUB
 
T

Tom Ogilvy

SUB TEST
DIM M(1 to 3) as String
dim x as integer

M(1)="TWO"
M(2)="THREE"
M(3)="FOUR"

FOR X = 1 TO 3
MSGBOX M(X)

NEXT X

END SUB
 
C

cmdecker2

Create an array:

Sub TEST()
Dim M1, M2, M3 As String
Dim x As Integer
Dim m(20) As Variant
m(1) = "TWO"
m(2) = "THREE"
m(3) = "FOUR"

For x = 1 To 3
MsgBox (m(x))
Next
End Sub

Carl
 
G

Guest

OR:

Sub xx
dim item as variant
for each item in Array("TWO","THREE","FOUR")
MsgBox item
next
End Sub

' You can add or remove items from the Array list a will.
 
A

Al

Thanks Tom!! Hadn't thought about using an array.
-----Original Message-----
SUB TEST
DIM M(1 to 3) as String
dim x as integer

M(1)="TWO"
M(2)="THREE"
M(3)="FOUR"

FOR X = 1 TO 3
MSGBOX M(X)

NEXT X

END SUB

--
Regards,
Tom Ogilvy




.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top