Sign in to follow this  
Followers 0
jtsteffen

GUICtrlSetData does not update data

4 posts in this topic

Hello

I have been trying to get the GUICtrlSetData command to update the text in a Input control and just cannot seem to get it to work. In my troubleshooting, I can get the text to update if I insert theGUICtrlSetData earlier in the code and manually set the value to something, but if I try to do it after returning from a Sub, it will not. I suspect I have to be missing something very easy.

I've attached a sample of the code. It looks for a *.db file to load. To use it you would need to create a blank *.db file on your hard drive to find.

If anyone can explain why the Input line will not update to the file name after I return from the subroutine, I would be greatly appreciative.

Thanks

#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstants.au3>
#include <Misc.au3>                                             
#include <String.au3>                                               
#include <EditConstants.au3>                                        
#include <GUIConstantsEx.au3>   
#include <ButtonConstants.au3>

; Important Files to Know
Global $vsFold_Reference=@MyDocumentsDir                            ; My Documents
Global $vsFolderName1                                               ; Path to Folder 1
Global $vsFolderName2                                               ; Path to Folder 2
Global $vsFileName1                                                 ; Path to File 1
Global $vsFileName2                                                 ; Path to File 2
Global $hFolder1                                                    ; Handle for Folder 1
Global $hFolder2                                                    ; Handle for Folder 2
Global $hFile1                                                      ; Handle for File 1
Global $hFile2                                                      ; Handle for File 2

; Declare Local Variables

; Button Handles
Local $bClose                                                       ; Close the Program
Local $bDBtoINI                                                     ; Convert DBMain.DB to INI file
Local $bINItoDB                                                     ; Convert INI file to DBMain.db

; Declare GUI Variables
Local $wMainWin                                                     ; Handle of Window main GUI
Local $mFileMenu                                                    ; Handle of Menu File
Local $iExitItem                                                    ; Handle of SubMenu Exit in File
Local $mHelpMenu                                                    ; Handle of Menu Help
Local $mManageINI                                                   ; Handle of Menu Manage INI
Local $iLoadItem                                                    ; Handle of SubMenu Load
Local $iSyncIniItem                                                 ; Handle of SubMenu for Syncing Data
Local $iSplitBaseItem                                               ; Handle of SubMenu for Splitting Base Station Info out of dbmain.db
Local $iSplitBaseIniItem                                            ; Handle of SubSubMenu for Splitting INI Base Station Info out of dbmain.ini
Local $iSplitBaseDbItem                                             ; Handle of SubSubMenu for Splitting DB Base Staiton Info out of dbmain.db
Local $Msg                                                          ; Variable handling GUI Control

; Declare Program Variables
Local $MsgBoxAns                                                    ; Answer to Message Box

; Start the program
_Main()

Func _Main()
    ; Create GUI
    $wMainWin = GUICreate("Test", 500, 300)

; Create Buttons and Check Boxes
    $bClose = GUICtrlCreateButton("&Close", 390, 140, 90)
    $bDBtoINI = GUICtrlCreateButton("&DB to INI", 390,15,90,45)
    $bINItoDB = GUICtrlCreateButton("&INI to DB", 390,75,90,45)
    
    ; Create Main GUI Text
    GUICtrlCreateLabel("File Loaded:", 10, 19, 60, 25)
    $hFile1 = GUICtrlCreateInput($vsFileName1, 75, 17, 300, 27, $ES_READONLY, $WS_EX_STATICEDGE)
    GUICtrlCreateLabel("Folder Location:", 10, 62, 60, 25)
    $hFolder1 = GUICtrlCreateInput($vsFolderName1, 75, 65, 300, 27, $ES_READONLY, $WS_EX_STATICEDGE)

    ; Create File Menus and Lists
    $mFileMenu = GUICtrlCreateMenu("File")
    $iExitItem = GUICtrlCreateMenuItem("Exit", $mFileMenu)
    $mManageINI = GUICtrlCreateMenu("Manage Database")
    $iSplitBaseItem = GUICtrlCreateMenu("Split Base Data From", $mManageINI, 1)
    $iSyncIniItem = GUICtrlCreateMenuItem("Sync Data", $mManageINI, 2)
    $iSplitBaseIniItem = GUICtrlCreateMenuItem("INI", $iSplitBaseItem)
    $iSplitBaseDbItem = GUICtrlCreateMenuItem("DB", $iSplitBaseItem)
    $mHelpMenu = GUICtrlCreateMenu("Help")

    GUICtrlSetState ($iSyncIniItem, $GUI_DISABLE)
    GUICtrlSetState ($iSplitBaseIniItem, $GUI_DISABLE)

