I made a sandbox app to test simple pieces of code and I found out something interesting about string concatenation. I'm curious as to why it's implemented in this way.
The code:
sub RunUserInterface()
mainScreen = CreateObject("roPosterScreen")
msgPort = CreateObject("roMessagePort")
mainScreen.SetMessagePort(msgPort)
adjective = "funny"
mainScreen.ShowMessage("this is a "+adjective+" test") ' *** concatenation works correctly
print "this is a "+adjective+" test" ' *** concatenation works correctly
mainScreen.Show()
while true
msg = Wait(0, mainScreen.GetMessagePort())
if type(msg) = "roPosterScreenEvent"
if msg.isScreenClosed()
exit while
end if
end if
end while
mainScreen.Close()
end sub
You can see that both the ShowMessage() function and the print statement uses a
plus (+) sign to concatenation strings. I am able to change the code so that the print statement uses a
semi-colon (;) instead, but if I also try that on the ShowMessage() function, I get a syntax error.
sub RunUserInterface()
mainScreen = CreateObject("roPosterScreen")
msgPort = CreateObject("roMessagePort")
mainScreen.SetMessagePort(msgPort)
adjective = "funny"
mainScreen.ShowMessage("this is a ";adjective;" test") ' *** concatenation does not work (syntax error)
print "this is a ";adjective;" test" ' *** concatenation works correctly
mainScreen.Show()
while true
msg = Wait(0, mainScreen.GetMessagePort())
if type(msg) = "roPosterScreenEvent"
if msg.isScreenClosed()
exit while
end if
end if
end while
mainScreen.Close()
end sub