Sign in to follow this  
Followers 0
jfcby

[RESOLVED] Inputbox update GUI after file selection

4 posts in this topic

#1 ·  Posted (edited)

Hi,

How can I get my script to update the GUI after I select a file using a input box and saving the results to an ini file.

My ini file:

CODE
[Dirs]

DirAppDataCom=C:\Documents and Settings\All Users\Application Data

DirAppDataDir=C:\Documents and Settings\jfc14\Application Data

DirComFiles=C:\Program Files\Common Files

DirDsktpCom=C:\Documents and Settings\All Users\Desktop

DirDsktp=C:\Documents and Settings\jfc14\Desktop

DirDocCom=C:\Documents and Settings\All Users\Documents

DirMyDoc=C:\Documents and Settings\jfc14\My Documents

DirProFiles=C:\Program Files

DirProCom=C:\Documents and Settings\All Users\Start Menu\Programs

DirPro=C:\Documents and Settings\jfc14\Start Menu\Programs

DirSys=C:\WINDOWS\system32

ScriptFullPath=C:\Program Files\AutoIT3\My Projects\InputBox.au3

DirWin=C:\WINDOWS

DirWrk=C:\Program Files\AutoIT3\My Projects

CompName=OM-587485

[default]

setgdir=

setgpath=

setgfull=C:\Program Files\AutoIT3\My Projects\InputBox2.txt

setgexcelcap=InputBox2.txt - Notepad2

My Autoit code:

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

Global $sIni, $Dirs, $GUI

Global $DefsetgFull, $DefSetgDir, $DefSetgPath, $DefSetgExcelCap
Global $sFilePath1, $sFilePath2, $sFile
Global $array1

;Set ini file
$sIni = @ScriptDir & "\InputBox.ini"
_sIni()

;Read ini file
_rIni()

$GUI = GUICreate("InputBox", 350, 225) ; Create dialog box displayed center

; Main Label Title
$lbl_txt1 = GUICtrlCreateLabel("InputBox example test!", 5, 10, 345, 15, $SS_CENTER)

; Open File Label
$lbl_txt2 = GUICtrlCreateLabel("Select or Open File", 5, 75, 215, 25)

; Inputbox
$ipt_1 = GuiCtrlCreateInput($DefSetgFull, 5, 100, 330, 16, -1)

; Buttons
$btn_Select = GUICtrlCreateButton("Select", 185, 125, 75, 25)
$btn_Open = GUICtrlCreateButton("Open", 261, 125, 75, 25)

