Jump to content

Why does a string used in an expression return 0?


Recommended Posts

I beg to differ: the behavior matches the specified conversion conventions of AutoIt (in this case, Number() specification) and, frankly I find that pretty logical (from the AutoIt point of view).

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

I know AutoIt is very forgiving but I feel like that shouldn't make sense (and doesn't to me). I'd expect number() to return the int/float value of a string representation of a number. Not capture numbers up until a non numeric value.

Global $sString = "32 Apples and 43 oranges"
ConsoleWrite(Number($sString) & @LF)

I've never used it in this sense but even though it starts with a number this should fail because it is a full blown string sentence.

Global $sString = "32 Apples and 43 oranges"
ConsoleWrite(IsNumber($sString) & @LF)

Should act like this. IsNumber says this is not a number, even though Number() would return 32. If someone was expecting some numbers in a string but IsNumber says it's not one, the programmer would have some warning about needing numbers, or use a regular expression to get the numbers from a string (if they wanted to do so)

#include <Array.au3>

Global $sString = "32 Apples and 43 oranges"
Global $aRegExp = Null

If (IsNumber($sString)) Then
    ConsoleWrite($sString & @LF)
Else
    $aRegExp = StringRegExp($sString, "\d+", 3)
    ConsoleWrite(_ArrayToString($aRegExp, ", ") & @LF)
EndIf

 

Link to comment
Share on other sites

1 hour ago, jchd said:

I beg to differ: the behavior matches the specified conversion conventions of AutoIt (in this case, Number() specification) and, frankly I find that pretty logical (from the AutoIt point of view).

Exceptions aside!

MsgBox('0.1e+001', 'OK / Cancel ???', Number('0.1e+001'))

This proves that the conversion  is inconsistent.

Link to comment
Share on other sites

9 hours ago, InunoTaishou said:

I know AutoIt is very forgiving but I feel like that shouldn't make sense (and doesn't to me). I'd expect number() to return the int/float value of a string representation of a number. Not capture numbers up until a non numeric value.

Ever wrote a little C/C++ program and used atoi()? http://www.cplusplus.com/reference/cstdlib/atoi/

That behavior is pretty standard in many programming languages and doing so AutoIt didn't create a new path in wild forest but highways with common signs and heavy traffic.

8 hours ago, czardas said:

This proves that the conversion  is inconsistent.

??? Which inconsistancy?

 

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

53 minutes ago, jchd said:

??? Which inconsistancy?

If the internal conversion was using the same algorithm as Number(), then the message box would contain both OK and Cancel buttons. I only get an OK button, which implies that Number() is inconsistent with the internal numeric conversion (in this instance). We've discussed several inconsistencies with AutoIt over the years and this is just another one of them. Perhaps it seems trivial, but it's still a fact.

Edited by czardas
Link to comment
Share on other sites

Fact?

Can you please reread the help under MsgBox, in particular the constants for parameter "flag".

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

I'm not sure what you are getting at, perhaps we are talking about two different things.

$MB_OKCANCEL = 1
Number('0.1e+001') = 1
MsgBox'(0.1e+001', '', '') does not give $MB_OKCANCEL style.

Internal conversion is different to Number() as it is implemented in AutoIt on my machine. I only mentioned it because I thought you stated something to the contrary which I deemed to be incorrect.

Edited by czardas
Link to comment
Share on other sites

I apologize for responding too fast, was looking at return values not flag.

Yeah, that sound a bit strange. Clearly the conversion isn't done the same way here. Nonetheless, passing a flag (integer) value as a string containing a float in scientific notation isn't that common in solid code. We (non-DEVs) can do nothing against that but I wouldn't loose much if it wasn't fixed within hours.

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

can someone pop the hood and tell us exactly what is happening with the string values that you use to declare an array / set parameters?

As best I can tell it performs a string left up to the first non 0-9 character, then performs a number() on that string.

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

I suppose it just uses the result of Number().

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

2 hours ago, jchd said:

I suppose it just uses the result of Number().

but it doesn't, as evidenced by @czardas

It evaluates that scientific string as 0 because that is the only value prior to a non 0-9 character '.'  put any other number (even zero padded numbers) before the decimal point and you will get that number, which is absolutely not the behavior of number() so there has to be formatting of that string happening prior.

Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

Indeed, scientific notation isn't parsed correctly in these cases.

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

×
×
  • Create New...