Jump to content
Sign in to follow this  
blckpythn

Else syntax error

Recommended Posts

blckpythn

I can't understand exactly why but every one of my functions returns an Else syntax error.

For example

Func A()
    If $A = $GUI_CHECKED Then $AB = " /A" Else $AB = ""
EndFunc   ;==>A

Returns

C:\Directory\File.au3(242,40) : ERROR: syntax error
    If $A = $GUI_CHECKED Then $AB = " /A" Else
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

Share this post


Link to post
Share on other sites
AdamUL

You cannot use Else on a one line If statement. Quoted from the help file

If <expression> Then statement

For other forms of If you must use the syntax

If <expression> Then

statements

...

[ElseIf expression-n Then

[elseif statements ... ]]

...

[Else

[else statements]

...

EndIf

Here is your function updated.

Func A()
  If $A = $GUI_CHECKED Then 
    $AB = " /A" 
  Else 
    $AB = "" 
  EndIf
EndFunc   ;==>A

Adam

Share this post


Link to post
Share on other sites
blckpythn

Well, that seems to fix it but I'm still having problems

They aren't changing the values properly.

And my If checked then guictrlsetstate gui_enabled

Here is my entire script

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_Comment=XGUI is a graphical Xcopy interface.
#AutoIt3Wrapper_Res_Description=XGUI is a graphical Xcopy interface.
#AutoIt3Wrapper_Res_Fileversion=4.21.2010
#AutoIt3Wrapper_Res_LegalCopyright=TBD
#AutoIt3Wrapper_Run_Tidy=y
#AutoIt3Wrapper_Run_Obfuscator=y
#Obfuscator_Parameters=/striponly
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=C:\Users\Matthew\Desktop\XCopy_GUI.kxf
$XCopy_GUI = GUICreate("XGUI - msdewart", 410, 393, 250, 164)
$Parameters = GUICtrlCreateGroup("", 10, 5, 380, 326)
$Source = GUICtrlCreateInput("Source", 30, 25, 260, 21)
$BrowseSource = GUICtrlCreateButton("Browse", 300, 25, 80, 25, $WS_GROUP)
$Destination = GUICtrlCreateInput("Destination", 30, 55, 260, 21)
$BrowseDest = GUICtrlCreateButton("Browse", 300, 55, 80, 25, $WS_GROUP)
$EXCLUDE = GUICtrlCreateCheckbox("/EXCLUDE", 30, 85, 80, 17)
$D = GUICtrlCreateCheckbox("/D:m-d-y", 30, 115, 80, 17)
GUICtrlSetTip(-1, "Date must be m-d-y format. All files made on or after date entered will be copied.")
$FileExcludeInput = GUICtrlCreateInput("Exclude Files by Name", 120, 85, 170, 21)
GUICtrlSetTip(-1, "file1[+file2][+file3]...Specifies a list of files containing strings.  Each string should be in a separate line in the files.  When any of the strings match any part of the absolute path of the file to be copied, that file will be excluded from being copied.  For example, specifying a string like \obj\ or .obj will exclude all files underneath the directory obj or all files with the .obj extension respectively.")
GUICtrlSetState($FileExcludeInput, $GUI_DISABLE)
$DateInput = GUICtrlCreateInput("Copy files made m-d-y or later.", 120, 115, 170, 21)
GUICtrlSetTip(-1, "Copies files changed on or after the specified date. If no date is given, copies only those whose source time is newer than the destination time.")
GUICtrlSetState($DateInput, $GUI_DISABLE)
$A = GUICtrlCreateCheckbox("/A", 22, 149, 97, 17)
GUICtrlSetTip(-1, "Copies only files with the archive attribute set, doesn't c hange the attribute.")
$M = GUICtrlCreateCheckbox("/M", 22, 169, 97, 17)
GUICtrlSetTip(-1, "Copies only files with the archive attribute set, turns off the archive attribute.")
$P = GUICtrlCreateCheckbox("/P", 22, 189, 97, 17)
GUICtrlSetTip(-1, "Prompts you before creating each destination file.")
$S = GUICtrlCreateCheckbox("/S", 22, 209, 97, 17)
GUICtrlSetTip(-1, "Copies directories and subdirectories except empty ones.")
$E = GUICtrlCreateCheckbox("/E", 22, 229, 97, 17)
GUICtrlSetTip(-1, "Copies directories and subdirectories, including empty ones. Same as /S /E. May be used to modify /T.")
$V = GUICtrlCreateCheckbox("/V", 22, 249, 97, 17)
GUICtrlSetTip(-1, "Verifies each new file.")
$W = GUICtrlCreateCheckbox("/W", 22, 269, 97, 17)
GUICtrlSetTip(-1, "Prompts you to press a key before copying.")
$T = GUICtrlCreateCheckbox("/T", 152, 289, 97, 17)
GUICtrlSetTip(-1, "Creates directory structure, but does not copy files. Does not include empty directories or subdirectories. /T /E includes")
$R = GUICtrlCreateCheckbox("/R", 152, 269, 97, 17)
GUICtrlSetTip(-1, "Overwrites read-only files.")
$H = GUICtrlCreateCheckbox("/H", 152, 249, 97, 17)
GUICtrlSetTip(-1, "Copies hidden and system files also.")
$G = GUICtrlCreateCheckbox("/G", 152, 229, 97, 17)
GUICtrlSetTip(-1, "Allows the copying of encrypted files to destination that does not support encryption.")
$L = GUICtrlCreateCheckbox("/L", 152, 209, 97, 17)
GUICtrlSetTip(-1, "Displays files that would be copied.")
$F = GUICtrlCreateCheckbox("/F", 152, 189, 97, 17)
GUICtrlSetTip(-1, "Displays full source and destination file names while copying.")
$Q = GUICtrlCreateCheckbox("/Q", 152, 169, 97, 17)
GUICtrlSetTip(-1, "Does not display file names while copying.")
$I = GUICtrlCreateCheckbox("/I", 152, 149, 97, 17)
GUICtrlSetTip(-1, "If destination does not exist and copying more than one file, assumes that destination must be a directory.")
$C = GUICtrlCreateCheckbox("/C", 22, 289, 97, 17)
$Z = GUICtrlCreateCheckbox("/Z", 290, 289, 97, 17)
GUICtrlSetTip(-1, "Continues copying even if errors occur.")
$Y2 = GUICtrlCreateCheckbox("/-Y", 290, 269, 97, 17)
GUICtrlSetTip(-1, "Causes prompting to confirm you want to overwrite an existing destination file.")
$Y = GUICtrlCreateCheckbox("/Y", 290, 249, 97, 17)
GUICtrlSetTip(-1, "Suppresses prompting to confirm you want to overwrite an existing destination file.")
$X = GUICtrlCreateCheckbox("/X", 290, 229, 97, 17)
GUICtrlSetTip(-1, "Copies file audit .")
$O = GUICtrlCreateCheckbox("/O", 290, 209, 97, 17)
GUICtrlSetTip(-1, "Copies file ownership and ACL information.")
$N = GUICtrlCreateCheckbox("/N", 290, 189, 97, 17)
GUICtrlSetTip(-1, "Copies using the generated short names.")
$K = GUICtrlCreateCheckbox("/K", 290, 169, 97, 17)
GUICtrlSetTip(-1, "Copies attributes. Normal Xcopy will reset read-only attributes.")
$U = GUICtrlCreateCheckbox("/U", 290, 149, 97, 17)
GUICtrlSetTip(-1, "Copies only files that already exist in destination.")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Copy = GUICtrlCreateButton("Copy", 290, 335, 90, 45, $WS_GROUP)
GUICtrlSetTip(-1, "Copies the source to the directory using the selected parameters")
$Close = GUICtrlCreateButton("Close", 180, 345, 80, 25, $WS_GROUP)
GUICtrlSetTip(-1, "Exit Xcopy GUI")
$About = GUICtrlCreateButton("About", 20, 361, 80, 25, $WS_GROUP)
GUICtrlSetTip(-1, "Displays XGUI Info")
$Help = GUICtrlCreateButton("Help", 20, 337, 80, 25, $WS_GROUP)
GUICtrlSetTip(-1, "Displays Xcopy info")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Global $SourcePath
Global $DestPath
Global $Date
Global $DateOutput
Global $ExcludedFiles
Global $Excluded
Global $AB
Global $EB
Global $PB
Global $SB
Global $VB
Global $WB
Global $CB
Global $IB
Global $QB
Global $FB
Global $LB
Global $GB
Global $HB
Global $RB
Global $TB
Global $UB
Global $KB
Global $NB
Global $OB
Global $XB
Global $YB
Global $Y2B
Global $ZB

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Source
            Source()
        Case $BrowseSource
            BrowseSource()
        Case $Destination
            Destination()
        Case $BrowseDest
            BrowseDest()
        Case $D
            D()
        Case $DateInput
            DateInput()
        Case $EXCLUDE
            EXCLUDE()
        Case $FileExcludeInput
            FileExcludeInput()
        Case $A
            A()
        Case $M
            M()
        Case $P
            P()
        Case $S
            S()
        Case $E
            E()
        Case $V
            V()
        Case $W
            W()
        Case $T
            T()
        Case $R
            R()
        Case $H
            H()
        Case $G
            G()
        Case $L
            L()
        Case $F
            F()
        Case $Q
            Q()
        Case $I
            I()
        Case $C
            C()
        Case $Z
            Z()
        Case $Y2
            Y2()
        Case $Y
            Y()
        Case $X
            X()
        Case $O
            O()
        Case $N
            N()
        Case $K
            K()
        Case $U
            U()
        Case $Copy
            Copy()
        Case $Close
            Exit
        Case $Help
            Help()
        Case $About
            About()
    EndSwitch
WEnd

Func BrowseSource()
    $SourcePath = FileSelectFolder("Select Source Path", Default, 7, Default)
    GUICtrlSetData($Source, $SourcePath, Default)
EndFunc   ;==>BrowseSource

Func Source()
    $SourcePath = GUICtrlRead($Source)
EndFunc   ;==>Source

Func BrowseDest()
    $DestPath = FileSelectFolder("Select Destination Path", Default, 7, Default)
    GUICtrlSetData($Destination, $DestPath, Default)
EndFunc   ;==>BrowseDest

Func Destination()
    $DestPath = GUICtrlRead($Destination)
EndFunc   ;==>Destination

Func D()
    If $D = $GUI_CHECKED Then
        GUICtrlSetState($DateInput, $GUI_ENABLE)
    Else
        GUICtrlSetState($DateInput, $GUI_DISABLE)
    EndIf
EndFunc   ;==>D

Func DateInput()
    If $D = $GUI_CHECKED Then
        $DateOutput = " /D:" & $Date
    Else
        $DateOutput = ""
    EndIf
EndFunc   ;==>DateInput

Func EXCLUDE()
    If $EXCLUDE = $GUI_CHECKED Then
        GUICtrlSetState($FileExcludeInput, $GUI_ENABLE)
    Else
        GUICtrlSetState($FileExcludeInput, $GUI_DISABLE)
    EndIf
EndFunc   ;==>EXCLUDE

Func FileExcludeInput()
    If $Excluded = $GUI_CHECKED Then
        $Excluded = " /EXCLUDE " & $ExcludedFiles
    Else
        $Excluded = ""
    EndIf
EndFunc   ;==>FileExcludeInput

Func A()
    If $A = $GUI_CHECKED Then
        $AB = " /A"
    Else
        $AB = ""
    EndIf
EndFunc   ;==>A


Func M()
    If $M = $GUI_CHECKED Then
        $MB = " /M"
    Else
        $MB = ""
    EndIf
EndFunc   ;==>M

Func P()
    If $P = $GUI_CHECKED Then
        $PB = " /P"
    Else
        $PB = ""
    EndIf
EndFunc   ;==>P

Func S()
    If $S = $GUI_CHECKED Then
        $SB = " /S"
    Else
        $SB = ""
    EndIf
EndFunc   ;==>S

Func E()
    If $E = $GUI_CHECKED Then
        $EB = " /E"
    Else
        $EB = ""
    EndIf
EndFunc   ;==>E

Func V()
    If $V = $GUI_CHECKED Then
        $VB = " /V"
    Else
        $VB = ""
    EndIf
EndFunc   ;==>V

Func W()
    If $W = $GUI_CHECKED Then
        $WB = " /W"
    Else
        $WB = ""
    EndIf
EndFunc   ;==>W

Func T()
    If $T = $GUI_CHECKED Then
        $TB = " /T"
    Else
        $TB = ""
    EndIf
EndFunc   ;==>T

Func R()
    If $R = $GUI_CHECKED Then
        $RB = " /R"
    Else
        $RB = ""
    EndIf
EndFunc   ;==>R

Func H()
    If $H = $GUI_CHECKED Then
        $HB = " /H"
    Else
        $HB = ""
    EndIf
EndFunc   ;==>H

Func G()
    If $G = $GUI_CHECKED Then
        $GB = " /G"
    Else
        $GB = ""
    EndIf
EndFunc   ;==>G

Func L()
    If $L = $GUI_CHECKED Then
        $LB = " /L"
    Else
        $LB = ""
    EndIf
EndFunc   ;==>L

Func F()
    If $F = $GUI_CHECKED Then
        $FB = " /F"
    Else
        $FB = ""
    EndIf
EndFunc   ;==>F

Func Q()
    If $Q = $GUI_CHECKED Then
        $QB = " /Q"
    Else
        $QB = ""
    EndIf
EndFunc   ;==>Q

Func I()
    If $I = $GUI_CHECKED Then
        $IB = " /I"
    Else
        $IB = ""
    EndIf
EndFunc   ;==>I

Func C()
    If $C = $GUI_CHECKED Then
        $CB = " /C"
    Else
        $CB = ""
    EndIf
EndFunc   ;==>C

Func Z()
    If $Z = $GUI_CHECKED Then
        $ZB = " /Z"
    Else
        $ZB = ""
    EndIf
EndFunc   ;==>Z

Func Y2()
    If $Y2 = $GUI_CHECKED Then
        $Y2B = " /-Y"
    Else
        $Y2B = ""
    EndIf
EndFunc   ;==>Y2

Func Y()
    If $Y = $GUI_CHECKED Then
        $YB = " /Y"
    Else
        $YB = ""
    EndIf
EndFunc   ;==>Y

Func X()
    If $X = $GUI_CHECKED Then
        $XB = " /X"
    Else
        $XB = ""
    EndIf
EndFunc   ;==>X

Func O()
    If $O = $GUI_CHECKED Then
        $OB = " /O"
    Else
        $OB = ""
    EndIf
EndFunc   ;==>O

Func N()
    If $N = $GUI_CHECKED Then
        $NB = " /N"
    Else
        $NB = ""
    EndIf
EndFunc   ;==>N

Func K()
    If $K = $GUI_CHECKED Then
        $KB = " /K"
    Else
        $KB = ""
    EndIf
EndFunc   ;==>K

Func U()
    If $U = $GUI_CHECKED Then
        $UB = " /U"
    Else
        $UB = ""
    EndIf
EndFunc   ;==>U


Func Copy()
    $Date = GUICtrlRead($DateInput)
    $ExcludedFiles = GUICtrlRead($FileExcludeInput)
    MsgBox(0, "Results", $SourcePath & " " & $DestPath & " " & $DateOutput & " " & $Excluded & $AB & $EB & $PB & $SB & $VB & $WB & $CB & $IB & $QB & $FB & $LB & $GB & $HB & $RB & $TB & $UB & $KB & $NB & $OB & $XB & $YB & $Y2B & $ZB, Default, Default)
EndFunc   ;==>Copy

;~ Func Copy()
;~  $Date = GUICtrlRead($DateInput)
;~  $ExcludedFiles = GUICtrlRead($FileExcludeInput)
;~  Run("cmd.exe /c xcopy " & $SourcePath & $DestPath & $DateOutput & $Excluded & $AB & $EB & $PB & $SB & $VB & $WB & $CB & $IB & $QB & $FB & $LB & $GB & $HB & $RB & $TB & $UB & $KB & $NB & $OB & $XB & $YB & $Y2B & $ZB, @WindowsDir)
;~ EndFunc   ;==>Copy

Func About()
    MsgBox(0, "About XGUI", "This program was written as a low resource alternative to RichCopy." & @CRLF & _
            @CRLF & _
            "                            Written by Matthew Dewart 4/21/2010")
EndFunc   ;==>About

Func Help()
    Local $helptext = "XCOPY [source] [destination] [/A | /M] [/D[:date]] [/P] [/S [/E]] [/V] [/W]" & @CRLF & _
            "                           [/C] [/I] [/Q] [/F] [/L] [/G] [/H] [/R] [/T] [/U]" & @CRLF & _
            "                           [/K] [/N] [/O] [/X] [/Y] [/-Y] [/Z]" & @CRLF & _
            "                           [/EXCLUDE:file1[+file2][+file3]...]" & @CRLF & _
            @CRLF & _
            "  source       Specifies the file(s) to copy." & @CRLF & _
            "  destination  Specifies the location and/or name of new files." & @CRLF & _
            "  /A           Copies only files with the archive attribute set," & @CRLF & _
            "               doesn't change the attribute." & @CRLF & _
            "  /M           Copies only files with the archive attribute set," & @CRLF & _
            "               turns off the archive attribute." & @CRLF & _
            "  /D:m-d-y     Copies files changed on or after the specified date." & @CRLF & _
            "               If no date is given, copies only those files whose" & @CRLF & _
            "               source time is newer than the destination time." & @CRLF & _
            "  /EXCLUDE:file1[+file2][+file3]..." & @CRLF & _
            "               Specifies a list of files containing strings.  Each string" & @CRLF & _
            "               should be in a separate line in the files.  When any of the" & @CRLF & _
            "               strings match any part of the absolute path of the file to be" & @CRLF & _
            "               copied, that file will be excluded from being copied.  For" & @CRLF & _
            "               example, specifying a string like \obj\ or .obj will exclude" & @CRLF & _
            "               all files underneath the directory obj or all files with the" & @CRLF & _
            "               .obj extension respectively." & @CRLF & _
            "  /P           Prompts you before creating each destination file." & @CRLF & _
            "  /S           Copies directories and subdirectories except empty ones." & @CRLF & _
            "  /E           Copies directories and subdirectories, including empty ones." & @CRLF & _
            "               Same as /S /E. May be used to modify /T." & @CRLF & _
            "  /V           Verifies each new file." & @CRLF & _
            "  /W           Prompts you to press a key before copying." & @CRLF & _
            "  /C           Continues copying even if errors occur." & @CRLF & _
            "  /I           If destination does not exist and copying more than one file," & @CRLF & _
            "               assumes that destination must be a directory." & @CRLF & _
            "  /Q           Does not display file names while copying." & @CRLF & _
            "  /F           Displays full source and destination file names while copying." & @CRLF & _
            "  /L           Displays files that would be copied." & @CRLF & _
            "  /G           Allows the copying of encrypted files to destination that does" & @CRLF & _
            "               not support encryption." & @CRLF & _
            "  /H           Copies hidden and system files also." & @CRLF & _
            "  /R           Overwrites read-only files." & @CRLF & _
            "  /T           Creates directory structure, but does not copy files. Does not" & @CRLF & _
            "               include empty directories or subdirectories. /T /E includes" & @CRLF & _
            "               empty directories and subdirectories." & @CRLF & _
            "  /U           Copies only files that already exist in destination." & @CRLF & _
            "  /K           Copies attributes. Normal Xcopy will reset read-only attributes." & @CRLF & _
            "  /N           Copies using the generated short names." & @CRLF & _
            "  /O           Copies file ownership and ACL information." & @CRLF & _
            "  /X           Copies file audit settings (implies /O)." & @CRLF & _
            "  /Y           Suppresses prompting to confirm you want to overwrite an" & @CRLF & _
            "               existing destination file." & @CRLF & _
            "  /-Y          Causes prompting to confirm you want to overwrite an" & @CRLF & _
            "               existing destination file." & @CRLF & _
            "  /Z           Copies networked files in restartable mode." & @CRLF & _
            @CRLF & _
            "The switch /Y may be preset in the COPYCMD environment variable." & @CRLF & _
            "This may be overridden with /-Y on the command line." & @CRLF
    MsgBox(0, "Xcopy GUI Help", $helptext)
EndFunc   ;==>Help

Share this post


Link to post
Share on other sites
somdcomputerguy

You bet. Happy to help when I can.


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites
blckpythn

Another quick one

How do I get

Run("cmd.exe /c xcopy \\TTCDATA01\Student_Home\NST\msdewart\Desktop\New Folder1 \\TTCDATA01\Student_Home\NST\msdewart\Desktop\New Folder2 /EXCLUDE document.txt /E /P /V /W /F /L /-Y")

to work.

Share this post


Link to post
Share on other sites
somdcomputerguy

Try this quote from the help file

To run DOS (console) commands, try Run(@ComSpec & " /c " & 'commandName', "", @SW_HIDE) ; don't forget " " before "/c"

Here's a link to the Run command.

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.