Pointer function

Vars a1,a2,a3,a4, testVar As String
var x as Integer = 4
var y as Integer = 1

while y <x
testVar = “a”+x.toString

testVar = “The Text”. <<—

Wend

I used to do this as &testVar in Dbase . I don’t know what this is called ,
is there a way to do this in Xojo ?

Thx in Advance…

Roger

(Please remember to use code tags to make code easier to read. That’s three backticks before and after the code block.)

I’m not sure I understand your example, mostly because I’m not familiar with Dbase. What is the final result you seek?

Also, I’m sure this is a typo, but your While loop will never end.

Thanks Kim,

it is a pointer to a variable… If you have string vars A1, A2, A3 , then Use a Substitute var testVar…

testVar = “A”+“1”
testVar = “Text is A1”

print(a1)
Text is A1

testVar = “A”+“2”
testVar = “Text is A2”

I hope this makes sense :grinning:

Yes, but no, Xojo doesn’t allow that. There are, however, other techniques you can use to emulate that. For example, instead of a String variable, use a Dictionary. Or perhaps, if it fits your use case, use a String array.

Thx Kem …

If A1 was a property, you could do it like this, not very quick, but can be useful:

Dim myProperties() As Introspection.PropertyInfo = Introspection.GetType(Self).GetProperties
For Each pi As Introspection.PropertyInfo In myProperties
  If pi.name = "A1" Then
    system.DebugLog(pi.value(Self))
  End If
Next

You can then store pi in a variable/property of type Introspection.PropertyInfo and use it in a loop if you want the speed without the lookup cost.