jaberwacky Posted July 23, 2010 Share Posted July 23, 2010 (edited) I'm trying to pass this number to a function: 9223372036854775807. When I use consolewrite in the function to display the number I get the scientific value instead: 9.22337203685478e+018. This only happens when I use AutoItObject. I have abstracted the script to focus on the problem area: I should mention that my Windows 7 machine is 64 bit. expandcollapse popup#include <AutoItObject.au3> Global Const $intMAX = 9223372036854775807 ;~ Global Const $intMAX = 2147483647 ; works fine when using this instead _AutoItObject_Startup() Global $calc = Calculator() ConsoleWrite("Before:" & @TAB & $intMAX & @LF) $calc.Sum($intMAX, 0) Func Calculator() Local $this = _AutoItObject_Create() _AutoItObject_AddMethod($this, "Sum", "Calculator_Sum") Return $this EndFunc ;==>Calculator Func Calculator_Sum($this, Const $p, Const $q) ConsoleWrite("After:" & @TAB & $p & @LF) If ($p >= 0 And $q >= 0) Or ($p < 0 And $q < 0) Then ; possibility of overflow condition If $q >= 0 Then Local Const $result = $p + $q If $result < $p Then ; overfloweth Return SetError(1, 0, "overflow") Else Return $result EndIf EndIf Else ; no possibility of overflow Return $p + $q EndIf EndFunc ;==>Calculator_Sum this works fine: Global Const $intMAX = 9223372036854775807 display($intMAX) Func display($num) ConsoleWrite($num & @LF) EndFunc ;==>display Edited July 23, 2010 by jaberwocky6669 Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
E1M1 Posted July 23, 2010 Share Posted July 23, 2010 Global Const $intMAX = "9223372036854775807" ;it's string now, but $intMAX + $Something still returns right numbric value edited Link to comment Share on other sites More sharing options...
jaberwacky Posted July 23, 2010 Author Share Posted July 23, 2010 Global Const $intMAX = "9223372036854775807" ;it's string now, but $intMAX + $Something still returns right numbric value Thanks E1M1. I tried it just now but unfortunately when I add $p and $q the result still returns scientific notation. expandcollapse popup#include <AutoItObject.au3> Global Const $intMAX = "9223372036854775807" ;~ ;Global Const $intMAX = 2147483647 ; works fine when using this instead _AutoItObject_Startup() Global $calc = Calculator() ConsoleWrite("Before:" & @TAB & $intMAX & @LF) $calc.Sum($intMAX, 1) Func Calculator() Local $this = _AutoItObject_Create() _AutoItObject_AddMethod($this, "Sum", "Calculator_Sum") Return $this EndFunc ;==>Calculator Func Calculator_Sum($this, Const $p, Const $q) ConsoleWrite("After:" & @TAB & $p & @LF) If ($p >= 0 And $q >= 0) Or ($p < 0 And $q < 0) Then ; possibility of overflow condition If $q >= 0 Then Local Const $result = $p + $q ConsoleWrite("But still returns scientific notation:" & @TAB & $result & @LF) If $result < $p Then ; overfloweth Return SetError(1, 0, "overflow") Else Return $result EndIf EndIf Else ; no possibility of overflow Return $p + $q EndIf EndFunc ;==>Calculator_Sum Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
E1M1 Posted July 23, 2010 Share Posted July 23, 2010 (edited) I just played with some string commands, and got it work. It's reinventing ther wheel, but if wheel is badly invented you have to reinvent it. expandcollapse popup#include <AutoItObject.au3> Global Const $intMAX = "9223372036854775807" ;~ ;Global Const $intMAX = 2147483647 ; works fine when using this instead _AutoItObject_Startup() Global $calc = Calculator() ConsoleWrite("Before:" & @TAB & $intMAX & @LF) $calc.Sum($intMAX, 1) Func Calculator() Local $this = _AutoItObject_Create() _AutoItObject_AddMethod($this, "Sum", "Calculator_Sum") Return $this EndFunc ;==>Calculator Func Calculator_Sum($this, Const $p, Const $q) ConsoleWrite("After:" & @TAB & $p & @LF) If ($p >= 0 And $q >= 0) Or ($p < 0 And $q < 0) Then ; possibility of overflow condition If $q >= 0 Then $plen = StringLen($p) $qlen = StringLen($q) If $plen > $qlen Then $str = StringRight($p, $qlen + 1) If StringLeft($str, 1) = 0 And StringLen($str) > 1 Then $res = "0" & $str + $q $result = StringLeft($p,$plen - ($qlen +1)) & $res Else $res = $str + $q $result = StringLeft($p,$plen - ($qlen +1)) & $res EndIf Else ;Your code here EndIf ConsoleWrite("But still returns scientific notation:" & @TAB & $result & @LF) If $result < $p Then ; overfloweth Return SetError(1, 0, "overflow") Else Return $result EndIf EndIf Else ; no possibility of overflow Return $p + $q EndIf EndFunc ;==>Calculator_Sum Edited July 23, 2010 by E1M1 edited Link to comment Share on other sites More sharing options...
jaberwacky Posted July 23, 2010 Author Share Posted July 23, 2010 Hey, that works for sure. Now to wonder why it doesn't work when I pass large numbers when using autoitobject. The workaround is nice but I'd like to be able to do it using integers though. Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
E1M1 Posted July 23, 2010 Share Posted July 23, 2010 maybe you have to recode AutoItObject.au3 for your needs. I think reason is that Autoit has it's limitations. I am not sure what causes this. edited 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