; Show the GUICreate
    GUISetState(@SW_SHOW)
    While 1
        $Msg = GUIGetMsg()
        Select
            Case $Msg = $bClose                         ; Pressed the close button
                Exit
            Case $Msg = $GUI_EVENT_CLOSE                ; Corner X pressed
                Exit
            Case $Msg = $iSplitBaseDbItem               ; Split the Db file into separate files with one Base Station
                _ClearAllData($wMainWin)
                GUICtrlSetData($hFile1, $vsFileName1)
                GUICtrlSetData($hFolder1, StringRight($vsFolderName1,54))
                _SelectFile1($wMainWin)
                GUICtrlSetData($hFile1, $vsFileName1)
                GUICtrlSetData($hFolder1, StringRight($vsFolderName1,54))
            Case $Msg = $iExitItem                      ; Exit choses from the Main Menu
                Exit
        EndSelect
    Wend
EndFunc

Func _SelectFile1($wParWin)
; Select the DB1 file to open

    ; Declare GUI variables
    Local $vsTempFolder                                                                                         ; Temporary Existing Folder Name
    
    ;Start Code
    $vsTempFolder = FileOpenDialog("Choose the DBMAIN.DB file to Open", $vsFold_Reference, "dbmain.db (*.db)", 1 + 2, "", $wParWin) ; Select desired dbmain.db
    If @error = 1 Then Return                                                                                   ; If nothing is selected go back to Main Menu

    ; Extract File and Folder Info
    $vsFolderName1 = StringLeft($vsTempFolder,(StringInStr($vsTempFolder,"\",0,-1)))                        ; Get Folder Name from Filename
    $vsFileName1 = StringRight($vsTempFolder,StringLen($vsTempFolder) - StringInStr($vsTempFolder,"\",0,-1))  ; Get File Name from Filename
    If StringLower(StringRight($vsTempFolder,3)) <> ".db" Then                                                  ; Verify it is a *.db
        MsgBox(1,"Incorrect File Format",$vsDB1FileName & " is not a valid file to convert.  Please make sure the file ends in *.db before attempting to " & _
            "Convert it.",0,$wParWin)
        Return
    EndIf

    ; Reassign Reference Folder to current folder
    If $vsFolderName1 <> "" Then $vsFold_Reference = $vsFolderName1
EndFunc

Func _ClearAllData($wParWin)
; clear the data out of the existing variables
    $vsFolderName1 = ""
    $vsFolderName2 = ""
    $vsFileName1 = ""
    $vsFileName2 = ""
    $hFolder1 = ""
    $hFolder2 = ""
    $hFile1 = ""
    $hFile2 = ""

EndFunc

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hi jtsteffen,

your handle for the input control may not be accessible if you call it from another function.

Try declaring it as a global variable first. :unsure:

global $i

Func _main()
   $h = GUICreate()
   $i = GUiCtrlCreateInput()
EndFunc

Func _change()
   GUICtrlSetData($i, "New Value")
EndFunc

Edit: Added example.

Edited by Hannes123

Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

Share this post


Link to post
Share on other sites

jtsteffen,

Your _ClearAllData function destroys not only the data but also the ControlIDs of the Input controls. :unsure:

Just remove these lines:

$hFolder1 = ""
$hFolder2 = ""
$hFile1 = ""
$hFile2 = ""

from the function and all works as it should. :>

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Okay, I feel like a moron now. I knew it had to be something easy like that.

Thanks for the quick response. I've been banging my head on that one for some time.

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