ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   variable nam in VB (https://www.excelbanter.com/excel-programming/424136-variable-nam-vbulletin.html)

Brettjg

variable nam in VB
 
I've specified
Dim mem1, mem2, mem3
counter = 1

and I want to run through a loop such as
Do while counter <= 3
Msgbox "Name = " & mem & counter
counter = counter + 1
Loop

to show 3 Msgboxes, but VB doesn't like "mem & counter".

How do I express "mem & counter please?
Also, what do you actually call things like mem1, mem2? Are they simply
called dimensions or..........
Regards, Bret


Gary Keramidas[_2_]

variable nam in VB
 
not sure what you're trying to do, but maybe this will help

Sub test()
Dim mem(3) As String
Dim counter As Long

Do While counter <= 2
MsgBox "Name = " & mem(counter) & counter
counter = counter + 1
Loop
End Sub

--


Gary

"Brettjg" wrote in message
...
I've specified
Dim mem1, mem2, mem3
counter = 1

and I want to run through a loop such as
Do while counter <= 3
Msgbox "Name = " & mem & counter
counter = counter + 1
Loop

to show 3 Msgboxes, but VB doesn't like "mem & counter".

How do I express "mem & counter please?
Also, what do you actually call things like mem1, mem2? Are they simply
called dimensions or..........
Regards, Bret



Brettjg

variable nam in VB
 
Thanks very much Gary, that was exactly what I needed. Brett

"Gary Keramidas" wrote:

not sure what you're trying to do, but maybe this will help

Sub test()
Dim mem(3) As String
Dim counter As Long

Do While counter <= 2
MsgBox "Name = " & mem(counter) & counter
counter = counter + 1
Loop
End Sub

--


Gary

"Brettjg" wrote in message
...
I've specified
Dim mem1, mem2, mem3
counter = 1

and I want to run through a loop such as
Do while counter <= 3
Msgbox "Name = " & mem & counter
counter = counter + 1
Loop

to show 3 Msgboxes, but VB doesn't like "mem & counter".

How do I express "mem & counter please?
Also, what do you actually call things like mem1, mem2? Are they simply
called dimensions or..........
Regards, Bret





All times are GMT +1. The time now is 08:22 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com