locked
Calculation of a string and more RRS feed

  • Question

  • Hi to all.

    If I have a string "MATH.POWER(3,4)" how do I calculate its value?

    In fact, small basic recognizes it as a string and does not calculate the value even using LDMATH.EVAL.

    Thanks

    Thursday, August 31, 2017 11:56 AM

Answers

  • You have to translate your expression string to a language, that LDMath.Evaluate  can understand,

    That is JScript Math object    for LDMath.Evaluate and

    C#/VB .NET  Math class         for LDMath.Evaluate2

    (in this case to Math.Pow)

    e.g. like

    str = "MATH.POWER(3,4)"
    TextWindow.WriteLine("strOrig: "+ str)
    
    str = Text.ConvertToUpperCase(str)  ' or  Text.ConvertToLowerCase(str)    if you want lower case
    str = LDText.Replace(str, "MATH.POWER(", "Math.Pow(") ' case sensitive, here UPPER case
    'str = LDRegex.Replace(str, "MATH.POWER\(", "Math.Pow(", "")  ' case (in)sensitive
    TextWindow.WriteLine("str:     "+ str)
    TextWindow.WriteLine("")
    
    res = LDMath.Evaluate(str)    ' JScript Math object
    res2 = LDMath.Evaluate2(str)  '  C#/VB  .NET  Math.  class
    TextWindow.WriteLine("LDMath.Evaluate:   "+  res)
    TextWindow.WriteLine("LDAMath.Evaluate2: "+ res2)
    TextWindow.WriteLine("")


    Thursday, August 31, 2017 12:33 PM
    Answerer
  • Hello, BluStars.

    In my case: 3*3*3*3

    Small Basic: compiles source code to binary for CLR which calling .NET Library version of Math.Power().

    See Also

    https://social.technet.microsoft.com/wiki/contents/articles/39855.small-basic-how-a-program-runs.aspx


    Nonki Takahashi

    Thursday, August 31, 2017 12:39 PM

All replies

  • You have to translate your expression string to a language, that LDMath.Evaluate  can understand,

    That is JScript Math object    for LDMath.Evaluate and

    C#/VB .NET  Math class         for LDMath.Evaluate2

    (in this case to Math.Pow)

    e.g. like

    str = "MATH.POWER(3,4)"
    TextWindow.WriteLine("strOrig: "+ str)
    
    str = Text.ConvertToUpperCase(str)  ' or  Text.ConvertToLowerCase(str)    if you want lower case
    str = LDText.Replace(str, "MATH.POWER(", "Math.Pow(") ' case sensitive, here UPPER case
    'str = LDRegex.Replace(str, "MATH.POWER\(", "Math.Pow(", "")  ' case (in)sensitive
    TextWindow.WriteLine("str:     "+ str)
    TextWindow.WriteLine("")
    
    res = LDMath.Evaluate(str)    ' JScript Math object
    res2 = LDMath.Evaluate2(str)  '  C#/VB  .NET  Math.  class
    TextWindow.WriteLine("LDMath.Evaluate:   "+  res)
    TextWindow.WriteLine("LDAMath.Evaluate2: "+ res2)
    TextWindow.WriteLine("")


    Thursday, August 31, 2017 12:33 PM
    Answerer
  • Hello, BluStars.

    In my case: 3*3*3*3

    Small Basic: compiles source code to binary for CLR which calling .NET Library version of Math.Power().

    See Also

    https://social.technet.microsoft.com/wiki/contents/articles/39855.small-basic-how-a-program-runs.aspx


    Nonki Takahashi

    Thursday, August 31, 2017 12:39 PM