Sign in to follow this  
Followers 0
PeterF

IF... Returning an error

7 posts in this topic

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!

Share this post


Link to post
Share on other sites



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!

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Well Jos, Thank you again.

I must try this TIDY.

That is a better returned message than I received.

PeterF

Share this post


Link to post
Share on other sites

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

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

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

That should keep me busy for a while.

I will report back soon.

Thank You.

PeterF

Share this post


Link to post
Share on other sites

Only 15 minutes playing around with it. It worked like a charm.

that TIDY utility works nice too, thanks.

PeterF

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