Jump to content

Recommended Posts

Posted

Sorry I'm new to this, and having got hold of some of the basics and played with some examples I still can't figure this one out.

What I want to do via a GUI is for the user to select a folder and for that folder to be displayed in an input box so there is a visual on screen of the folder location.

Later on in the script, (still writting all of it as solving each section a bit at a time) this input will be used as the Source and Destination folders.

I decided on the FileSelectFolder as it was the most straightforward way of solving drive and network locations across multiple machine.

 

Code so far

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
Opt("GUIOnEventMode", 1)
;Global &Source, &Destination
Global $Source
Global $FileSelectFolder1
Global $FileSelectFolder
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Copy Folder", 615, 438, 192, 124)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "Form1Minimize")
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "Form1Maximize")
GUISetOnEvent($GUI_EVENT_RESTORE, "Form1Restore")
$Copy = GUICtrlCreateButton("Copy", 184, 208, 161, 49)
GUICtrlSetOnEvent(-1, "CopyClick")
$SourceButton = GUICtrlCreateButton("SourceButton", 48, 40, 137, 41)
GUICtrlSetOnEvent(-1, "SourceButtonClick")
$DestButton = GUICtrlCreateButton("DestButton", 48, 104, 137, 41)
GUICtrlSetOnEvent(-1, "DestButtonClick")
$Progress1 = GUICtrlCreateProgress(104, 320, 425, 49)
$Source = GUICtrlCreateInput("Source", 240, 48, 321, 21)
GUICtrlSetOnEvent(-1, "SourceChange")
$Destination = GUICtrlCreateInput("Destination", 240, 120, 305, 21)
GUICtrlSetOnEvent(-1, "DestinationChange")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    Sleep(100)
WEnd

Func CopyClick()

EndFunc
Func DestButtonClick()
    Local Const $sMessage = "Select a folder"
    ; Display an open dialog to select a file.
    Local $sFileSelectFolder1 = FileSelectFolder($sMessage, "")
    If @error Then
        ; Display the error message.
        MsgBox($MB_SYSTEMMODAL, "", "No folder was selected.")
    Else
        ; Display the selected folder.
        MsgBox($MB_SYSTEMMODAL, "", "You chose the following folder:" & @CRLF & $sFileSelectFolder1)
    EndIf

EndFunc

Func DestinationChange()

EndFunc
Func Form1Close()

EndFunc
Func Form1Maximize()

EndFunc
Func Form1Minimize()

EndFunc
Func Form1Restore()

EndFunc
Func SourceButtonClick()
    Local Const $sMessage = "Select a folder"
    ; Display an open dialog to select a file.
    Local $sFileSelectFolder = FileSelectFolder($sMessage, "")
    If @error Then
        ; Display the error message.
        MsgBox($MB_SYSTEMMODAL, "", "No folder was selected.")
    Else
        ; Display the selected folder.
        MsgBox($MB_SYSTEMMODAL, "", "You chose the following folder:" & @CRLF & $sFileSelectFolder)

    EndIf

EndFunc   ;==>Example)

Func SourceChange()

EndFunc
Func Source()

EndFunc

 

 

Posted (edited)

I think you are searcing for GuiCtrlSetData.

 

Please use the code-tags ("<>") next time:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
Opt("GUIOnEventMode", 1)
;Global &Source, &Destination
Global $Source
Global $FileSelectFolder1
Global $FileSelectFolder
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Copy Folder", 615, 438, 192, 124)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "Form1Minimize")
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "Form1Maximize")
GUISetOnEvent($GUI_EVENT_RESTORE, "Form1Restore")
$Copy = GUICtrlCreateButton("Copy", 184, 208, 161, 49)
GUICtrlSetOnEvent(-1, "CopyClick")
$SourceButton = GUICtrlCreateButton("SourceButton", 48, 40, 137, 41)
GUICtrlSetOnEvent(-1, "SourceButtonClick")
$DestButton = GUICtrlCreateButton("DestButton", 48, 104, 137, 41)
GUICtrlSetOnEvent(-1, "DestButtonClick")
$Progress1 = GUICtrlCreateProgress(104, 320, 425, 49)
$Source = GUICtrlCreateInput("Source", 240, 48, 321, 21)
GUICtrlSetOnEvent(-1, "SourceChange")
$Destination = GUICtrlCreateInput("Destination", 240, 120, 305, 21)
GUICtrlSetOnEvent(-1, "DestinationChange")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    Sleep(100)
WEnd

Func CopyClick()

EndFunc   ;==>CopyClick
Func DestButtonClick()
    Local Const $sMessage = "Select a folder"
    ; Display an open dialog to select a file.
    Local $sFileSelectFolder1 = FileSelectFolder($sMessage, "")
    If @error Then
        ; Display the error message.
        MsgBox($MB_SYSTEMMODAL, "", "No folder was selected.")
    Else
        ; Display the selected folder.
        MsgBox($MB_SYSTEMMODAL, "", "You chose the following folder:" & @CRLF & $sFileSelectFolder1)
        GUICtrlSetData($Destination,$sFileSelectFolder1)    ;<===========
    EndIf

