Jump to content
Sign in to follow this  
Dana

GuiCtrlCreateInput, GuiCtrlRead, & value

Recommended Posts

Dana

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?

Share this post


Link to post
Share on other sites
FireFox

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.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
Dana

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.

Share this post


Link to post
Share on other sites
BrewManNH

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 Gude
How 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

Share this post


Link to post
Share on other sites
Dana

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.

Share this post


Link to post
Share on other sites
BrewManNH

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 Gude
How 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

Share this post


Link to post
Share on other sites
grimmlock

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 by grimmlock

Thanks

Grimm

Share this post


Link to post
Share on other sites
grimmlock

Let me know if this is what you are looking for -

Opt("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 :ph34r:

Edited by grimmlock

Thanks

Grimm

Share this post


Link to post
Share on other sites
Dana

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.

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  

×