Forum Discussion

daleus's avatar
daleus
Visitor
14 years ago

String Concatenation

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

3 Replies

  • Print has features that let you format your output. Showmessage does not, so with Showmessage, you have to have create a string and pass it to the show message function like myposterscreen.ShowMessage("This is a "+chr(34)+" quote character")

    - Joel
  • "daleus" wrote:
    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


    "print" is a BASIC statement, not a function/procedural call with variable number of arguments and as such has somewhat free syntax. In particular, if i remember, "," separates printed arguments with extra spaces (or \t) - when ";" prints them "glued" together