Trying to run a series of variables through a counter loop… I cant figure out how to merge the basic variable and the number… (var1, var2, var3, etc)
Need help right after the comment, please
Dim variable as string
Dim var1 as string
Dim var as string
Var1 = ABCDE
Dim y as integer
Y = 1
// help here
Variable = var + y //????? How do I join a variable and a number to make one new variable
Do
Textfield.text = variable.totext
Y = y + 1
If y>3 then exit
loop
[quote=416674:@John Marshall]Trying to run a series of variables through a counter loop… I cant figure out how to merge the basic variable and the number… (var1, var2, var3, etc)
Need help right after the comment, please
Dim variable as string
Dim var1 as string
Dim var as string
Var1 = ABCDE
Dim y as integer
Y = 1
// help here
Variable = var + y //????? How do I join a variable and a number to make one new variable
Do
Textfield.text = variable.totext
Y = y + 1
If y>3 then exit
loop
[/code][/quote]
What are you wanting to achieve with:
[code]Variable = var + y //????? How do I join a variable and a number to make one new variable
What do you want Variable to contain? If you want to concatenate an integer to a string, you’d need to do:
Variable = var + y.totext
Also, with:
Textfield.text = variable.totext
Since textfield.text expects a string, and Variable is already a string, there’s no need to convert Variable to text using .totext.
[quote=416674:@John Marshall]
// help here
Variable = var + y //??? How do I join a variable and a number to make one new variable
Do
Textfield.text = variable.totext
Y = y + 1
If y>3 then exit
loop
[/code][/quote]
For starters John, a variable can be a number or a string as you may well know.
From what you posted in your original post, you declared var as a string, yet you didn’t assign it a value!
I’ve adjusted the code to a include the assignment of “Var”. btw., it’s good practice to try to stick with capitalisation. Although, as far as I’m aware Xojo doesn’t care if you code “Var1” or “vAR1” - they are treated one and the same, it’s not case sensitive. Nevertheless, it makes it easier for you and others to read if you stick to a style
[code] Dim variable as string
Dim var1 as string
Dim var as string
Var1 = “ABCDE”
var = “XYZ”
Dim y as integer
Y = 1
// shown here:
variable = var + Str(y) // This is one way to join (concatenate) a string and a number to make one new (string) variable.
Textfield1.text = variable[/code]
This works as expected using a push button and a text field. Adding a loop (to increment the number) from this point is easy enough.
If you explain more, then you’ll get better help. This is as far as I can help