Jump to content

IF... Returning an error


Recommended Posts

I am trying to create a script (below) for users to backup their favorites (later some other stuff) in the event of a HDD failure. The script between the "-------" works ERROR free. But, as soon as I check for the OS and add IF...(ElseIF or Else)...EndIF, I get an error (during run Beta in SciTE). It says IF doesn't have a matching ENDIF, but references "FUNC". Do I have something out of place?

Thanks, PeteF :)

$OSVer = @OSVersion

If $OSVer = "WIN_XP" Then

; ------------------------- Between the dashes works fiine START

$UserNAME = @UserName

$UserDIR = @UserProfileDir

; 1

; Prompt the user to run the script - use a Yes/No prompt (4 - see help file)

$answer = MsgBox(4, ""& $OSVer & "", "Do You Want to Copy Your Favorites to the Server?")

; Check the user's answer to the prompt (see the help file for MsgBox return values)

; If "No" was clicked (7) then exit the script

If $answer = 7 Then

;MsgBox(0, "ADP Backup Utility", "OK. Bye!")

Exit

EndIf

; 2

;DirCreate("H:\FAV-BACKUP")

; 3

;Yes

_FileCopy2(""& $UserDIR & "\Favorites\*.*","H:\FAV-BACKUP\")

Func _FileCopy2($fromFile,$tofile)

Local $FOF_RESPOND_YES = 16

Local $FOF_SIMPLEPROGRESS = 256

$winShell = ObjCreate("shell.application")

$winShell.namespace($tofile).CopyHere($fromFile,$FOF_RESPOND_YES)

EndFunc

; ---------------------------------- END

; Else

; I want to repeat the above Routine for WIN_98

;If Win_98

;Endif

EndIf

EXIT

; Finished!

Link to comment
Share on other sites

  • Developers

Peter, you have an Func...EndFunc inside of a If...EndIf which isn't allowed.

Here is your script when ran through Tidy...

$OSVer = @OSVersion

If $OSVer = "WIN_XP" Then
    ; ------------------------- Between the dashes works fiine START
    $UserNAME = @UserName
    $UserDIR = @UserProfileDir
    ; 1
    ; Prompt the user to run the script - use a Yes/No prompt (4 - see help file)
    $answer = MsgBox(4, "" & $OSVer & "", "Do You Want to Copy Your Favorites to the Server?")
    ; Check the user's answer to the prompt (see the help file for MsgBox return values)
    ; If "No" was clicked (7) then exit the script
    If $answer = 7 Then
        ;MsgBox(0, "ADP Backup Utility", "OK. Bye!")
        Exit
    EndIf
    
    
    ; 2
    ;DirCreate("H:\FAV-BACKUP")
    
    ; 3
    ;Yes
    _FileCopy2("" & $UserDIR & "\Favorites\*.*", "H:\FAV-BACKUP\")
;### Tidy Error: Level error -> "If" Not closed before Func statement.
;### Tidy Error: Level error -> "Func" cannot be inside any IF/Do/While/For/Case/Func statement.
    Func _FileCopy2($fromFile, $tofile)
        Local $FOF_RESPOND_YES = 16
        Local $FOF_SIMPLEPROGRESS = 256
        $winShell = ObjCreate("shell.application")
        $winShell.namespace ($tofile).CopyHere ($fromFile, $FOF_RESPOND_YES)
    EndFunc   ;==>_FileCopy2
    ; ---------------------------------- END
    ; Else
    ; I want to repeat the above Routine for WIN_98
    ;If Win_98
    ;Endif
EndIf
Exit
; Finished!

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

FUNC can't reside inside any of the conditionals I am familiar with.

Is this a good use for the missing GOTO (FAQ)?

Func...EndFunc is used for subroutines you regularly need. so in this case if you need to copy multiple files its easier to put that logic in its own Func...End, in stead of repeating the same code over and over again, which you then call by FuncName(Parameters).

Don't think there is an relation to a Goto which is really used to jump around in a program.

Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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...