Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
daleus
Visitor

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
0 Kudos
3 REPLIES 3
RokuJoel
Binge Watcher

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
0 Kudos
daleus
Visitor

Re: String Concatenation

Oh, I see.

Thanks for clearing that up.
0 Kudos
EnTerr
Roku Guru

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
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.