jackrabbit Posted December 12, 2008 Share Posted December 12, 2008 (edited) Dear all, I met a strange case. Here is part of my code. $avg_CLoad = 0 For $i = 0 To 15 $avg_CLoad = $avg_CLoad + $CLoad [$i] MsgBox (0, "", $CLoad[$i] & "***" &$avg_CLoad) Next The values of array $CLoad are 4e-013, 4e-013, 4e-013, 4e-013, 8e-013, 8e-013, 8e-013, 8e-013, 1.2e-012, 1.2e-012, 1.2e-012, 1.2e-012, 1.9e-012, 1.9e-012 , 1.9e-012 , 1.9e-012. However, AutoIt always give me $avg_CLoad = 0. For some reason, it does interpret the $CLoad as 0. The MsgBox print $CLoad properly, but the $avg_CLoad are always 0. Then I added Number function to wrapper $CLoad. Then 4e-013 and 8e-013 are interpreted as 4 and 8! 1.2e-012 and 1.9e-012 are interpreted properly. But if I write a simple test code, autoit can interpret it correctly. I am not sure why this happened. Any advice? Thank you. Edited December 12, 2008 by jackrabbit Link to comment Share on other sites More sharing options...
martin Posted December 12, 2008 Share Posted December 12, 2008 Dear all, I met a strange case. Here is part of my code. $avg_CLoad = 0 For $i = 0 To 15 $avg_CLoad = $avg_CLoad + $CLoad [$i] MsgBox (0, "", $CLoad[$i] & "***" &$avg_CLoad) Next The values of array $CLoad are 4e-013, 4e-013, 4e-013, 4e-013, 8e-013, 8e-013, 8e-013, 8e-013, 1.2e-012, 1.2e-012, 1.2e-012, 1.2e-012, 1.9e-012, 1.9e-012 , 1.9e-012 , 1.9e-012. However, AutoIt always give me $avg_CLoad = 0. For some reason, it does interpret the $CLoad as 0. The MsgBox print $CLoad properly, but the $avg_CLoad are always 0. Then I added Number function to wrapper $CLoad. Then 4e-013 and 8e-013 are interpreted as 4 and 8! 1.2e-012 and 1.9e-012 are interpreted properly. But if I write a simple test code, autoit can interpret it correctly. I am not sure why this happened. Any advice? Thank you. No problem when I tried with production version 3.2.12.1 and Beta version 3.2.13.11. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
ProgAndy Posted December 12, 2008 Share Posted December 12, 2008 AutoIt doesn't handle thise numbers correctly if they are saved as a string. Just wrote a quick converter with Execute: Dim $CLoad[16] = ["4e-013", "4e-013", "4e-013", "4e-013", "8e-013", "8e-013", "8e-013", "8e-013", "1.2e-012", 1.2e-012, 1.2e-012, 1.2e-012, 1.9e-012, 1.9e-012 , 1.9e-012 , 1.9e-012] $avg_CLoad = 0 For $i = 0 To 15 $avg_CLoad = $avg_CLoad + _NumConvert($CLoad [$i]) MsgBox (0, "", $CLoad[$i] & "***" &$avg_CLoad) Next Func _NumConvert($expnum) ; by Prog@ndy <- do not remove this line Select Case IsNumber($expnum) Return $expnum Case StringIsInt($expnum) Or StringIsFloat($expnum) Return Number($expnum) Case StringRegExp($expnum,"\A\d+[eE][+-]?\d+\Z") Return Execute($expnum) EndSelect Return 0 EndFunc *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
martin Posted December 12, 2008 Share Posted December 12, 2008 (edited) AutoIt doesn't handle thise numbers correctly if they are saved as a string. Just wrote a quick converter with Execute: Dim $CLoad[16] = ["4e-013", "4e-013", "4e-013", "4e-013", "8e-013", "8e-013", "8e-013", "8e-013", "1.2e-012", 1.2e-012, 1.2e-012, 1.2e-012, 1.9e-012, 1.9e-012 , 1.9e-012 , 1.9e-012] $avg_CLoad = 0 For $i = 0 To 15 $avg_CLoad = $avg_CLoad + _NumConvert($CLoad [$i]) MsgBox (0, "", $CLoad[$i] & "***" &$avg_CLoad) Next Func _NumConvert($expnum) ; by Prog@ndy <- do not remove this line Select Case IsNumber($expnum) Return $expnum Case StringIsInt($expnum) Or StringIsFloat($expnum) Return Number($expnum) Case StringRegExp($expnum,"\A\d+[eE][+-]?\d+\Z") Return Execute($expnum) EndSelect Return 0 EndFunc If strings are being used then why not just have Dim $CLoad[16] = ["4e-013", "4e-013", "4e-013", "4e-013", "8e-013", "8e-013", "8e-013", "8e-013", "1.2e-012", 1.2e-012, 1.2e-012, 1.2e-012, 1.9e-012, 1.9e-012 , 1.9e-012 , 1.9e-012] $avg_CLoad = 0 For $i = 0 To 15 $avg_CLoad = $avg_CLoad + Execute($CLoad [$i]) MsgBox (0, "", $CLoad[$i] & "***" &$avg_CLoad) Next ? EDIT: I suppose that isn't the point of your post though, because you were giving a way to deal with whatever might be used. Edited December 12, 2008 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
ProgAndy Posted December 12, 2008 Share Posted December 12, 2008 (edited) Right, you could use execute directly, but i think this could be slower and it's not very save. Since i don't know, where the numbers come from, they could be user input, and Execute can be used to execute whole AutOit commands... Edited December 12, 2008 by ProgAndy *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
jackrabbit Posted December 12, 2008 Author Share Posted December 12, 2008 Thank you guys. After further check my code, I am so embarrassed to find that I made a mistake in my code. These values are extracted from a text file. When I extract them, I accidentally extract one more white space at the end of the string. So instead of "4e-013", it is really "4e-013 ". After I removed the white space and then it work. I am really appreciate your help and sorry for misleading you. 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