Jump to content

Recommended Posts

Posted (edited)

Hello,

I am attempting - rather unsuccessfully, to implement If|Then within a Switch|Case script. Here is the script:

; -----------------------------------------------
#include <MsgBoxConstants.au3>
; -----------------------------------------------
Opt("MustDeclareVars", 1)
; -----------------------------------------------
Global $iEMBWidth = 650
Global $iMsgDelay = 4
; -----------------------------------------------
IfGFoldersExist()
; -----------------------------------------------
Func IfGFoldersExist()
    Local $condition
    Local $iStart = 11, $iEnd = 10
    Local $sFolder[$iStart] = [$iEnd]
    $sFolder[1] = "G:\AltPeakData"
    $sFolder[2] = "G:\Automation_Data"
    $sFolder[3] = "G:\CHT_Files"
    $sFolder[4] = "G:\ControlTrack_Data"
    $sFolder[5] = "G:\F-Key_Data"
    $sFolder[6] = "G:\Mix_Templates"
    $sFolder[7] = "G:\Prf_Data"
    $sFolder[8] = "G:\Scene_Data"
    $sFolder[9] = "G:\Session_Data"
    $sFolder[10] = "G:\Session_Master"
    ; -----------------
    Local $iFolderExists[$iStart] = [$iEnd]
    $iFolderExists[1] = FileExists($sFolder[1])
    $iFolderExists[2] = FileExists($sFolder[2])
    $iFolderExists[3] = FileExists($sFolder[3])
    $iFolderExists[4] = FileExists($sFolder[4])
    $iFolderExists[5] = FileExists($sFolder[5])
    $iFolderExists[6] = FileExists($sFolder[6])
    $iFolderExists[7] = FileExists($sFolder[7])
    $iFolderExists[8] = FileExists($sFolder[8])
    $iFolderExists[9] = FileExists($sFolder[9])
    $iFolderExists[10] = FileExists($sFolder[10])
    ; -----------------
    Local $sMessage = "Confirm if folders exist..." & @CRLF & @CRLF, $iWidth = 500, $iHeight = 390
    Local $iOpt = 5, $sFontName = "Corbel Bold", $iFontSize = 16
    ; -----------------------------------------------
    SplashTextOn("", $sMessage, $iWidth, $iHeight, -1, -1, $iOpt, $sFontName, $iFontSize)
    ; -----------------------------------------------
    For $i = 1 To $sFolder[0]
        Local $sResult = FileExists($sFolder[$i])
;~      Local $sResult = "" ; For testing only!!
        ; -----------------------------------------------
        Switch $sResult
            Case 0
                $sResult = "The folder [" & $sFolder[$i] & "] DOES NOT exist!"
            Case 1
                $sResult = "The folder [" & $sFolder[$i] & "] DOES exist!"
        EndSwitch
        ; -----------------------------------------------
        $sMessage &= $sResult & @CRLF
    Next
    ; -----------------------------------------------
    $sMessage &= @CRLF & "Confirm if folders exist is now completed..." & @CRLF
    ; -----------------------------------------------
    SplashTextOn("", $sMessage, $iWidth, $iHeight, -1, -1, $iOpt, $sFontName, $iFontSize)
    Sleep(3500)
    SplashOff()
    ; -----------------------------------------------
    ; My attempt!!
;~  If $sResult <> $sFolder[10] Then
;~      RestoreInitialFolderData()
;~  EndIf
;~  If $sResult = $sFolder[1] Then
;~      Notice()
;~  EndIf
EndFunc   ;==>IfGFoldersExist
; -----------------------------------------------
Func RestoreInitialFolderData()
    MsgBox($MB_SYSTEMMODAL, "Title", "RestoreInitialFolderData", 2)
EndFunc   ;==>RestoreInitialFolderData
; -----------------------------------------------
Func Notice()
    MsgBox($MB_SYSTEMMODAL, "Title", "Done!", 2)
EndFunc   ;==>Notice
; -----------------------------------------------

If Case = 0, I then need to call the "RestoreInitialFolderData()" function
If Case = 1, I then need to call the "Notice()" function

Any ideas!!

Edited by mr-es335
Posted (edited)
;~ If Case = 0, I then need to call the "RestoreInitialFolderData()" function
;~ If Case = 1, I then need to call the "Notice()" function
Switch FileExists($sFolder[$i])
    Case 1
        $sResult = "The folder [" & $sFolder[$i] & "] DOES exist!"
        Notice()
    Case Else
        $sResult = "The folder [" & $sFolder[$i] & "] DOES NOT exist!"
        RestoreInitialFolderData()
