Sign in to follow this  
Followers 0
notta

Autofill input box from file

3 posts in this topic

#1 ·  Posted (edited)

Hey guys, I have this test GUI where I check to see if a file exists and if the file does exist it reads a comma delimited file and uses that info for the default value of the input box. For some reason this is not working like I thought it would. No matter if the file does exist or does not exist it's returning "not empty"

Is it because of how I declared the array that each element is actually null and not blank? That's the only reason I can think of why this is not working. All I'm trying to achieve is if a script has already been run on a users machine then my fields will be inputted with all the users previously entered data(first name, last name, phone,etc...) There are 25 columns in my csv file with some user info. Any ideas? Thanks.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <array.au3>

Opt('MustDeclareVars', 1)

Global $tempfnlabel = ""
Global $templastname = ""
Global $aTest[26]
Global $fopen1
Global $read
Global $okbtn
Example1()

; example 1
Func Example1()
    Local $msg

    if FileExists("1.csv") Then
        $fopen1 = FileOpen("1.csv",0)
        $read = FileReadLine($fopen1,1)
        $aTest = StringSplit($read,",")
        FileClose($fopen1)
    EndIf

    _ArrayDisplay($aTest)
    GUICreate("My GUI",500,500); will create a dialog box that when displayed is centered
    $tempfnlabel = GUICtrlCreateLabel ("First Name:",  10, 83)
    $tempfirstname = GuiCtrlCreateInput($aTest[1], 65, 80, 150, 20)
    GUICtrlSetLimit($tempfirstname,18)

    GUICtrlCreateLabel ("Last Name:",  255, 83)
    $templastname = GuiCtrlCreateInput($aTest[2], 310, 80, 150, 20)
    GUICtrlSetLimit($templastname,18)
    
    $okbtn = GUICtrlCreateButton ("Ok", 220,  455, 60, 20)
    GUICtrlSetState($okbtn,$GUI_ENABLE)
        GUISetState(@SW_SHOW)   ; will display an empty dialog box
    
; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()
        
        Select
            Case $msg = $okbtn
                if $tempfirstname == "" Then
                    MsgBox(0,"Error","Box is empty")
                Else
                                        msgbox(0,"",$tempfirstname);hmm this returns the value 4
                    MsgBox(0,"Error","Not empty")
                EndIf
            Case $msg = $GUI_EVENT_CLOSE
                Exit
        EndSelect
    WEnd
    GUIDelete()
EndFunc;==>Example1
Edited by notta

Share this post


Link to post
Share on other sites



You are using this statement in a wrong way:

if $tempfirstname == "" Then

this will be always false since you are testing a control and not its content (as long as $tempfirstname exists - your inputbox - its handle will be a numeric value)

To work you have to change the statement:

if GUICtrlRead($tempfirstname) = "" Then

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

You are using this statement in a wrong way:

if $tempfirstname == "" Then

this will be always false since you are testing a control and not its content (as long as $tempfirstname exists - your inputbox - its handle will be a numeric value)

To work you have to change the statement:

if GUICtrlRead($tempfirstname) = "" Then

Yep, it's been a while since I've added anything to my GUI so I forgot about using GUICtrlRead to get the actual value. Thanks for the help.

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