View Full Version : Basic Scripting Question

01 January 2007, 02:32 AM
Dear XSI users.....

I am getting into scripting and sure it speeds up my overall workflow.
However since my scripting level is purely at "copy-paste-edit",
sometimes I am going nowhere but wasting time.

For instance I couldn't figure out the folowing.

Here is what I want to achive with this script
1) setup user input and set it as variable oValue
2) simple math (oValue + 12)
3) print the result

I typed in 12 as my input and if I scripted correctly,
I should get 24 right? (12+12=24)

Yes, VBS is fine but Jscript is returning weird result.
Can anybody please have a look at it and teach me
what I am doing wrong?
oValue = XSIInputBox( "How many?", "?", "0.0" )
z = oValue + 12
LogMessage z

' INFO : 24
var oValue = XSIInputBox( "How many?", "?", "0.0" );
var z = oValue+12
LogMessage (z)

// INFO : 1212

12+12 = 1212 ???

01 January 2007, 02:49 AM
In JScript there are no difference between number and string.

XSIInputBox return a string -> your oValue treated as string, so your oValue + 12 is read as string concat.

How about forcing it to be number using Number(oValue) which will convert the string into number.


01 January 2007, 02:54 AM
misterdi beat me...

You can check out for some quick JScript info:

Here's some more info on JScript Type Conversion:

01 January 2007, 03:02 AM
It's because JScript (and javascript) have a bad habit of treating numbers as string when using the '+' op.

var oValue = XSIInputBox( "How many?", "?", "0.0" );
var tmp = oValue -1 + 1; // force JScript to treat this as a number
var z = tmp + 12
LogMessage (z)

/edit - everyone beat me :)

01 January 2007, 03:02 AM
Never expected a reply this fast.....
Thank you so much misterdi & TonyEdwards & 5quid
Number(oValue) and var tmp = oValue -l + l;
worked !!!
Thanks again!!!

CGTalk Moderation
01 January 2007, 03:02 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.