Jump to content
Sign in to follow this  
Leonick

Autoit....does simple math sometimes WRONG!!

Recommended Posts

Leonick

Ok guys...this one is really wierd.

I cannot overcome it by myself....its realy strange.

Its a huge script,...so i narrowed it down.

There's one line.....

"If $start > $ende Then"

This one is giving random results!!!

Sometimes it calculates it right, sometimes wrong.

Directly over the calculation i have a output of the variables....

and sometimes it does it really wrong...

strange..

code

func f8()
    $start = GUICtrlRead($Inputstart)
    $ende = GUICtrlRead($Inputende)


    ConsoleWrite("$start=" & $start & @LF)
    ConsoleWrite("$ende=" & $ende & @LF)
    ConsoleWrite("$startdefault=" & $startDefault & @LF)

If $start > $ende Then
            MsgBox("", "", "Start is bigger then end")
            ConsoleWrite("Start is bigger then end"&@lf)
            Return
        Else
            ConsoleWrite("#############")
        EndIf

EndFunc   ;==>f8

here's the console output:

>Running:(3.3.0.0)>_<:\AutoIt3\autoit3.exe "E:\###Scripts###\xxxxxxxxx.au3"

$start=3 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!

$ende=150 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!

$startdefault=2

Start is bigger then end !!!!!!!!!!!!!!!!!!!!!!

+>00:54:54 AutoIT3.exe ended.rc:0

+>00:54:55 AutoIt3Wrapper Finished

>Exit code: 0 Time: 6.429

I mean...how can that be possible.....?????

If the program is already running correct,....then its no problem....its only the first time is start it.

The variables are read from a .ini ,...and then put into a inputbox....

and then, as you see in the script are read from there.

But thats not the point,...since above the code is the output of the variables, to check if reading is correct.

I am losing my brain on this one...

Edited by Leonick

Share this post


Link to post
Share on other sites
Valuater

Your information and code does not re-create the problem. Please give code that duplicates the error.

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
Leonick

Your information and code does not re-create the problem. Please give code that duplicates the error.

8)

yeah sorry i know,...but the code is several thousand lines long...

and it jumps trough several functions, before ending there....

but i found out, if i do the check:

If isinteger($start) <> true Then

beep(200,500)

EndIf

that $start and $ende seem not to be a number,....

but shouldn't it also work if they are integer??

and how can i change them to a number?

by rewriting it back to the .ini...and rereading it back again?

Share this post


Link to post
Share on other sites
Valuater

INT()

Returns the integer (whole number) representation of an expression.

$String = "15"

MsgBox(4096, "Number", Int($String))

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
Valuater

Maybe a better example... ( more useful )

$String = "19"

$String2 = "18"

MsgBox(4096, "Number", (Int($String) > Int($String2)))

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
Leonick

Oh great..i didn't know that INT() is not only putting floating point into integer,..but also strings into integer.

It's working...big thx.

But I dont understand why??

since

$start="1"
$ende="6"

if $start> $ende then
beep(200,500)
EndIf

is also working..

so autoit converts the string automaticly into a number.

So in what format does it read the variables from my gui??

Edited by Leonick

Share this post


Link to post
Share on other sites
Valuater

I still don't know. There was not a reproductive script for me to analyze

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
Leonick

sorry, but that could be difficult...

I mean all you need is the vaiable and the format:

So here i did some testing

code
start:>>>8<<<
Ende:>>>150<<<

;both variables §start and $ende have the same output:

StringIsAlNum returns:1
IsArray returns:0
IsBinary returns:0
IsDeclared returns:0
IsDllStruct returns:0
IsFloat returns:0
IsInt returns:0
IsKeyword returns:0
IsNumber returns:0
IsString returns:1
IsPtr returns:0
IsObj returns:0

you need anything more?

Edited by Leonick

Share this post


Link to post
Share on other sites
miketh2005

sorry, but that could be difficult...

I mean all you need is the vaiable and the format:

So here i did some testing

code
start:>>>8<<<
Ende:>>>150<<<

;both variables §start and $ende have the same output:

StringIsAlNum returns:1
IsArray returns:0
IsBinary returns:0
IsDeclared returns:0
IsDllStruct returns:0
IsFloat returns:0
IsInt returns:0
IsKeyword returns:0
IsNumber returns:0
IsString returns:1
IsPtr returns:0
IsObj returns:0

