Jump to content

Making calculation inside a string.


ezzetabi
 Share

Recommended Posts

  • 4 weeks later...

hmmm, i was thinking of what newkreation said too... write what the user types into an ini file and then call it later... lemme see if this would work, later...because i got a concert to attend =/

(sry i know this post is old but, you know :idiot:)

FootbaG
Link to comment
Share on other sites

hmmm, i was thinking of what newkreation said too... write what the user types into an ini file and then call it later... lemme see if this would work, later...because i got a concert to attend =/

(sry i know this post is old but, you know :idiot:)

<{POST_SNAPBACK}>

Ofcourse it won't work.

I tested just now:

INIWrite(@TempDir & "Test.tmp", "Calculation", "Test1", "5*3+15")
$Calc = INIRead(@TempDir & "Test.tmp", "Calculation", "Test1", "")
MsgBox(64, "Debug", "$Calc:" & @CRLF & $Calc)
Link to comment
Share on other sites

hmmm, shouldn't there be a Number function in there?

but here's what i thought

INIWrite (@TempDir & "\test.ini\", "Prolem", "Numbers", "4/2")
$calculation= INIRead (@TempDir & "\test.ini\", "Problem", "Numbers", "What problem?")
$do= Number ($calculation)
MsgBox (0, "test", $do)

but even so, that returns 0 and is like the same thing as doing this:

$math= GUIRead ($edit_23)
      $answer= Number ($math)
      GUICtrlSetData ($edit_23, "= ", 1)
      GUICtrlSetData ($edit_23, $answer, 1)

inside the script...

so i was wrong =(

FootbaG
Link to comment
Share on other sites

Found a way to do this!

See here:

;Example:
$RetValue = _Calc("5 * 5 * (5 + 25)")
MsgBox(64, "Test _Calc", "$RetValue: " & $RetValue)

Func _Calc($Expr)
   $TmpBatch = @TempDir & "\Calc.bat"
   If NOT FileExists($TmpBatch) Then CreateBatch($TmpBatch)
   $val = RunWait($TmpBatch & ' "' & $Expr & '"', "", @SW_HIDE)
EndFunc

Func CreateBatch($BatchFile)
   $OpenBatch = FileOpen($BatchFile, 2)
      FileWriteLine($OpenBatch, "SET /A VAL=%1")
      FileWriteLine($OpenBatch, "EXIT %VAL%")
   FileClose($OpenBatch)
EndFunc
Edited by SlimShady
Link to comment
Share on other sites

It is just a variation of Valik's idea and it can't return non integers.

Try

;Example:
$RetValue = _Calc("5 * 5 * (5 + 25.1)")
MsgBox(64, "Test _Calc", "$RetValue: " & $RetValue)

Func _Calc($Expr)
  $TmpBatch = @TempDir & "\Calc.bat"
  If NOT FileExists($TmpBatch) Then CreateBatch($TmpBatch)
  $val = RunWait($TmpBatch & ' "' & $Expr & '"', "", @SW_HIDE)
EndFunc

Func CreateBatch($BatchFile)
  $OpenBatch = FileOpen($BatchFile, 2)
     FileWriteLine($OpenBatch, "SET /A VAL=%1")
     FileWriteLine($OpenBatch, "EXIT %VAL%")
  FileClose($OpenBatch)
EndFunc
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...