I have several webpages in my project with names like webpage1, webpage2, webpage3, and so on… I would like to launch them from a black-box method. In Visual Foxpro, there is macro substitution using ampersand (&), similar to this (not the exact syntactical code but just the idea):
[code]Sub Launch(page as integer)
Dim strPage As String = “webpage” + format(page,"#")
Dim webpage As webpage
webpage = New &strPage // this is where macro substitution takes place
webpage.show
End Sub
[/code]
How to do this in Xojo? Thanking you all in advance.
You dont
There is no equivalent
A select case or something equivalent is needed
Now you might ask “why is that?”
Well
NEW requires the “name of an existing class” in order to work
But you’ll notice it is not NEW followed by STRING its “NEW ClassName”
Suppose you wrote
Dim strPage As String = "foobar123" + format(page,"#")
webpage = New &strPage // this is where macro substitution takes place
in VFP I pray to god you’d get a nice error at runtime about this
But in Xojo the class has to exist at COMPILE time to use the NEW operator
Hence that can’t work
And Xojo will strip out classes that it can figure out are NOT used - another reason computing the name wont help out at compile time
Its just a different way to do things that VFP took
Thanks for the prompt reply, Norman. I have no problem with explicit calls it’s just that I wanted to make sure if there is an “easy” or short way to do it in Xojo.