you need anything more?

difficult? just paste the script into nopaste.dk

...

Share this post


Link to post
Share on other sites
Leonick

difficult? just paste the script into nopaste.dk

...

Its customized to my computer,...containing pixelgetcolor,...window titles,.... ini's....

it wouldn't run anyway...

but what information are you looking for???

there's all you need.

the value of the variable,...and the format....and that it is working with int($var) instead of $var

Share this post


Link to post
Share on other sites
SmOke_N

You don't need a recreation script. You're trying to do math with strings, that's a bit silly if you ask me, you'll get a big enough string that the statement wouldn't be true. If you're trying to do "simple" math, do simple coding and make your integers integers with Int(), floats or doubles with Number(), and you won't run into the issues your facing.


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.

Share this post


Link to post
Share on other sites
Leonick

Doing math with strings is silly??

That's NOT silly... why trying to make me look like a fool?

You should have read the whole thing, before blaming someone.

since i already posted:

code
$start="1"
$ende="6"

if $start> $ende then
beep(200,500)
EndIf

is working as well!! and they are STRINGS!!

Probably you didn't realized yet that autoit can calculate with numbers even if they are strings.(Did it 10000 times before!!)

But only in this case its not working!!!!! (reading the string out of a Gui)

And i simply wanna know why,.....

Share this post


Link to post
Share on other sites
SmOke_N

Doing math with strings is silly??

That's NOT silly... why trying to make me look like a fool?

You should have read the whole thing, before blaming someone.

since i already posted:

code
$start="1"
$ende="6"

if $start> $ende then
beep(200,500)
EndIf

is working as well!! and they are STRINGS!!

Probably you didn't realized yet that autoit can calculate with numbers even if they are strings.(Did it 10000 times before!!)

But only in this case its not working!!!!! (reading the string out of a Gui)

And i simply wanna know why,.....

I did read it... and you are trying to do math with a string, "hoping" it is treated as a number/int... That doesn't seem silly to you? Just because something works once or twice, doesn't make it right.

As I said, I'd stick to what I know works (If Int($s_var) > Int($s_var2)), rather than "hoping" that the devs have taken in account for every single situation that someone would try to use a string as a Int/Double.


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.

Share this post


Link to post
Share on other sites
Leonick

I did read it... and you are trying to do math with a string, "hoping" it is treated as a number/int... That doesn't seem silly to you? Just because something works once or twice, doesn't make it right.

As I said, I'd stick to what I know works (If Int($s_var) > Int($s_var2)), rather than "hoping" that the devs have taken in account for every single situation that someone would try to use a string as a Int/Double.

You are right,....but the thing is, that it worked 100% until now, so i wasn't aware of that string/Int thing,...and i am a noob in autoit,...so next time explain it right, without offending other people.

but thx anyway...

Share this post


Link to post
Share on other sites
Jos

...and i am a noob in autoit,...so next time explain it right, without offending other people.

but thx anyway...

Excuse me? Do I understand it correctly that you have a problem with answers given to you particularly the word "Silly"?

Hope I am intepreting this incorrectly.

Jos


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
ctyankeeinok

OK, I think I see the issue. You are doing math with strings which can give you problems. In the string world, 3 is greater than 150, because strings are evaluated left to right. The assumption is null AFTER the number, not zeros before. To see how it works, open Excel and type in the following in three cells in three rows:

'3

'15

'150

You have to add the single quote to declare it as text. Now sort the cells and you will see that the 3 comes last. Excel tries to correct your mistake with a popup, but take the second option (sort numbers and text separately). It sorts to the following:

'15

'150

'3

It is evaluating the characters from left to right. A comparison of < or > will work the same. One is less than three so it comes first, regardless of the characters following it. Your eye tricks you into thinking that it will evaluate a number in its entirety, but that is not true because the datatype is a string. Make sense?

Try the following:

$3string = "3"
$15string = "15"
$3int = 3
$15int = 15

if $3string < $15string Then
    MsgBox(0,"","3 string is less than 15 string")
Else
    MsgBox(0,"","15 string is less than 3 string!")
EndIf
if $3int < $15int Then
    MsgBox(0,"","3 int is less than 15 int")
Else
    MsgBox(0,"","15 int is less than 3 int")
EndIf

Share this post


Link to post
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
Sign in to follow this  

×