Ozirys Posted March 22, 2024 Posted March 22, 2024 Execute(100^2-96^2) give 19216 !!!! and Execute(100^2+96^2) give 19216 You have a problem with "+" and "-"....
Nine Posted March 22, 2024 Posted March 22, 2024 If I remember correctly it is a known issue. This works : ConsoleWrite(Execute((100^2) - (96^2)) & @CRLF) “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Multi-Threading Made Easy
Moderators Melba23 Posted March 22, 2024 Moderators Posted March 22, 2024 Ozirys, Nine is quite correct - look in the Help file under <Operators - Precedence> and you will see this: Although the operator precedence should suffice in most cases, is recommended to use brackets to force the order of evaluation if the result is critical or if the expression is complex. e.g. (2 + 4) * 10 equals 60. This is particularly true for the - operator which can be used for both binary subtraction (subtraction of 2 numbers)and unary negation (setting the negative of a value). The use of brackets is highly recommended in this case to prevent confusion. M23 teodoric666 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Ozirys Posted March 22, 2024 Author Posted March 22, 2024 I know, but... I'm surprised that Excel is able to find the solution WITHOUT "()" and Autoit can't. Do you think that a UDF file can resolve the problem ?
ioa747 Posted March 22, 2024 Posted March 22, 2024 (edited) ConsoleWrite(Execute((100^2) - (96^2)) & @CRLF) ;784 ConsoleWrite(Execute("(100^2) - (96^2)") & @CRLF) ;784 ConsoleWrite(Execute("100^2" - "96^2") & @CRLF) ;4 ConsoleWrite(Execute(100 * 100 - 96 * 96) & @CRLF) ;784 ConsoleWrite(Execute(100^2 -- 96^2) & @CRLF) ;784 ConsoleWrite(Execute(100^2 -+ 96^2) & @CRLF) ;784 ConsoleWrite(Execute(100^2 +- 96^2) & @CRLF) ;19216 everything works to me Edited March 22, 2024 by ioa747 teodoric666 1 I know that I know nothing
Moderators SmOke_N Posted March 22, 2024 Moderators Posted March 22, 2024 47 minutes ago, Ozirys said: I know, but... I'm surprised that Excel is able to find the solution WITHOUT "()" and Autoit can't. Do you think that a UDF file can resolve the problem ? Probably... ConsoleWrite( _ExecuteNums("100^2-96^2") & @CRLF) Func _ExecuteNums($vData) Local Const $sRE = "(\d+\h*[\*\\\^]\h*\d+)" Return Execute(StringRegExpReplace($vData, $sRE, "\($1\)")) EndFunc I didn't exclusively test this... you may want to Ozirys 1 Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Andreik Posted March 22, 2024 Posted March 22, 2024 1 hour ago, Ozirys said: Do you think that a UDF file can resolve the problem ? Let's write a parser instead of putting two parentheses.
Moderators Melba23 Posted March 22, 2024 Moderators Posted March 22, 2024 Ozirys, The question of the varied operator precedence found in different programming languages was discussed in this thread: It was after that thread that I added more explnation in the Help file. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
argumentum Posted March 22, 2024 Posted March 22, 2024 1 hour ago, Ozirys said: Do you think that a UDF file can resolve the problem ? 22 minutes ago, Andreik said: Let's write a parser instead of putting two parentheses I vote +1 for the UDF. Now, in the phrase "Let's write ..", would that mean "Let me ( meaning you ) write ..", because if that is so, then yes, let's do it ( I must confess that my math is barely enough for single digit addition, and just barely ) Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
Ozirys Posted March 27, 2024 Author Posted March 27, 2024 Using this solution solve the problem with "^", but if i want to solve "4500/20*360" it give 0.625 because it makes "4500/(20*360)" Before use this function it is necessary to check if the string contain "^" ConsoleWrite( _ExecuteNums("100^2-96^2") & @CRLF) Func _ExecuteNums($vData) Local Const $sRE = "(\d+\h*[\*\\\^]\h*\d+)" Return Execute(StringRegExpReplace($vData, $sRE, "\($1\)")) EndFunc
Moderators SmOke_N Posted March 27, 2024 Moderators Posted March 27, 2024 (edited) So... Like I said, I didn't extensively test it... It makes sense looking at the regular expression pattern that the 20*360 was encased by parenthesis. Func _ExecuteNums($vData) Local Const $sRE = "(\d+\h*[\*/^]\h*\d+)" Return Execute(StringRegExpReplace($vData, $sRE, "\($1\)")) EndFunc I had the wrong character for divisor in the first one... in the few tests I did they worked. Edit: For some reason, my other edit didn't post... this should take care of you coming back in a week saying it doesn't work with numbers/floats/doubles. Func _ExecuteNums($vData, $vDec = ".") ; escape decmal chars Local Const $sDecRE = "([\\\.\^\$\|\[|\]\(\)\{\}\*\+\?\#])" $vDec = StringRegExpReplace($vDec, $sDecRE, "\\$1") Local $sRE = "(\d+[\" & $vDec & "\d]*\h*[\*/^]\h*\d+[\" & $vDec & "\d]*)" Return Execute(StringRegExpReplace($vData, $sRE, "\($1\)")) EndFunc Edited March 27, 2024 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Ozirys Posted March 27, 2024 Author Posted March 27, 2024 I have tested a new regular expression "(\d+\h*[\\\^]\h*\d+)" Working good
Moderators SmOke_N Posted March 27, 2024 Moderators Posted March 27, 2024 1 hour ago, Ozirys said: I have tested a new regular expression "(\d+\h*[\\\^]\h*\d+)" Working good Hmm... [\\\^] will only look for back slash and "to the power of" ^ ... both codes I provided in my last post are correct (for all my different testing), but the operator regex is [\*/^] Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Ozirys Posted April 5, 2024 Author Posted April 5, 2024 I don't know anything about "regular expression". I simplified: "(\d+\h*[\^]\h*\d+)" it works too
Moderators SmOke_N Posted April 6, 2024 Moderators Posted April 6, 2024 8 hours ago, Ozirys said: I don't know anything about "regular expression". I simplified: "(\d+\h*[\^]\h*\d+)" it works too That works on something like: "18/14*4"? 😲 Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
jugador Posted April 7, 2024 Posted April 7, 2024 (edited) ConsoleWrite( _ExecuteNums('18/14 * 4') & @CRLF) ConsoleWrite( _ExecuteNums("100^2-96^2") & @CRLF) Func _ExecuteNums($vData) Return Execute(StringRegExpReplace($vData, '([\d.]+)', '($1)')) EndFunc Edited April 7, 2024 by jugador
jchd Posted April 7, 2024 Posted April 7, 2024 There are other forms of numbers like -1.5e3 for instance. Also this won't work with 100^2--96^3 It's still unclear how -100^2-.5^-1 is interpreted: (-100)^2 - .5^-1 (as AutoIt = 9998) or -(100^2) - .5^-1 (standard = -10002) This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
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