EndSwitch

Edit: ...I have no idea.

Edited by argumentum
oops

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

  • Developers
Posted (edited)

Just learn to add some consolewrite()  statements for key variables to debug!

Wild guess: wrong value in: 

$sFolder[0]
Edited by Jos

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

Posted
17 hours ago, argumentum said:

Edit: ...I have no idea.

...that is because:

...
    Local $iStart = 11, $iEnd = 10
    Local $sFolder[$iStart] = [$iEnd]
    $sFolder[1] = "G:\AltPeakData"
    $sFolder[2] = "G:\Automation_Data"
    $sFolder[3] = "G:\CHT_Files"
    $sFolder[4] = "G:\ControlTrack_Data"
    $sFolder[5] = "G:\F-Key_Data"
    $sFolder[6] = "G:\Mix_Templates"
    $sFolder[7] = "G:\Prf_Data"
    $sFolder[8] = "G:\Scene_Data"
    $sFolder[9] = "G:\Session_Data"
    $sFolder[10] = "G:\Session_Master"
    ; -----------------
    Local $iFolderExists[$iStart] = [$iEnd]
    $iFolderExists[1] = FileExists($sFolder[1])
    $iFolderExists[2] = FileExists($sFolder[2])
    $iFolderExists[3] = FileExists($sFolder[3])
    $iFolderExists[4] = FileExists($sFolder[4])
    $iFolderExists[5] = FileExists($sFolder[5])
    $iFolderExists[6] = FileExists($sFolder[6])
    $iFolderExists[7] = FileExists($sFolder[7])
    $iFolderExists[8] = FileExists($sFolder[8])
    $iFolderExists[9] = FileExists($sFolder[9])
    $iFolderExists[10] = FileExists($sFolder[10])
    ; -----------------
...

makes no sense. Why would you code it that way !?. It just don't make any sense.

...

    ; you can make a file and read from it or
    ; declare it just like this:
    $sFolders = "G:\AltPeakData" & @CRLF
    $sFolders &= "G:\Automation_Data" & @CRLF
    $sFolders &= "G:\CHT_Files" & @CRLF
    $sFolders &= "G:\ControlTrack_Data" & @CRLF
    $sFolders &= "G:\F-Key_Data" & @CRLF
    $sFolders &= "G:\Mix_Templates" & @CRLF
    $sFolders &= "G:\Prf_Data" & @CRLF
    $sFolders &= "G:\Scene_Data" & @CRLF
    $sFolders &= "G:\Session_Data" & @CRLF
    $sFolders &= "G:\Session_Master" & @CRLF

    ; then chop that into an array
    $aFolders = StringSplit($sFolders, @CRLF, 1)

    ; make the $aFolderExists array based of $aFolders
    Local $aFolderExists = $aFolders ; lazy way but it will work

    ; then use a for loop
    For $n = 1 To UBound($aFolders) - 1
        If $aFolders[$n] = "" Then ContinueLoop
        $aFolderExists[$n] = FileExists($aFolders[$n])
        ConsoleWrite(($aFolderExists[$n] = 0 ? '!' : '+') & ' This is at index ' & $n & ' and contains this string: "' & _
            $aFolders[$n] & '" and does ' & ($aFolderExists[$n] = 0 ? 'not ' : '') & 'exist.'& @CRLF)
    Next

...

You have over 600 posts and, what have you learned ?.

You are going to have to slow down your hurry to get your code done.
Because you lack flexibility. You don't know how to use a "for loop" and that is a shame.

And do use the "F1" key in the editor.  Most of the answers given to you are right there ;) 

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Posted

Not really. Just gave him a for loop example. The way it goes, is going to be a head scratcher for him.
But after over 600 questions of always the same, c'mon !. 

The code is to tell him to slow down and learn. I've been there and do understand him.
But in the end, there is only so much one gets done by copy and paste. Eventually the coder needs to know/learn or get ignored by the rest of the users

Do you understand @mr-es335 that you are not in an "ignore list". You are just not showing independence of thought.
Do learn or you'll be faced with more posts not been answered. And that is going to be painful as you already experienced this week in another post.
Please do look at the help file we all actively contribute to maintain, and practice, practice, practice.

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

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
×
×
  • Create New...