Jump to content

GUICtrlRead not working - Help


aguynamedray
 Share

Recommended Posts

Hello,

It seems a little bit confused about GUICtrlRead function. I have to transfer my backup files to the server with the below code but seems not working. 

 

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)


$Form1 = GUICreate("Files Submission", 225, 152, 192, 124)
$Group1 = GUICtrlCreateGroup("", 8, 8, 121, 129)
$Input1 = GUICtrlCreateInput("", 24, 48, 89, 21)
GUICtrlSetLimit(-1, 3)
$Text1 = GUICtrlRead($Input1)
$Input2 = GUICtrlCreateInput("", 24, 96, 89, 21)
GUICtrlSetLimit(-1, 5)
$Text2 = GUICtrlRead($Input2)
$Label3 = GUICtrlCreateLabel("Days Code (WED)", 24, 31, 61, 17)
GUICtrlSetOnEvent(-1, "Label3Click")
$Label4 = GUICtrlCreateLabel("5 Digit Numbers (123458)", 24, 79, 79, 17)
GUICtrlSetOnEvent(-1, "Label4Click")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button1 = GUICtrlCreateButton("Submit", 136, 16, 75, 25)
GUICtrlSetOnEvent(-1, "Button1Click")
$Button2 = GUICtrlCreateButton("Exit", 136, 48, 75, 25)
GUICtrlSetOnEvent(-1, "Button2Click")
GUISetState(@SW_SHOW)


