Dana Posted March 4, 2014 Posted March 4, 2014 I have, in part (this is obviously not complete code): $crackflow = 0.05 $flownow = 0 . . . $InCrackFlow = GUICtrlCreateInput($crackflow, 140, 224, 41, 21) . . . $nMsg = GUIGetMsg() Switch $nMsg Case $InCrackFlow $crackflow = GUICtrlRead($InCrackFlow) . . . While ($flownow < $crackflow) . . . (do more stuff...) If the user doesn't change the input field in question, the program runs correctly, exiting when $flownow (which comes via RS232 from a gas flow meter by other code, using Martin's excellent comm manager UDF) exceeds 0.05. However, if the value in $inCrackFlow is edited by the user, the while loop immediately exits. Took awhile, but it seems it's treating the edited value as text? If I change it to $crackflow = Number(GUICtrlRead($InCrackFlow)) it works as expected. I tried adding the $ES_NUMBER style to the input box, but that prevents me from inserting a decimal point, which certainly limits its usefulness. Other input boxes, where I'm not doing a greater than/less than comparison with the input value, seem to be correctly treated as a number. Why is it not treated as a number when doing a comparison?
FireFox Posted March 5, 2014 Posted March 5, 2014 Hi, Please show the comparison which fails. You can create an input limited to decimal numbers using WM_COMMAND (to get an event when the user enters smt) and a regex. Br, FireFox.
Dana Posted March 5, 2014 Author Posted March 5, 2014 Strange. It happens every time in the original program; the while statement evaluates as 0 and the loop terminates. However, I made a stripped down version: Opt("trayicondebug", 1) #include <GUIConstantsEx.au3> $crackflow = 0.05 ; lpm $Form1_1 = GUICreate("Form1", 600, 401) $LabCrackFlow = GUICtrlCreateLabel("Crack Flow", 40, 224) $InCrackFlow = GUICtrlCreateInput($crackflow, 140, 224, 41, 21) $ButStart = GUICtrlCreateButton("Start", 232, 344, 75, 25) $ButExit = GUICtrlCreateButton("Exit", 336, 344, 75, 25) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $ButExit Exit Case $InCrackFlow $crackflow = GUICtrlRead($InCrackFlow) Case $ButStart $flownow = "0.002 " While ($flownow < $crackflow) ConsoleWrite($flownow & @CRLF) $flownow = $flownow + .01 WEnd ConsoleWrite("Finished " & $flownow & @CRLF) EndSwitch WEnd In this version, I initialized $flownow as a string with a trailing space. The program executes correctly if I leave the input as is, and if I change the input to, say, 0.06. However, if I change the input to .06 (without the leading zero) the loop terminates on the first pass. Without the trailing space in the $flownow assigment, the program executes correctly. In the real program, the comm UDF returns the initial value as +0.002, perhaps there's a trailing space there that I'm not seeing. At any rate, it doesn't matter as using Number() to insure the values are numeric fixes it, and it's just a temporary test routine to evaluate some new hardware... I'd just like to know what's going on.
BrewManNH Posted March 5, 2014 Posted March 5, 2014 You should also check to see if the value from the input is a numeric before processing it, as an empty string when converted to a number = 0. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
Dana Posted March 6, 2014 Author Posted March 6, 2014 It's definitely not empty; I see each value received via RS232 (with a ConsoleWrite statement in the loop); the initial value always starts at +0.002. Something strange in how Autoit interprets a variant as a string or number.
BrewManNH Posted March 6, 2014 Posted March 6, 2014 GUICtrlRead from an input control returns a string, if you need it to be a number, you should use Number() on it, otherwise it might be misconverted during the check phase. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
grimmlock Posted March 7, 2014 Posted March 7, 2014 (edited) Quick question Dana, *Edit* Do you know what the correct output from should be from the ConsoleWrite, if a user changes the value from 0.05 to say 0.01? I think I may have a solution but wanted to make sure that I am getting the correct results before I post it. Thanks, Grimm Edited March 7, 2014 by grimmlock Thanks Grimm
grimmlock Posted March 7, 2014 Posted March 7, 2014 (edited) Let me know if this is what you are looking for - expandcollapse popupOpt("trayicondebug", 1) #include <GUIConstantsEx.au3> #Include <EditConstants.au3> $crackflow = 0.05 ; lpm $Form1_1 = GUICreate("Form1", 600, 401) $LabCrackFlow = GUICtrlCreateLabel("Crack Flow", 40, 224) $InCrackFlow = GUICtrlCreateInput($crackflow, 140, 224, 41, 21) $ButStart = GUICtrlCreateButton("Start", 232, 344, 75, 25) $ButExit = GUICtrlCreateButton("Exit", 336, 344, 75, 25) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $ButExit Exit Case $ButStart ; added an If Statement that looks at the value in the input box and if it does not contain a 0.X such as just .X then it will reset the data in the input box to have the 0.X value ; X = value in the Input field If Not Stringinstr(GUICtrlRead($InCrackFlow), "0.") Then GUICtrlSetData($InCrackFlow, "0" & GUICtrlRead($InCrackFlow)) ConsoleWrite("If Start = " & GUICtrlRead($InCrackFlow) & @CRLF); test to see if the .X value will re-display a 0.X value Else ConsoleWrite("Else Start = " & GUICtrlRead($InCrackFlow) & @CRLF) ; test else display what is the input field EndIf $flownow = "0.002" $crackflow = GUICtrlRead($InCrackFlow) ; moved from a case to here with the other name = value While ($flownow < $crackflow) ConsoleWrite($flownow & @CRLF) $flownow = $flownow + .01 WEnd ConsoleWrite("Finished " & $flownow & @CRLF) EndSwitch WEnd Take care Edited March 7, 2014 by grimmlock Thanks Grimm
Dana Posted March 11, 2014 Author Posted March 11, 2014 ConsoleWrite("0.002" < ".300") returns False ConsoleWrite(Number("0.002") < ".300") returns True ConsoleWrite("0.002" < "0.300") returns True ConsoleWrite(0.002 < "0.300") returns True ConsoleWrite(0.002 < ".300") returns True ConsoleWrite(+0.002 < ".300") returns True ConsoleWrite("+0.002" < ".300") returns False ConsoleWrite("+0.002" < "0.300") returns True ConsoleWrite("+0.002" < 1) returns True ConsoleWrite("+0.002" < "1") returns True ConsoleWrite("0.002 " < "0.300") returns True ConsoleWrite("0.002 " < ".300") returns False From this I deduce: If either value is an umbiguously numeric variable (assigned without quotes, or converted using Number()), then both values in the comparison are treated as numeric and the comparison is valid. If both values start as strings (assigned with quotes or from functions like GuiCtrlRead or StringSplit that provide strings), then both values must be unambiguously numeric (first character numeric, not a decimal point, and no extra characters) or the comparison will be invalid. Grimmlock's solution works by eliminating the leading decimal point, but using Number() is a cleaner solution.
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