GUISetState() ; display dialog box

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $btn_Select
            ;Select File            
            $sFile = FileOpenDialog("Select file:", $DefSetgFull, "All Files (*.*)")
            If @error Then ContinueLoop
             GUICtrlSetData($ipt_1, $sFile) ; GUI will be updated at next iteration
             IniWrite($sIni, "default", "setgfull", $sFile)
             
             ;Read ini file
             _rINI()
             MsgBox(0, "", "Select: " & $DefSetgFull)
            
            ;Set selected file caption title
            $array1 = StringSplit($sFile, '\', 1)
            IniWrite($sIni, "default", "setgexcelcap", $array1[UBound($array1) -1] & " - Notepad2")             
            
        Case $msg = $btn_Open
            ;Open File
                MsgBox(1, "", StringLen($DefSetgExcelCap) & " -- " & $DefSetgExcelCap)
            If Not WinExists($DefSetgExcelCap) Then                 
                ;=MsgBox(1, "", $DefSetgExcelCap & " < Caption ---- Path > " & $sFilePath1)
                ;=MsgBox(1, "", $DefSetgFull & " < Default Full Path")
                MsgBox(0, "", "Open: " & $DefSetgFull)                  
                ShellExecute($DefSetgFull)
            EndIf
        EndSelect
    WEnd
        
    Func _exit()
        Exit
    EndFunc

    Func _sIni()
        ;Settings for ini file
        
        $Dirs = "DirAppDataCom=" & @AppDataCommonDir & @LF & _
                "DirAppDataDir=" & @AppDataDir & @LF & _
                "DirComFiles=" & @CommonFilesDir & @LF & _ 
                "DirDsktpCom=" & @DesktopCommonDir & @LF & _
                "DirDsktp=" & @DesktopDir & @LF & _
                "DirDocCom=" & @DocumentsCommonDir & @LF & _
                "DirMyDoc=" & @MyDocumentsDir & @LF & _
                "DirProFiles=" & @ProgramFilesDir & @LF & _
                "DirProCom=" & @ProgramsCommonDir & @LF & _
                "DirPro=" & @ProgramsDir & @LF &  _
                "DirSys=" & @SystemDir & @LF & _
                "ScriptFullPath=" & @ScriptFullPath & @LF & _
                "DirWin=" & @WindowsDir & @LF & _
                "DirWrk=" & @WorkingDir & @LF & _
                "CompName=" & @ComputerName & @LF 
        IniWriteSection($sIni, "Dirs", $Dirs)       
    EndFunc     ;iniFile
    
    Func _rIni()
        ;Read ini file
        $DefSetgDir = IniRead($sIni, "Default", "setgdir", "NotFound")
        $DefSetgPath = IniRead($sIni, "Default", "setgpath", "NotFound")
        $DefSetgFull = IniRead($sIni, "Default", "setgfull", "NotFound")
        $DefSetgExcelCap = IniRead($sIni, "Default", "setgexcelcap", "NotFound")        
    EndFunc

Thank you for yur help,

jfcby

Edited by jfcby

Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB ****

Share this post


Link to post
Share on other sites



See GUICtrlSetData() in the help file.

GUICtrlSetData($ipt_1, $sFile)

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

See GUICtrlSetData() in the help file.

GUICtrlSetData($ipt_1, $sFile)
GEOSoft,

Thanks for your reply.

1. Do I have

GUICtrlSetData($ipt_1, $sFile)
in the correct place.

1a. If not where should it be in the code?

2. I want only one instance of a file open. After I select a file I'm using WinExist to check if the file is open. Now, even if the file is open it opens another file.

How can I get the code to check if a file is open and open it if not found?

Thank you for yur help,

jfcby


Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB ****

Share this post


Link to post
Share on other sites

This is the completed working code:

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

Global $sIni, $Dirs, $GUI

Global $DefsetgFull, $DefSetgDir, $DefSetgPath, $DefSetgExcelCap
Global $sFilePath1, $sFilePath2, $sFile
Global $array1

;Set ini file
$sIni = @ScriptDir & "\InputBox.ini"
_sIni()

;Read ini file
_rIni()

$GUI = GUICreate("InputBox", 350, 225) ; Create dialog box displayed center

; Main Label Title
$lbl_txt1 = GUICtrlCreateLabel("InputBox example test!", 5, 10, 345, 15, $SS_CENTER)

; Open File Label
$lbl_txt2 = GUICtrlCreateLabel("Select or Open File", 5, 75, 215, 25)

; Inputbox
$ipt_1 = GuiCtrlCreateInput($DefSetgFull, 5, 100, 330, 16, -1)

; Buttons
$btn_Select = GUICtrlCreateButton("Select", 185, 125, 75, 25)
$btn_Open = GUICtrlCreateButton("Open", 261, 125, 75, 25)

GUISetState() ; display dialog box

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $btn_Select
            ;Select File            
            $sFile = FileOpenDialog("Select file:", $DefSetgFull, "All Files (*.*)")
            If @error Then ContinueLoop
             GUICtrlSetData($ipt_1, $sFile) ; GUI will be updated at next iteration
             IniWrite($sIni, "default", "setgfull", $sFile)
             
             ;Set selected file caption title
             $array1 = StringSplit($sFile, '\', 1)
             IniWrite($sIni, "default", "setgexcelcap", $array1[UBound($array1) -1] & " - Notepad2")    
             
             ;Read ini file
             _rINI()
             MsgBox(0, "", "Select: " & $DefSetgFull)
            
                        
            
        Case $msg = $btn_Open
            ;Open File
                MsgBox(1, "", StringLen($DefSetgExcelCap) & " -- " & $DefSetgExcelCap)
            If Not WinExists($DefSetgExcelCap) Then                 
                ;=MsgBox(1, "", $DefSetgExcelCap & " < Caption ---- Path > " & $sFilePath1)
                ;=MsgBox(1, "", $DefSetgFull & " < Default Full Path")
                MsgBox(0, "", "Open: " & $DefSetgFull)                  
                ShellExecute($DefSetgFull)
            EndIf
        EndSelect
    WEnd
        
    Func _exit()
        Exit
    EndFunc

    Func _sIni()
        ;Settings for ini file
        
        $Dirs = "DirAppDataCom=" & @AppDataCommonDir & @LF & _
                "DirAppDataDir=" & @AppDataDir & @LF & _
                "DirComFiles=" & @CommonFilesDir & @LF & _ 
                "DirDsktpCom=" & @DesktopCommonDir & @LF & _
                "DirDsktp=" & @DesktopDir & @LF & _
                "DirDocCom=" & @DocumentsCommonDir & @LF & _
                "DirMyDoc=" & @MyDocumentsDir & @LF & _
                "DirProFiles=" & @ProgramFilesDir & @LF & _
                "DirProCom=" & @ProgramsCommonDir & @LF & _
                "DirPro=" & @ProgramsDir & @LF &  _
                "DirSys=" & @SystemDir & @LF & _
                "ScriptFullPath=" & @ScriptFullPath & @LF & _
                "DirWin=" & @WindowsDir & @LF & _
                "DirWrk=" & @WorkingDir & @LF & _
                "CompName=" & @ComputerName & @LF 
        IniWriteSection($sIni, "Dirs", $Dirs)       
    EndFunc     ;iniFile
    
    Func _rIni()
        ;Read ini file
        $DefSetgDir = IniRead($sIni, "Default", "setgdir", "NotFound")
        $DefSetgPath = IniRead($sIni, "Default", "setgpath", "NotFound")
        $DefSetgFull = IniRead($sIni, "Default", "setgfull", "NotFound")
        $DefSetgExcelCap = IniRead($sIni, "Default", "setgexcelcap", "NotFound")        
    EndFunc

jfcby

1 person likes this

Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB ****

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