[solved] Can't mix strings with numerical values

Just starting out? Need help? Post your questions and find answers here.
falsam
Posts: 286
Joined: Mon May 05, 2014 9:49 pm
Location: France
Contact:

[solved] Can't mix strings with numerical values

Post by falsam »

Hello there ^^

I have a problem with this code.

Code: Select all

;-New message from an user
  !socket.on('usermessage', function(v_data) {
  !   v_username = v_data.username;
  !   v_usermessage = v_data.message;
  AddGadgetItem(#userHistoric, 0,  username + Chr(10) + usermessage)
  !});
AddGadgetItem generates an error message
Can't mix strings with numerical values.
If I replace

Code: Select all

AddGadgetItem(#userHistoric, 0,  username + Chr(10) + usermessage)
with

Code: Select all

AddGadgetItem(#userHistoric, 0,  "" + username + Chr(10) + usermessage)
I do not have this error message.

Thanks for your help.
Last edited by falsam on Tue May 31, 2016 2:38 pm, edited 1 time in total.

➽ Windows 11 - jdk-11.0.2 - SB 3.00 - Android 15
https://falsam.com

Sorry for my poor english
Fred
Site Admin
Posts: 1821
Joined: Mon Feb 24, 2014 10:51 am

Re: Can't mix strings with numerical values

Post by Fred »

You need to declare username with a string type before using it in inline JS. When not using Str(), the string expression needs to start with a string value, not a numeric one.
User avatar
Peter
Posts: 1197
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: Can't mix strings with numerical values

Post by Peter »

Hello falsam,

what about this one?

Code: Select all

;-New message from an user
  Define username.s
  Define usermessage.s
  !socket.on('usermessage', function(v_data) {
  !   v_username = v_data.username;
  !   v_usermessage = v_data.message;
  AddGadgetItem(#userHistoric, 0,  username + Chr(10) + usermessage)
  !});
Greetings ... Peter
falsam
Posts: 286
Joined: Mon May 05, 2014 9:49 pm
Location: France
Contact:

Re: Can't mix strings with numerical values

Post by falsam »

Thanks Fred & Peter. Problem solved.

➽ Windows 11 - jdk-11.0.2 - SB 3.00 - Android 15
https://falsam.com

Sorry for my poor english
Post Reply