SlimShady Posted June 11, 2004 Share Posted June 11, 2004 (edited) What I want to accomplish: - User inputs a formula - The formula is saved in an INI file - The script reads the formula, when needed, from the file - The script uses the formula to perform math functions Idea(s) I have: - User inputs a formula + "|" + (number of variables) + "|" + (value of each variable + "|") - Script reads input - Script reads how many variables there are - Each alphabetic character will get it's own variable (From a to f) - check if there are () characters, calculate those first Question: Can I dynamically create variables? (number of different variables is known) Edited June 11, 2004 by SlimShady Link to comment Share on other sites More sharing options...
trids Posted June 11, 2004 Share Posted June 11, 2004 Sounds like the early stages of a script language .. check out Larry's ScriptWriter, which builds an AU3 script. Cos if you use AU3 syntax etc, you can use the AU3 engine and all the features (looping, conditions, functions) that will come next. HTH Link to comment Share on other sites More sharing options...
SlimShady Posted June 11, 2004 Author Share Posted June 11, 2004 Sounds like the early stages of a script language .. check out Larry's ScriptWriter, which builds an AU3 script. Cos if you use AU3 syntax etc, you can use the AU3 engine and all the features (looping, conditions, functions) that will come next. HTH Come on, I'm serious. Here's an example formula: [Formula1] Value=a*x|a=3|x=6 Value contains variables that should be declared. How do I declare those variables in AutoIt? Because the user can declare unlimited variables, I need to know how to declare 'em in AutoIt. Link to comment Share on other sites More sharing options...
Holger Posted June 11, 2004 Share Posted June 11, 2004 @SlimShady: don't know if this is what you mean but I did a simular thing with a loop and then read out the operator like "*", "+", "-", "/". Maybe the most important is the result?...I don't know. What happens then with the result when the math-functions are ended? Old project:GUI/Tray menu with icons and colors Other old stuff:IconFileScanner, TriState/ThreeState GUI TreeView, GUI ContextMenu created out of a TreeView Link to comment Share on other sites More sharing options...
SlimShady Posted June 11, 2004 Author Share Posted June 11, 2004 @SlimShady: don't know if this is what you mean but I did a simular thing with a loop and then read out the operator like "*", "+", "-", "/".Maybe the most important is the result?...I don't know.What happens then with the result when the math-functions are ended?Yeah, I can use that. But that's not all.This will be a part of an existing script.Let me see if I can answer your first question...Can't....Second question:- User can add/delete formulas.- In an Gui the user can choose a formula, enter some values- In the script I want to parse the formula and declare the variables- use the values with the formula- display the result Link to comment Share on other sites More sharing options...
Holger Posted June 11, 2004 Share Posted June 11, 2004 @SlimShady: what if you use an array like f.i. $matharray[1000][5] and you fill it with: a|3|x|6|* ... maybe a little bit like this Global $matharray[1000][5] ... $idx = 0 While 1 ... If IniRead... $idx = $idx + 1 $matharray[0][0] = $idx; store max index to first array field $matharray[$idx][0] = StringSplit... $matharray[... ... WEnd For $idx = 1 To $matharray[0][0] If $matharray[$idx][4] = "*" Then Msgbox(0,"Result",$matharray[$idx][1] * $matharray[$idx][4] ... Next ... Old project:GUI/Tray menu with icons and colors Other old stuff:IconFileScanner, TriState/ThreeState GUI TreeView, GUI ContextMenu created out of a TreeView Link to comment Share on other sites More sharing options...
SlimShady Posted June 11, 2004 Author Share Posted June 11, 2004 You didn't explain how that example works. Is that 5: 5 dimensions for 5 formulas? In the mean time I'll see if I can make it work this way. Thanks. Link to comment Share on other sites More sharing options...
Holger Posted June 11, 2004 Share Posted June 11, 2004 @slimshady: no, 5 dimensions for 1 formular, maybe you have to check in the value-string for a "*", "-", "+"...etc. so that you know when the next 'math-string' begins. If you have: Value=a*x|a=3|x=6|b+c|c=5|b=12... So you have to read through the string until the next operator... a*x|a=3|x=6|b+ or you split it by operators and take the one before the splitoperator... Difficult... You write then all parts of the math-string to the array you know... a*x|a=3|x=6 -> a|3|x|6|* b+c|c=5|b=12 -> c|5|b|12|+ Old project:GUI/Tray menu with icons and colors Other old stuff:IconFileScanner, TriState/ThreeState GUI TreeView, GUI ContextMenu created out of a TreeView Link to comment Share on other sites More sharing options...
SlimShady Posted June 11, 2004 Author Share Posted June 11, 2004 @slimshady: no, 5 dimensions for 1 formular, maybe you have to check in the value-string for a "*", "-", "+"...etc. so that you know when the next 'math-string' begins. If you have: Value=a*x|a=3|x=6|b+c|c=5|b=12... So you have to read through the string until the next operator... a*x|a=3|x=6|b+ or you split it by operators and take the one before the splitoperator... Difficult... You write then all parts of the math-string to the array you know... a*x|a=3|x=6 -> a|3|x|6|* b+c|c=5|b=12 -> c|5|b|12|+Problem: In your example you took only 2 variables. But that has to be undefined. Let me show you: a*x|a=3|x=6 -> a|3|x|6|* b+c|c=5|b=12 -> c|5|b|12|+ After the 6 you see the asterix. How would I know when all the variables have been declared? I was thinking about generating a second script, like Larry mentioned. If I can't make this work; If I'm stuck, I'll do that. Link to comment Share on other sites More sharing options...
trids Posted June 11, 2004 Share Posted June 11, 2004 You could have the script write another script that will return the information to the calling scripts window title. This may involve FileInstalling AutoIt3.exe into your script... seems redundant... but maybe necessary... I will try to whip up an example..Lar.Thanks Lar .. that's what I meant .. cos then you get all the benefits of looping, conditions, functions etc. Link to comment Share on other sites More sharing options...
SlimShady Posted June 11, 2004 Author Share Posted June 11, 2004 Thanks Lar .. that's what I meant .. cos then you get all the benefits of looping, conditions, functions etc. Sorry, I didn't understand what you mean.And I wasn't thinking about a second script, yet. Link to comment Share on other sites More sharing options...
trids Posted June 11, 2004 Share Posted June 11, 2004 And I wasn't thinking about a second script, yet.Well, in a way the formula(s) in your INI file are like a mini script. Which suggests that you can use the friendly AU3 scripting engine to interpret for you ... So you can either change the format of the INI file to plain AU3 syntax, which has the benefit of allowing loops, conditions, yada-yadahOr you can build an intermediary Au3 (script) file from the "formulas" in your INI file .. and pass this on to the scripting engine.Either way you avoid having to reinvent the wheel Link to comment Share on other sites More sharing options...
SlimShady Posted June 11, 2004 Author Share Posted June 11, 2004 Because I'm creating an interactive Gui, I'll have to add/keep one variable empty: one dynamic variable. I figured that out. BTW, I'm doing this just for fun. So, I don't need to compile it or FileInstall AutoIt3.exe. Here's an example of how I'm gonna use it: $AU3EXE = @ProgramFilesDir & '\AutoIt3\AutoIt3.exe' $AU3TMP = @tempdir & '\Eval.au3' $string = "$a * $b / $c + $d - $e + $val|$a = 5|$b = 10|$c=15|$d=20|$e = 6|$val = " & GUIRead($input) $a_Eval = StringSplit(StringStripWS($string,8),"|") For $i = 1 to $a_Eval[0] If $i <> 1 Then If StringInStr($a_Eval[$i],"=") Then $var = StringLeft($a_Eval[$i],StringInStr($a_Eval[$i],"=")-1) $val = StringTrimLeft($a_Eval[$i],StringInStr($a_Eval[$i],"=")) $string = StringReplace($string,$var,$val) EndIf Else $string = $a_Eval[$i] EndIf Next AutoItWinSetTitle("AU3EvalMe...") $string = 'WinSetTitle("AU3EvalMe...","",' & $string & ')' FileDelete($AU3TMP) FileWrite($AU3TMP,$string & @CRLF) RunWait('"' & $AU3EXE & '" "' & $AU3TMP & '"') MsgBox(4096,"",AutoItWinGetTitle()) MsgBox(4096,"",5 * 10 / 15 + 20 - 6) Thank you for your help, Larry. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now