Jump to content

Recommended Posts

Posted (edited)

Good day,

The following script has two global variables that I would prefer to declare as local variables namely, $sSelectedPath and $sMasterEdlFile.

About the $sSelectedPath variable
1) The $sSelectedPath variable is assigned in two functions namely, BrowseForFolder() and _EnterSetName()
2) In the BrowseForFolder() function, the $sSelectedPath variable is passed to the function _MoveWavData()
3) In the _EnterSetName() function, the $sSelectedPath variable is passed to the function _CreateFolder()
4) However, there are two functions that also require the $sSelectedPath variable namely, _DeleteTextListing and _SelectWavData()
* Note: The $sSelectedPath variable is alols employed in the _DeleteTextListing() function

About the $sMasterEdlFile variable
1) The $sMasterEdlFile variable is being dervied from: StringMid($sSelectedPath, 10, 6) in the _SelectWavData() function
2) The $sMasterEdlFile variable is then employed in _FileSelectFolder() function which, I do believe returns the result of $sMasterEdlFile as $sDestFolder back to the _SelectWavData() function

What I AM looking for...
Assistance in "how" to go about resolving the above.

What I AM NOT looking for...
A completed script. I really need to learn "how" to go about resolving such issues on my own.

Here is the script...

; -----------------------------------------------
; With the assistance of...and the gratitude of...ioa747, AndrewG, and pixelsearch!
; Date: November 5th, 2024
; -----------------------------------------------
#include <AutoItConstants.au3>
#include <File.au3>
#include <FileConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <MsgBoxConstants.au3>
; -----------------------------------------------
Opt("MustDeclareVars", 1)
; -----------------------------------------------
ClipPut("F:\Audio\Type_1\AllMe") ; For testing purposes only
; -----------------------------------------------
Global $sSelectedPath = ""
Global $sMasterEdlFile = ""
; -----------------------------------------------
Global $hGUI = GUICreate(" Testing", 225, 165)
GUISetFont(14, 800, 0, "Calibri")
; -----------------------------------------------
; COLUMN 3 BUTTONS
Global $_sCol3Row3 = GUICtrlCreateButton("Browse Folder", 10, 10, 200, 25)
Global $_sCol3Row4 = GUICtrlCreateButton("Enter Set Name", 10, 40, 200, 25)
Global $_sCol3Row5 = GUICtrlCreateButton("Launch TAC", 10, 70, 200, 25)
Global $_sCol3Row6 = GUICtrlCreateButton("Create Type_# Data", 10, 100, 200, 25)
Global $_sCol3Row9 = GUICtrlCreateButton("Exit", 10, 130, 200, 25)
; -----------------------------------------------
GUISetState(@SW_SHOW, $hGUI)
; -----------------------------------------------
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
            ; COLUMN 3 BUTTONS
        Case $_sCol3Row3
            _BrowseForFolder()
        Case $_sCol3Row4
            _EnterSetName()
        Case $_sCol3Row5
            ;_DeleteTextListing()
            ;_LaunchTAC()
        Case $_sCol3Row6
            _SelectWavData()
        Case $_sCol3Row9
            _ExitMe()
    EndSwitch
