numeric fields

numeric fields

Post by cGlldHN3aW » Thu, 05 Aug 2004 16:29:03


I've got a problem with the scripcontrol

this is the code i use ;

Dim MyScriptControl As New ScriptControl

MyScriptControl.Language = "VBScript"
MyScriptControl.AddObject("a", CType(10.0, Double))
MyScriptControl.AddObject("b", CType(20.0, Double))


MyScriptControl.ExecuteStatement("endresult = a + b")

Recalc = MyScriptControl.Eval("endresult")


The result is 1020 like a string

when i use a other formula endresult= a * b it returns 200

How can i force the scriptcontrol to add the two variables instead of treating them a string ?

kind regards

Pietswieb
 
 
 

numeric fields

Post by VG9tIExhdm » Thu, 05 Aug 2004 21:19:02

Try explicitly converting at least one of your variables to a number using CDbl in the ExecuteStatement ...

MyScriptControl.ExecuteStatement("endresult = CDbl(a) + CDbl(b)")

This occurs with Eval and ExecuteStatement because they are working on strings and the plus sign has an ambiguous meaning in VB. It can either be a math or string operator. Because the statement being evaluated isa string, by necessity , the two variables' contents are being typecast to strings, even though you have taken the trouble to define them as double percision, real numbers.

Tom Lavedas
===========