EndFunc   ;==>DestButtonClick

Func DestinationChange()

EndFunc   ;==>DestinationChange
Func Form1Close()

EndFunc   ;==>Form1Close
Func Form1Maximize()

EndFunc   ;==>Form1Maximize
Func Form1Minimize()

EndFunc   ;==>Form1Minimize
Func Form1Restore()

EndFunc   ;==>Form1Restore
Func SourceButtonClick()
    Local Const $sMessage = "Select a folder"
    ; Display an open dialog to select a file.
    Local $sFileSelectFolder = FileSelectFolder($sMessage, "")
    If @error Then
        ; Display the error message.
        MsgBox($MB_SYSTEMMODAL, "", "No folder was selected.")
    Else
        ; Display the selected folder.
        MsgBox($MB_SYSTEMMODAL, "", "You chose the following folder:" & @CRLF & $sFileSelectFolder)
        GUICtrlSetData($Source,$sFileSelectFolder)  ;<=========
    EndIf

EndFunc   ;==>SourceButtonClick

Func SourceChange()

EndFunc   ;==>SourceChange
Func Source()

EndFunc   ;==>Source

 

Edited by AutoBert
Posted (edited)

try this other way.. :)

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
Opt("GUIOnEventMode", 1)
;Global &Source, &Destination
Global $Source
Global $FileSelectFolder1
Global $FileSelectFolder
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Copy Folder", 615, 438, 192, 124)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "Form1Minimize")
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "Form1Maximize")
GUISetOnEvent($GUI_EVENT_RESTORE, "Form1Restore")
$Copy = GUICtrlCreateButton("Copy", 184, 208, 161, 49)
GUICtrlSetOnEvent(-1, "CopyClick")
$SourceButton = GUICtrlCreateButton("SourceButton", 48, 40, 137, 41)
GUICtrlSetOnEvent(-1, "SourceButtonClick")
$DestButton = GUICtrlCreateButton("DestButton", 48, 104, 137, 41)
GUICtrlSetOnEvent(-1, "DestButtonClick")
$Progress1 = GUICtrlCreateProgress(104, 320, 425, 49)
$Source = GUICtrlCreateInput("Source", 240, 48, 321, 21)
GUICtrlSetOnEvent(-1, "SourceChange")
$Destination = GUICtrlCreateInput("Destination", 240, 120, 305, 21)
GUICtrlSetOnEvent(-1, "DestinationChange")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    Sleep(100)
WEnd

Func CopyClick()

EndFunc   ;==>CopyClick
Func DestButtonClick()
    Local Const $sMessage = "Select a folder"
    ; Display an open dialog to select a file.
    Local $sFileSelectFolder1 = FileSelectFolder($sMessage, "")
    $_Path = _WinAPI_GetFullPathName($sFileSelectFolder1);-----------------------here
    If @error Then
        ; Display the error message.
        MsgBox($MB_SYSTEMMODAL, "", "No folder was selected.")
    Else
        ; Display the selected folder.
        GUICtrlSetData($Destination, $_Path);-----------------------here
        MsgBox($MB_SYSTEMMODAL, "", "You chose the following folder:" & @CRLF & $sFileSelectFolder1)
    EndIf

EndFunc   ;==>DestButtonClick

Func DestinationChange()

EndFunc   ;==>DestinationChange
Func Form1Close()

EndFunc   ;==>Form1Close
Func Form1Maximize()

EndFunc   ;==>Form1Maximize
Func Form1Minimize()

EndFunc   ;==>Form1Minimize
Func Form1Restore()

EndFunc   ;==>Form1Restore
Func SourceButtonClick()
    Local Const $sMessage = "Select a folder"
    ; Display an open dialog to select a file.
    Local $sFileSelectFolder = FileSelectFolder($sMessage, "")
    $_Path = _WinAPI_GetFullPathName($sFileSelectFolder);-----------------------here
    If @error Then
        ; Display the error message.
        MsgBox($MB_SYSTEMMODAL, "", "No folder was selected.")
    Else
        ; Display the selected folder.
        GUICtrlSetData($Source, $_Path);-----------------------here
        MsgBox($MB_SYSTEMMODAL, "", "You chose the following folder:" & @CRLF & $sFileSelectFolder)

    EndIf

EndFunc   ;==>SourceButtonClick

Func SourceChange()

EndFunc   ;==>SourceChange
Func Source()

EndFunc   ;==>Source

 

Edited by 232showtime

ill get to that... i still need to learn and understand a lot of codes graduated.gif

Correct answer, learn to walk before you take on that marathon.

Posted
11 minutes ago, 232showtime said:

try this other way.. :)

as i think after a small testing phase, the MsgBox will be removed for success, it's the same way as mine. :) And also with MsgBox the difference isn't so big to speak from a other way.

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...