daleus
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-23-2011
02:00 AM
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:
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.
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 3

RokuJoel
Binge Watcher
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-23-2011
09:37 AM
Re: String Concatenation
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
- Joel
daleus
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-23-2011
11:09 AM
Re: String Concatenation
Oh, I see.
Thanks for clearing that up.
Thanks for clearing that up.
EnTerr
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-23-2011
10:00 PM
Re: String Concatenation
"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