Jump to content

A bug in Execute()


Recommended Posts

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 ?

Link to comment
Share on other sites

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

:oops:

Edited by ioa747

I know that I know nothing

Link to comment
Share on other sites

  • Moderators
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

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.

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 :P
( 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.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • Moderators
Posted (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 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.

Link to comment
Share on other sites

  • Moderators
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.

Link to comment
Share on other sites

  • 2 weeks later...
  • Moderators
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.

Link to comment
Share on other sites

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 here
RegExp tutorial: enough to get started
PCRE 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)

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...