WEnd
; -----------------------------------------------
Func _BrowseForFolder()
    Local $sSourceWavPath = "F:\Audio\SourceWavData"
    ; -----------------------------------------------
    While 1
        Local $sSelectedPath = FileSelectFolder("Please select a valid Type_#\Set_Name folder...", "F:\Audio")
        Local $iFileExists = FileExists($sSelectedPath & "\wav")
        ; -----------------------------------------------
        If StringRegExp($sSelectedPath & "\", "\\Type_[1-4]\\") Then
            ; -------------
            If $iFileExists Then
                _MoveWavData($sSourceWavPath, $sSelectedPath)
                ExitLoop
            EndIf
        Else
            MsgBox($MB_TOPMOST, "Error!", "You must to select a valid Type_#\Set_Name folder...")
        EndIf
    WEnd
EndFunc   ;==>_BrowseForFolder
; -----------------------------------------------
Func _MoveWavData($sSourceWavPath, $sSelectedPath)
    Local $sSelectedWavPath = $sSelectedPath & "\wav"
    ; -----------------------------------------------
    FileMove($sSourceWavPath & "\*.*", $sSelectedWavPath, $FC_OVERWRITE)
    ; -----------------------------------------------
    _LaunchWavFolder($sSelectedWavPath)
EndFunc   ;==>_MoveWavData
; -----------------------------------------------
Func _LaunchWavFolder($sSelectedWavPath)
    If Not WinExists($sSelectedWavPath) Then ShellExecute($sSelectedWavPath)
    ; -----------------------------------------------
    WinWaitActive($sSelectedWavPath, "", 1)
    ; -----------------
    WinMove($sSelectedWavPath, "", 970, 100, 550, 650)
    ; -----------------------------------------------
    _CreateTextListing($sSelectedWavPath)
EndFunc   ;==>_LaunchWavFolder
; -----------------------------------------------
Func _CreateTextListing($sSelectedWavPath)
    Local $WavFileListing = _FileListToArray($sSelectedWavPath, "*.wav")
    ; -----------------------------------------------
    If Not @error Then
        ; Create the data file
        _FileCreate($sSelectedWavPath & "\FileListing.txt")
        ; Write the array to the data file
        _FileWriteFromArray($sSelectedWavPath & "\FileListing.txt", $WavFileListing)
    EndIf
    ; -----------------------------------------------
    _LaunchTextListing($sSelectedWavPath)
EndFunc   ;==>_CreateTextListing
; -----------------------------------------------
Func _LaunchTextListing($sSelectedWavPath)
    If Not FileExists($sSelectedWavPath & "\FileListing.txt") Then Return
    ; -----------------------------------------------
    ShellExecute($sSelectedWavPath & "\FileListing.txt")
    ; -----------------------------------------------
    WinWaitActive($sSelectedWavPath & "\FileListing.txt", "", 2)
    ; -----------------
    WinMove($sSelectedWavPath & "\FileListing.txt", "", 400, 100, 550, 650)
EndFunc   ;==>_LaunchTextListing
; -----------------------------------------------
Func _EnterSetName()
    Local $_SourceWavPath = "F:\Audio\SourceWavData"
    ; -----------------
    Local $sSelectedPath = InputBox("Notice!", "Enter the complete path...", "", " M", 200, 130)
    Local $SplitPath = StringSplit($sSelectedPath, "\")
    ; -----------------------------------------------
    If $SplitPath[0] <= 3 Or $SplitPath[0] >= 5 Then
        MsgBox($MB_SYSTEMMODAL, "Error!", "Incorrect path name!")
        _EnterSetName()
    Else
        _CreateFolder($_SourceWavPath, $sSelectedPath)
    EndIf
EndFunc   ;==>_EnterSetName
; -----------------------------------------------
Func _CreateFolder($sSourceWavPath, $sSelectedPath)
    DirCreate($sSelectedPath & "\edl")
    DirCreate($sSelectedPath & "\wav")
    ; -----------------------------------------------
    _MoveWavData($sSourceWavPath, $sSelectedPath)
EndFunc   ;==>_CreateFolder
; -----------------------------------------------
Func _DeleteTextListing($SetNameWave)
    FileDelete($SetNameWave & "\FileListing.txt")
EndFunc   ;==>_DeleteTextListing
; -----------------------------------------------
Func _LaunchTAC()
    Local $_sSrcPath = "D:\Install\System_Data\Apps\TAC\TAudioConverter.exe"
    ; -----------------------------------------------
    Run($_sSrcPath)
    ; -----------------------------------------------
    Sleep(500)
    ; -----------------
    WinMove("[CLASS:TAudioConverterUniqueName]", "", 160, 130, 792, 590)
EndFunc   ;==>_LaunchTAC
; -----------------------------------------------
;Func _SelectWavData($sSelectedPath)
Func _SelectWavData()
    Local $ConfirmCreate = MsgBox($MB_YESNO, "Notice!", "Create " & StringMid($sSelectedPath, 10, 6) & " Session Data from .wav file data?")
    ; -----------------------------------------------
    ; If the data exists
    If $ConfirmCreate = $IDYES Then
        Local $WavFiles = _FileOpenDialog() ; Obtain the wav file data
        Local $sDestFolder = _FileSelectFolder() ; Obtain the destination path for the .edl data
        Local $sWavFolder = $WavFiles[1] ; Contains only the path of $sSelectedPath PLUS "\wav", regardless of the number of previously selected .wav files.
        ; -----------------------------------------------
        For $i = 2 To $WavFiles[0] ; First file name in element 2, and so on.
            Local $sWavFileName = $sWavFolder & "\" & $WavFiles[$i]
            Local $sWavBaseName = StringTrimRight($WavFiles[$i], 4)
            ; -----------------
            Local $sNewEdlFile = $sDestFolder & "\" & $sWavBaseName & ".edl"
            ; -----------------
            FileCopy($sMasterEdlFile, $sNewEdlFile, $FC_NOOVERWRITE)
        Next
        ; -----------------
        MsgBox($MB_ICONINFORMATION, "Success!", "The " & StringMid($sSelectedPath, 10, 6) & " Sesson .edl data file(s) have been successfully created!")
        ; -----------------------------------------------
    Else ; $IDNO
        MsgBox($MB_ICONINFORMATION, "Cancelled!", "The operation was cancelled by the user.")
        Exit
    EndIf
EndFunc   ;==>_SelectWavData
; -----------------------------------------------
Func _FileOpenDialog()
    While 1
        Local $sMessage = "Please select the required source .wav file data..."
        Local $_ConfirmOpenDialog = MsgBox($MB_YESNO, "Notice!", $sMessage)
        ; -----------------------------------------------
        If $_ConfirmOpenDialog = $IDYES Then
            Local $_sFileOpenDialog = FileOpenDialog($sMessage, $sSelectedPath & "\wav", "Wave Data (*.wav)", BitOR($FD_FILEMUSTEXIST, $FD_MULTISELECT))
            ; -----------------------------------------------
            If @error Then
                MsgBox($MB_ICONINFORMATION, "Error!", "No source .wav file data was selected!" & @CRLF & "You must select at least one source .wav file!")
                ContinueLoop ; While 1
            EndIf
            ; -----------------------------------------------
            Local $WavFiles = StringSplit($_sFileOpenDialog, "|")
            ; -----------------------------------------------
            If $WavFiles[0] = 1 Then ; If only one file was selected by the user.
                Local $iPos_LastBackslash = StringInStr($WavFiles[1], "\", 0, -1) ; -1 starts from the right (+++).
                ; -----------------------------------------------
                ReDim $WavFiles[3]
                $WavFiles[2] = StringMid($WavFiles[1], $iPos_LastBackslash + 1) ; The file name.
                $WavFiles[1] = StringLeft($WavFiles[1], $iPos_LastBackslash - 1) ; The path without the last backslash.
                $WavFiles[0] = 2
            EndIf
            ; -----------------
            Return $WavFiles
            ; -----------------
        Else ; $IDNO
            MsgBox($MB_ICONINFORMATION, "Notice!", "The operation was cancelled by the user. Exiting!")
            Exit
        EndIf
    WEnd
EndFunc   ;==>_FileOpenDialog
; -----------------------------------------------
Func _FileSelectFolder()
    While 1
        Local $sMessage = "Please select the Destination folder for the Session .edl file(s)..."
        Local $sConfirmFileSelect = MsgBox($MB_YESNO, "Notice!", $sMessage)
        ; -----------------------------------------------
        If $sConfirmFileSelect = $IDYES Then
            Local $sDestFolder = FileSelectFolder($sMessage, $sSelectedPath)
            ; -----------------------------------------------
            If @error Then
                MsgBox($MB_ICONINFORMATION, "Notice!", "No destination Session .edl folder was selected!" & @CRLF & "You must select a destination Session .edl folder!")
                ContinueLoop ; While 1
                ; -----------------------------------------------
            ElseIf StringMid($sSelectedPath, 10, 6) = "Type_1" Then
                $sMasterEdlFile = "G:\Session_Master\Show\Session_Data\" & "Type1.edl"
                ; -----------------
            ElseIf StringMid($sSelectedPath, 10, 6) = "Type_2" Then
                $sMasterEdlFile = "G:\Session_Master\Show\Session_Data\" & "Type2.edl"
                ; -----------------
            ElseIf StringMid($sSelectedPath, 10, 6) = "Type_3" Then
                $sMasterEdlFile = "G:\Session_Master\Show\Session_Data\" & "Type3.edl"
                ; -----------------
            ElseIf StringMid($sSelectedPath, 10, 6) = "Type_4" Then
                $sMasterEdlFile = "G:\Session_Master\Show\Session_Data\" & "Type4.edl"
                ; -----------------
            Else
                MsgBox($MB_ICONERROR, "Notice!", "The " & $sMasterEdlFile & " Session .edl file was not found.")
                ContinueLoop ; While 1
            EndIf
            ; -----------------
            Return $sDestFolder
            ; -----------------
        Else ; $IDNO
            MsgBox($MB_ICONINFORMATION, "Notice!", "The operation was cancelled by the user. Exiting!")
            Exit
        EndIf
    WEnd
EndFunc   ;==>_FileSelectFolder
; -----------------------------------------------
Func _ExitMe()
    Exit
EndFunc   ;==>_ExitMe
; -----------------------------------------------

As always, any assistance in this matter would be greatly appreciated!

PS: I have attached a text file outlining what I refer to as "The Process" - which is employed with the above script. Also, I am not sure if the attached image is of any assistance...but is being provided regardless.

The Process.txt

 

image.png

Edited by mr-es335
Added image...
Posted (edited)

Not sure where you are looping for. You could pass along to functions like you are doing. Using globals is in this case not that bad.

You could make a struct but still then it will be global struct.

https://www.autoitscript.com/autoit3/docs/functions/DllStructGetData.htm

There are some object oriënted udfs around to make classes.

Edited by junkew
Posted

junkew,

Thanks for the follow-up..appreciated!

You suggested, "You could pass along to functions like you are doing. " This is what I have been attempting to do...all with NO success!

Someone suggested using ClipPut() and ClipGet(). Not very elegant...but appears to do the job.

Posted

Concerning $sSelectedPath, you could declare it Local if you place your Main loop in a function, for example with the canvas below, which assigns the variable in _BrowseForFolder() and _EnterSetName() , then returns its value from both functions to Main() . Now you can pass the variable as a parameter in functions _DeleteTextListing() and _SelectWavData()

Main()
; -----------------------------------------------
Func Main
    Local $sSelectedPath = "", $sMasterEdlFile = ""
    Local $hGUI, $_sCol3Row3, $_sCol3Row4, $_sCol3Row5, $_sCol3Row6, $_sCol3Row9
    
    $hGUI = GUICreate(...)
    $_sCol3Row3 = GUICtrlCreateButton(...)
    $_sCol3Row4 = GUICtrlCreateButton(...)
    $_sCol3Row5 = GUICtrlCreateButton(...)
    $_sCol3Row6 = GUICtrlCreateButton(...)
    $_sCol3Row9 = GUICtrlCreateButton(...)
    GUISetState(@SW_SHOW, $hGUI)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                Exit
            Case $_sCol3Row3
                $sSelectedPath = _BrowseForFolder()
            Case $_sCol3Row4
                $sSelectedPath = _EnterSetName()
            Case $_sCol3Row5
                _DeleteTextListing($sSelectedPath)
            Case $_sCol3Row6
                _SelectWavData($sSelectedPath)
            Case $_sCol3Row9
                _ExitMe()
        EndSwitch
    WEnd
EndFunc
; -----------------------------------------------
Func _BrowseForFolder()
    Local $sSelectedPath = FileSelectFolder(...)
    ... 
    Return $sSelectedPath
EndFunc
; -----------------------------------------------
Func _EnterSetName()
    Local $sSelectedPath = InputBox(...)
    ...
    Return $sSelectedPath
EndFunc
; -----------------------------------------------
Func _DeleteTextListing($sSelectedPath)
    ...
EndFunc
; -----------------------------------------------
Func _SelectWavData($sSelectedPath)
    ...
Return
; -----------------------------------------------
Func _ExitMe()
    Exit
EndFunc 
; -----------------------------------------------

Of course you'll have to check, at a moment or another, if $sSelectedPath is valid (e.g if it's not empty)  for example in main loop (but not really user friendly) :

Case $_sCol3Row5
    If $sSelectedPath Then _DeleteTextListing($sSelectedPath)

Or you can check if $sSelectedPath is valid from within the functions _DeleteTextListing() and _SelectWavData() and warn the user that $sSelectedPath has not been set yet.

Another way could be to disable/enable both buttons $_sCol3Row5 (_DeleteTextListing) and $_sCol3Row6 (_SelectWavData) depending on the value of $sSelectedPath in functions _BrowseForFolder() and _EnterSetName() =>
* Disable the buttons if $sSelectedPath is empty
* Enable them if $sSelectedPath is valid

These are just quick ideas, untested, but well... you got the idea.

Posted (edited)

Good day,

"Possible" Solution #1: Write to an .ini file:

#include <MsgBoxConstants.au3>

_CreateIniData()

Func _CreateIniData()
    Local $IniFilePath = "I:\Live_Rig\Scripts\Development\_Ini\Write\data.ini"
    IniWrite($IniFilePath, "Filepath", "Value", "F:\Audio\Type_1\AllMe")
    Local $sReadIniFile = IniRead($IniFilePath, "Filepath", "Value", "Default Value")
    Local $sSelectedPath = $sReadIniFile
    _CreateFolder($sSelectedPath, $IniFilePath)
EndFunc   ;==>_CreateIniData

Func _CreateFolder($sSelectedPath, $IniFilePath)
    DirCreate($sSelectedPath & "\edl")
    DirCreate($sSelectedPath & "\wav")
    _DeleteTextListing($IniFilePath)
EndFunc   ;==>_CreateFolder

Func _DeleteTextListing($IniFilePath)
    FileDelete($IniFilePath)
EndFunc   ;==>_DeleteTextListing

 

Edited by mr-es335
Posted

Good day,

"Possible" Solution #2:

#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>

_CreateIniData()

Func _CreateIniData()
    Local $IniFilePath = "F:\Audio\data.ini"
    IniWrite($IniFilePath, "Filepath", "Value", "F:\Audio\Type_1\AllMe")
    Sleep(2000)
    _ReadIniData($IniFilePath)
EndFunc   ;==>_CreateIniData

Func _ReadIniData($IniFilePath)
    Local $sReadIniFile = IniRead($IniFilePath, "Filepath", "Value", "Default Value")
    ConsoleWrite($sReadIniFile & @CRLF)
    Local $sSelectedPath = $sReadIniFile
    Sleep(2000)
    _CreateFolder($sSelectedPath, $IniFilePath)
EndFunc   ;==>_ReadIniData

Func _CreateFolder($sSelectedPath, $IniFilePath)
    DirCreate($sSelectedPath & "\edl")
    DirCreate($sSelectedPath & "\wav")
    Sleep(2000)
    _DeleteIniFile($sSelectedPath, $IniFilePath)
EndFunc   ;==>_CreateFolder

Func _DeleteIniFile($sSelectedPath, $IniFilePath)
    FileDelete($IniFilePath)
    _DeleteFolder($sSelectedPath)
    Sleep(2000)
EndFunc   ;==>_DeleteIniFile

Func _DeleteFolder($sSelectedPath)
    Sleep(2000)
    DirRemove($sSelectedPath, $DIR_REMOVE)
EndFunc   ;==>_DeleteFolder

 

Posted (edited)
21 hours ago, mr-es335 said:

The following script has two global variables that I would prefer to declare as local variables namely, $sSelectedPath and $sMasterEdlFile.

As your script stands,
I only see $sMasterEdlFile being used.

You have declared $sSelectedPath as Global $selected Path = "" but you don't use it anywhere.
in _BrowseForFolder()  you have declared it as local. (not Global)
in _MoveWavData($sSourceWavPath, $sSelectedPath)   you pass it as an argument to the parameter $sSelectedPath (not Global)
in _EnterSetName()  you have declared it as local. (not Global)
in _CreateFolder($sSourceWavPath, $sSelectedPath)  you pass it as an argument to the parameter $sSelectedPath (not Global)

So even if you delete it or rename it, it won't affect anything.
exception is the function _SelectWavData()

how will you overcome it?
either you will set a path as default as start path or you will go to the suggestion I saw above to disable the button until the path is available
Otherwise, how can you delete something that hasn't been specified?

In my opinion, using a .ini file,
(even though you didn't need it, since you don't have to store anything that you need the next time you start the script)
just to avoid using a global variable, it's invalid
It seems to me that you have globalphobia that you need to overcome.

I'll use something I saw here and liked.
"Who cares if we add a couple of global variables to our scripts, if it makes them more readable ? We shouldn't frown when a user adds a few global variables, when #include adds dozen & hundreds of them... "

where you should focus is,
at what point will you define them so that they are available and updated in your script
e.g. don't call a function that uses it and it is not available
and when I say available I don't mean it has the value=""



And again, don't use global variable names as local variables or as parameters inside functions.

Edited by ioa747

I know that I know nothing

Posted

ioa747,

Please note the following:

For $sSelectedPath:
$sSelectedPath in _BrowseForFolder is passed to _MoveWavData < Ok!
$sSelectedPath in _EnterSetName is passed to _CreateFolder < Ok!
$sSelectedPath in _EnterSetName is passed to _MoveWavData < Ok!
$sSelectedPath in _SelectWavData is not being passed?!? < Not Ok!
• Thus, the sole purpose of this posting!
• Granted, $sSelectedPath is only being employed in _SelectWavData to indicate the Type_#.
$sSelectedPath in _FileOpenDialog is not being passed?!? < Not Ok!
$sSelectedPath in _FileSelectFolder is not being passed?!? < Not Ok!

For $sMasterEdlFile:
$sMasterEdlFile in _SelectWavData is not being passed?!? < Not Ok!
$sMasterEdlFile in _FileSelectFolder is global and is not being passed?!? < Not Ok!
• It would "appear" that I could declare $sMasterEdlFile as a local variable in _FileSelectFolder
• Maybe then, I could pass that value back to _SelectWavData? However...

The issued as I see it at present, is as follows:
1) If I pass a variable as an argument to a particular function, then that argument  has to be included in the initial function call...does it not?
• For example:

Case $_sCol3Row6
_SelectWavData(argument)

2) If I do that, then I receive the error, ": warning: $sMasterEdlFile: possibly used before declaration."

