Sign in to follow this  
Followers 0
cvocvo

Input Box Problem

3 posts in this topic

I am working with a GUI input box. When I type in a number in the input box and click update, it works great; but, when I type another number in the box or just click update again, it doesn't work. The input box returns the value zero.

Any idea where I went wrong with this?

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <StaticConstants.au3>
Global $sPrevText, $MainInputNumber, $label
PartitionSliderMain()
Func PartitionSliderMain()
    $sNum = 43762
    $FormPartitionSliderMain = GUICreate("Title", 500, 350, 334, 140, $DS_MODALFRAME)
    $Label1 = GUICtrlCreateLabel("Title", 35, 24, 273, 43)
    GUICtrlSetFont($Label1, 24, 400, 0, "Tahoma")
    $NextButton = GUICtrlCreateButton("Next", 376, 265, 105, 49, 0)
    GUICtrlSetOnEvent($NextButton, "NextButtonclick")
    $label = GUICtrlCreateLabel("Desired Shrink Space (" & $MainInputNumber & "MB)", 320, 85, 200)
    $MainInputNumber = GUICtrlCreateInput("", 320, 100, 60, 20)
    GUICtrlSetLimit(-1, 7)
    $UPMainButton = GUICtrlCreateButton("Update", 380, 100, 60, 20)
    GUICtrlSetOnEvent($UPMainButton, "UPMainButtonclick")
    
    ;$shrinkname = "\shrink.jpg"
    ;$shrinkpath = @ScriptDir & $shrinkname
    ;$newpartitionname = "\newpartition.jpg"
    ;$newpartitionpath = @ScriptDir & $newpartitionname
    $RadioC = 0
    $RadioD = 1
    $RadioE = 0

    ;GUICtrlCreatePic($shrinkpath, 40, 80, 32, 32, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
    GUICtrlCreateLabel("C:\", 15, 90)
    $FreeCSpace = Round(DriveSpaceFree("C:\"), 0)
    $TotalCSpace = Round(DriveSpaceTotal("C:\"), 0)
    $PercentCFree = $FreeCSpace * 100 / $TotalCSpace
    $PercentCFree = Round($PercentCFree, 1) & "%"
    GUICtrlCreateLabel($FreeCSpace & " of " & $TotalCSpace & "MB Free " & $PercentCFree, 80, 85)
    GUICtrlCreateLabel("Available Shrink Space: " & $sNum & "MB", 80, 100)

    GUISetState(@SW_SHOW)

    While 1
        _Input_Check($MainInputNumber, False) ; False means limit to numbers
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $NextButton
                Exit
            Case $GUI_EVENT_CLOSE, $UPMainButton
                UPMainButtonclick()
        EndSwitch
    WEnd
EndFunc
Func UPMainButtonclick()
    $MainInputNumber = GUICtrlRead($MainInputNumber)
    MsgBox(0, "", "Test" & $MainInputNumber)
    GUICtrlSetData($label, "Desired Shrink Space (" & $MainInputNumber & "MB)")
EndFunc
Func _Input_Check($hInput, $fLetterFlag = True)

    ; Read input
    $sText = GUICtrlRead($MainInputNumber)
    If $fLetterFlag Then
        ; Upper case the input and reset the content
        $sText = StringUpper($sText)
        GUICtrlSetData($MainInputNumber, $sText)
    EndIf

    ; Check if there are any unwanted characters
    $sMsg = ""
    If $fLetterFlag Then
        ; And if so delete the non-letters
        If StringRegExp($sText, "[^A-Z]") Then GUICtrlSetData($MainInputNumber, StringRegExpReplace($sText, "[^A-Z]", ""))
    Else
        ; And if so delete the non-numbers
        If StringRegExp($sText, "[^0-9]") Then GUICtrlSetData($MainInputNumber, StringRegExpReplace($sText, "[^0-9]", ""))
    EndIf

EndFunc

Thanks

Share this post


Link to post
Share on other sites



Hi, in this line

$MainInputNumber = GUICtrlRead($MainInputNumber)

you are overwritting the control handle with the data fround in the control

Its easier to keep track of your variables if you use a naming method like $hForHandle and $sForString

$sMainInputNumber = GUICtrlRead($hMainInputNumber)

GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.

Share this post


Link to post
Share on other sites

Ah, I see thanks for the advice and pointing me in the right direction -- fixed that up quick.

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  
Followers 0