$FileDest = ("\\Server4\SORT\DAYS\" & $Text1)
$SourceFile = ("D:\DAYS\*.docx")


While 1
Sleep(500)
WEnd


Func Button1Click()
$FinalDest = DirCreate($FileDest & $Text2)
FileCopy($SourceFile, $FinalDest)
EndFunc


Func Button2Click()
Exit
EndFunc

Will someone help me sort it out? Thanks.

 

Link to comment
Share on other sites

Hello, the thing is that it is reading the input fields at start, never again since that, so what you have to do is move the ctrlread code to the routine associated with the action, in you case, to the button, as i don't know exaclty what you want, this may not be precise, but it may give you a general idea.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)

$Form1 = GUICreate("Files Submission", 225, 152, 192, 124)
$Group1 = GUICtrlCreateGroup("", 8, 8, 121, 129)
$Input1 = GUICtrlCreateInput("", 24, 48, 89, 21)
GUICtrlSetLimit(-1, 3)
$Input2 = GUICtrlCreateInput("", 24, 96, 89, 21)
GUICtrlSetLimit(-1, 5)
$Label3 = GUICtrlCreateLabel("Days Code (WED)", 24, 31, 61, 17)
GUICtrlSetOnEvent(-1, "Label3Click")
$Label4 = GUICtrlCreateLabel("5 Digit Numbers (123458)", 24, 79, 79, 17)
GUICtrlSetOnEvent(-1, "Label4Click")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button1 = GUICtrlCreateButton("Submit", 136, 16, 75, 25)
GUICtrlSetOnEvent(-1, "Button1Click")
$Button2 = GUICtrlCreateButton("Exit", 136, 48, 75, 25)
GUICtrlSetOnEvent(-1, "Button2Click")
GUISetState(@SW_SHOW)

$Text1 = GUICtrlRead($Input1) ;Read before use
$FileDest = ("\\Server4\SORT\DAYS\" & $Text1)
$SourceFile = ("D:\DAYS\*.docx")

While 1
Sleep(100)
WEnd

Func Button1Click()
$Text2 = GUICtrlRead($Input2) ;Read before use
$FinalDest = DirCreate($FileDest & $Text2)
FileCopy($SourceFile, $FinalDest)
EndFunc

Func Button2Click()
Exit
EndFunc
Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

I don't quiet understand your idea but thank you for the reply. What I mean is the data in input1 will be the directory to be created. See below: 

Input1 Data: THU

Server: Server4SORTDAYS

Result: Server4SORTDAYSTHU

The in input2 will be the sub-directory to be created. See below: 

 

Input2 Data: 12345

Parent directory created by Input1: Server4SORTDAYSTHU

Result: Server4SORTDAYSTHU12345

Link to comment
Share on other sites

The value of $FinalDest is also an issue as it is the value returned from DirCreate. DirCreate does not return a path for you to use as a destination in FileCopy.

And what careca is implying is to use GuiCtrlRead in the event function rather then in the Global code section as you need to read the inputs when the "Submit" button is pressed. So the process with the event is button -> function -> read controls and act on the information that was read.

I modified the code with removing $FinalDest and other bits that seemed unneeded. Added some error checking so it may alert you what is not valid. Added some comments to explain what is going on.

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)

; an array with days of the week
Global $Today[8] = [7, 'SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
; source files
$SourceFile = ("D:\DAYS\*.docx")

; create the gui
$Form1 = GUICreate("Files Submission", 225, 152, 192, 124)
; create a group of inputs
$Group1 = GUICtrlCreateGroup("", 8, 8, 121, 129)
$Input1 = GUICtrlCreateInput($Today[@MDAY], 24, 48, 89, 21)
GUICtrlSetLimit(-1, 3)
GUICtrlSetTip(-1, 'e.g. ' & $Today[@MDAY])
$Input2 = GUICtrlCreateInput("", 24, 96, 89, 21)
GUICtrlSetLimit(-1, 5)
GUICtrlSetTip(-1, 'e.g. 12345')
$Label3 = GUICtrlCreateLabel("Days Code", 24, 31, 61, 17)
$Label4 = GUICtrlCreateLabel("5 Digit Numbers", 24, 79, 79, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
; create the buttons
$Button1 = GUICtrlCreateButton("Submit", 136, 16, 75, 25)
GUICtrlSetOnEvent(-1, "Button1Click")
$Button2 = GUICtrlCreateButton("Exit", 136, 48, 75, 25)
GUICtrlSetOnEvent(-1, "Button2Click")
GUISetState(@SW_SHOW)

While 1
    Sleep(500)
WEnd

Exit

Func Button1Click()
    Local $valid, $Text1, $Text2, $FileDest
    ; read the inputs
    $Text1 = GUICtrlRead($Input1) ; e.g. WED
    $Text2 = GUICtrlRead($Input2) ; e.g. 12345
    ; check if day of week input is valid
    For $1 = 1 To UBound($Today) -1
        If $Text1 = $Today[$1] Then
            $Text1 = StringUpper($Text1)
            $valid = True
            ExitLoop
        EndIf
    Next
    If Not $valid Then
        MsgBox(0x30, 'Invalid Input', 'Day code requires to be 3 letters and a valid day e.g. ' & $Today[@MDAY], 0, $Form1)
        Return 0
    EndIf
    ; check if input of digits is valid
    If Not StringIsDigit($Text2) Then
        MsgBox(0x30, 'Invalid Input', 'Require up to 5 digit numbers', 0, $Form1)
        Return 0
    EndIf
    ; build a path to the day folder
    $FileDest = "\\Server4\SORT\DAYS\" & $Text1
    ; the next line is debug only to test with so remove this line and the next when tested as ok
    Return MsgBox(0, 'FileCopy parameters', $SourceFile & ' , ' & $FileDest & '\' & $Text2, 0, $Form1); debug line only
    ; create the folder path to the folder named with digits else warn of error if unable to create the folder
    If DirCreate($FileDest & '\' & $Text2) Then
        ; copy the files to the digit folder and warn of error if the copy fails
        If Not FileCopy($SourceFile, $FileDest & '\' & $Text2) Then
            MsgBox(0x30, 'Warning', 'File copy error detected', 0, $Form1)
        EndIf
    Else
        MsgBox(0x30, 'Warning', 'Directory creation error detected', 0, $Form1)
    EndIf
EndFunc

Func Button2Click()
    Exit
EndFunc

The Return Msgbox() line is just for testing with what parameters are going to be passed to the FileCopy function. You can remove that line when you are satisfied with the result. :)

Link to comment
Share on other sites

Glad you sorted it, but, that's it? I mean... ok

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
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
 Share

  • Recently Browsing   0 members

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