So, the question that I seeking an answer to is "How is this particular anomaly to be overcome?"
• If the only means is the employment of global variables, the so be it!

 

 

 

Posted (edited)

Let's do a working hypothesis.
The user runs the script and the first thing he does is press the button $_sCol3Row6
This triggers _SelectWavData()

Func _SelectWavData()
    Local $ConfirmCreate = MsgBox($MB_YESNO, "Notice!", "Create  Session Data from .wav file data?") ; âš  remove the StringMid($sSelectedPath, 10, 6)
    ; -----------------------------------------------
    ; If the data exists
    If $ConfirmCreate = $IDYES Then

        Local $WavFiles = _FileOpenDialog() ; Obtain the wav file data
        Local $sWavFolder = $WavFiles[1] ; Contains only the path of $sSelectedPath PLUS "\wav", regardless of the number of previously selected .wav files.
        Local $sSelectedPath = StringLeft($sWavFolder, StringInStr($sWavFolder, "\", $STR_NOCASESENSEBASIC, -1) - 1)  ; âš  Declare $sSelectedPath
        ConsoleWrite("$sSelectedPath=" & $sSelectedPath & @CRLF)
        Local $sDestFolder = _FileSelectFolder($sSelectedPath) ; Obtain the destination path for the .edl data ; âš  give $sSelectedPath as argument
        ; -----------------------------------------------
        For $i = 2 To $WavFiles[0] ; First file name in element 2, and so on.
            Local $sWavFileName = $sWavFolder & "\" & $WavFiles[$i]
            Local $sWavBaseName = StringTrimRight($WavFiles[$i], 4)
            ; -----------------
            Local $sNewEdlFile = $sDestFolder & "\" & $sWavBaseName & ".edl"
            ; -----------------
            FileCopy($sMasterEdlFile, $sNewEdlFile, $FC_NOOVERWRITE)
        Next
        ; -----------------
        MsgBox($MB_ICONINFORMATION, "Success!", "The " & StringMid($sSelectedPath, 10, 6) & " Sesson .edl data file(s) have been successfully created!")
        ; -----------------------------------------------
    Else ; $IDNO
        MsgBox($MB_ICONINFORMATION, "Cancelled!", "The operation was cancelled by the user.")
        Exit
    EndIf
EndFunc   ;==>_SelectWavData
; -----------------------------------------------
Func _FileOpenDialog()
    ...
        Local $_sFileOpenDialog = FileOpenDialog($sMessage, "F:\Audio", "Wave Data (*.wav)", BitOR($FD_FILEMUSTEXIST, $FD_MULTISELECT)) ; âš  replace $sSelectedPath with "F:\Audio"
    ...
EndFunc   ;==>_FileOpenDialog
; -----------------------------------------------
Func _FileSelectFolder($sSelectedPath)  ; âš  add $sSelectedPath as parameter


Is this an acceptable solution?

Edit: correction
Local $sSelectedPath = StringLeft($sWavFolder, StringInStr($sWavFolder, "\", $STR_NOCASESENSEBASIC, -1) - 1)  ; ⚠ Declare $sSelectedPath

Edited by ioa747
correction

I know that I know nothing

Posted

Good day,

So, I have devised the following...all with employing global variables!!

; -----------------------------------------------
#include <File.au3>
#include <MsgBoxConstants.au3>
; -----------------------------------------------
Opt("MustDeclareVars", 1)
; -----------------------------------------------
_SelectSrcFolder()
; -----------------------------------------------
Func _SelectSrcFolder()
    Local $sSrcMessage = "Select the source .wav data folder..."
    Local $sSrcFolder = FileSelectFolder($sSrcMessage, "F:\Audio\")
    ; -----------------
    If @error Then
        MsgBox($MB_TOPMOST, "Error!", "No .wav file source folder selected...exiting!")
        Return
    Else
        _SelectDstFolder($sSrcFolder)
    EndIf
EndFunc   ;==>_SelectSrcFolder
; -----------------------------------------------
Func _SelectDstFolder($sSrcFolder)
    Local $sDstMessage = "Select the destination folder for the copied-and-renamed .edl data..."
    Local $sDstFolder = FileSelectFolder($sDstMessage, "F:\Audio\")
    ; -----------------
    If @error Then
        MsgBox($MB_TOPMOST, "Error!", "No destination folder selected...exiting!")
        Return
    Else
        _CreateArray($sSrcFolder, $sDstFolder)
    EndIf
EndFunc   ;==>_SelectDstFolder
; -----------------------------------------------
Func _CreateArray($sSrcFolder, $sDstFolder)
    Local $sWavFileData = _FileListToArray($sSrcFolder, "*.wav", $FLTA_FILES)
    ; -----------------------------------------------
    If @error Then
        MsgBox($MB_TOPMOST, "Error!", "No .wav file data located in the selected folder...exiting!")
        Return
    Else
        _DeriveType($sSrcFolder, $sDstFolder, $sWavFileData)
    EndIf
EndFunc   ;==>_CreateArray
; -----------------------------------------------
Func _DeriveType($sSrcFolder, $sDstFolder, $sWavFileData)
    Local $sDeriveType = StringMid($sSrcFolder, 10, 6)
    Local $sMasterEdlFile = "G:\Session_Master\Show\Session_Data\" & $sDeriveType & ".edl"
    ; -----------------------------------------------
    If Not FileExists($sMasterEdlFile) Then
        MsgBox($MB_TOPMOST, "Error", "The " & $sDeriveType & ".edl file was not found.")
        Return
    Else
        _RenameEdls($sSrcFolder, $sDstFolder, $sWavFileData, $sMasterEdlFile)
    EndIf
EndFunc   ;==>_DeriveType
; -----------------------------------------------
Func _RenameEdls($sSrcFolder, $sDstFolder, $sWavFileData, $sMasterEdlFile)
    For $i = 1 To $sWavFileData[0]
        Local $sWavFileName = $sWavFileData[$i]
        Local $sWavBaseName = StringTrimRight($sWavFileName, 4)
        ; -----------------
        Local $sNewEdlFile = $sDstFolder & "\" & $sWavBaseName & ".edl"
        ; -----------------
        FileCopy($sMasterEdlFile, $sNewEdlFile, $FC_NOOVERWRITE)
    Next
    ; -----------------
    MsgBox($MB_ICONINFORMATION, "Success", "All .edl files have been created successfully.")
EndFunc   ;==>_RenameEdls
; -----------------------------------------------

I am not sure if I have ever employed four arguments|parameters before!

The above methodology is how I prefer to develop scripts..."Top-Down" you might say! In this manner, I can test each function "on it's own", ascertaining 1) what variables are declared and 2) what variables are required to be passed.

As an aside...peruse the following:

Quote

_SelectSrcFolder
* Declares: $sSrcFolder
_SelectDstFolder
* Declares: $sDstFolder
_CreateArray
* Requires: $sSrcFolder and $sDstFolder
* Declares: $sWavFileData
_DeriveType
* Requires: $sSrcFolder
* Declares: $sMasterEdlFile
_RenameEdls
* Requires: $sWavFileData and $sMasterEdlFile
* Declares:  $sWavFileName, $sWavBaseName and $sNewEdlFile

Any comments and|or suggestion would be greatly appreciated.

Posted

Your topdown approach in itself is fine. But if someone else needs to understand it that person needs to read all code. A short main function calling well named functions gives a quicker understanding for the outsider.

Sidenote https://www.autoitscript.com/autoit3/docs/functions/Assign.htm as you solve it already just FYI.

Posted

Probably easier in a more OO style take a look at:
* https://github.com/genius257/AutoItObject-Internal/blob/master/README.md

* https://github.com/cosote/OOPEAu3/blob/master/README.md

 

And as suggested earlier probably more readable with a main function like below, you only need to read main to understand what your intention is.
Amount of errorhandling and how is more complex/clumsy reading in a procedural language or where you check for errors.
You could get main more clean of errorhandling if you check for variable value -1 within the function

; -----------------------------------------------
#include <File.au3>
#include <MsgBoxConstants.au3>
; -----------------------------------------------
Opt("MustDeclareVars", 1)
; -----------------------------------------------

main()

func main()
    local $sSrcFolder=_SelectSrcFolder()
    local $sDstFolder=_SelectDstFolder()

    if ($sSrcFolder <> -1) then
        local $sWavFileData   = _CreateArray($sSrcFolder)
        local $sMasterEdlFile = _DeriveType($sSrcFolder)
    endif

    if (($sSrcFolder <> -1) and ($sDstFolder <> -1) and ($sWavFileData <> -1) and ($sMasterEdlFile <> -1)) then
        _RenameEdls($sSrcFolder, $sDstFolder, $sWavFileData, $sMasterEdlFile)
        MsgBox($MB_ICONINFORMATION, "Success", "All .edl files have been created successfully.")
    Else
         MsgBox($MB_TOPMOST, "Error:", "Something in parameters went wrong!")
    EndIf
EndFunc

func selectFolder($sMessage)
    Local $sFolder = FileSelectFolder($sMessage, "F:\Audio\")
    If @error Then
        MsgBox($MB_TOPMOST, "Error:", "No .wav file source folder selected...exiting!")
        Return -1
    Else
        return $sFolder
    EndIf
EndFunc
Func _SelectSrcFolder()
    return SelectFolder("Select the source .wav data folder...")
EndFunc   ;==>_SelectSrcFolder
Func _SelectDstFolder()
    return selectFolder("Select the destination folder for the copied-and-renamed .edl data...")
EndFunc   ;==>_SelectDstFolder
Func _CreateArray($sSrcFolder)
    return _FileListToArray($sSrcFolder, "*.wav", $FLTA_FILES)
EndFunc   ;==>_CreateArray
Func _DeriveType($sSrcFolder)
    Local $sDeriveType = StringMid($sSrcFolder, 10, 6)
    Local $sMasterEdlFile = "G:\Session_Master\Show\Session_Data\" & $sDeriveType & ".edl"
    If Not FileExists($sMasterEdlFile) Then
        MsgBox($MB_TOPMOST, "Error", "The " & $sDeriveType & ".edl file was not found.")
        Return -1
    Else
        return $sMasterEdlFile
    EndIf
EndFunc   ;==>_DeriveType
Func _RenameEdls($sSrcFolder, $sDstFolder, $sWavFileData, $sMasterEdlFile)
    For $i = 1 To $sWavFileData[0]
        Local $sWavFileName = $sWavFileData[$i]
        Local $sWavBaseName = StringTrimRight($sWavFileName, 4)
        ; -----------------
        Local $sNewEdlFile = $sDstFolder & "\" & $sWavBaseName & ".edl"
        ; -----------------
        FileCopy($sMasterEdlFile, $sNewEdlFile, $FC_NOOVERWRITE)
    Next
EndFunc   ;==>_RenameEdls

 

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
  • Recently Browsing   0 members

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