Jump to content

_SelectWavData Script Issues


Go to solution Solved by ioa747,

Recommended Posts

Good day,

I have two identical scripts, the only exception being 1) the source data path is being manually entered [_EnterSetName()], and 2) the source data path is being browsed for [_BrowseForFolder()].

The purpose of having both, is 1) the source data path is being manually entered is for those situations where the source data path does not yet exist, and 2) the source data path is being browsed for is for an existing source data path. I do hope that this makes sense?

The issue is that the first works and the second does not! Yet, the ONLY DIFFERENCE is in the first Function...which is either _EnterSetName() or _BrowseForFolder()

I have added extra lines to _EnterSetName() to make the two scripts the same in length. I have also added MsgBox portions where needed.

Here is the script employing _EnterSetName()...

; -----------------------------------------------
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
; -----------------------------------------------
Opt("MustDeclareVars", 1)
; -----------------------------------------------
Global $_MasterEdlFile = "" ; This global variable must always be enabled!
; -----------------
Global $_sMasterType1Edl = "Type1.edl"
Global $_sMasterType2Edl = "Type2.edl"
Global $_sMasterType3Edl = "Type3.edl"
Global $_sMasterType4Edl = "Type4.edl"
; -----------------
Global $g_SetName = ""
; -----------------------------------------------
_EnterSetName()
; -----------------------------------------------
Func _EnterSetName()
    $g_SetName = InputBox("Notice!", "Enter the Type_# Set_Name...", "", " M", 200, 130)
    ; -----------------
    If @error Then
        MsgBox($MB_ICONWARNING, "Notice!", "The operation was cancelled. Exiting!")
        Exit
    Else
;Filler
;Filler
;Filler
;Filler
;Filler
;Filler
;Filler
;Filler
;Filler
                MsgBox(0, "", "#1: _EnterSetName(): " & $g_SetName) ; NO 1!!!!
        _SelectWavData($g_SetName)
    EndIf
;Filler
;Filler
EndFunc   ;==>_EnterSetName
; -----------------------------------------------
Func _SelectWavData($g_SetName)
    Local $_ConfirmCreate = MsgBox($MB_YESNO, "Notice!", "Create " & StringMid($g_SetName, 10, 6) & " Session Data from .wav file data?")
    MsgBox(0, "", "#2a: _SelectWavData(): " & $g_SetName)
    ; -----------------------------------------------
    If $_ConfirmCreate = $IDYES Then
        MsgBox(0, "", "#2b: _SelectWavData(): " & $g_SetName)
        Local $_WavFiles = _FileOpenDialog()
        MsgBox(0, "", "#2c: _SelectWavData(): " & $g_SetName)
        Local $_DestFolder = _FileSelectFolder()
        Local $_sWavFolder = $_WavFiles[1] ; Contains only a path, no matter if the user has selected one or more files.
        ; -----------------------------------------------
        For $i = 2 To $_WavFiles[0] ; First file name in element 2, and so on.
            Local $_WavFileName = $_sWavFolder & "\" & $_WavFiles[$i]
            Local $_WavBaseName = StringTrimRight($_WavFiles[$i], 4)
            ; -----------------
            Local $_NewEdlFile = $_DestFolder & "\" & $_WavBaseName & ".edl"
            ; -----------------
            FileCopy($_MasterEdlFile, $_NewEdlFile, $FC_NOOVERWRITE)
        Next
        ; -----------------
        MsgBox($MB_ICONINFORMATION, "Success!", "The " & StringMid($g_SetName, 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
        MsgBox(0, "", "#3: _FileOpenDialog(): " & $g_SetName)
        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, $g_SetName & "\wav", "Wave Data (*.wav)", BitOR($FD_FILEMUSTEXIST, $FD_MULTISELECT))
            ; -----------------------------------------------
            If @error Then
                MsgBox($MB_ICONINFORMATION, "Notice!", "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 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 $_Message = "Please select the Destination folder for the Session .edl file(s)..."
        Local $_ConfirmFileSelect = MsgBox($MB_YESNO, "Notice!", $_Message)
        ; -----------------------------------------------
        If $_ConfirmFileSelect = $IDYES Then
            Local $_DestFolder = FileSelectFolder($_Message, $g_SetName)
            ; -----------------------------------------------
            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($g_SetName, 10, 6) = "Type_1" Then
                $_MasterEdlFile = "G:\Session_Master\Show\Session_Data\" & $_sMasterType1Edl
                ; -----------------
            ElseIf StringMid($g_SetName, 10, 6) = "Type_2" Then
                $_MasterEdlFile = "G:\Session_Master\Show\Session_Data\" & $_sMasterType2Edl
                ; -----------------
            ElseIf StringMid($g_SetName, 10, 6) = "Type_3" Then
                $_MasterEdlFile = "G:\Session_Master\Show\Session_Data\" & $_sMasterType3Edl
                ; -----------------
            ElseIf StringMid($g_SetName, 10, 6) = "Type_4" Then
                $_MasterEdlFile = "G:\Session_Master\Show\Session_Data\" & $_sMasterType4Edl
                ; -----------------
            Else
                MsgBox($MB_ICONERROR, "Notice!", "The " & $_MasterEdlFile & " Session .edl file was not found.")
                ContinueLoop ; While 1
            EndIf
            ; -----------------
            Return $_DestFolder
            ; -----------------
        Else ; $IDNO
            MsgBox($MB_ICONINFORMATION, "Notice!", "The operation was cancelled by the user. Exiting!")
            Exit
        EndIf
    WEnd
EndFunc   ;==>_FileSelectFolder
; -----------------------------------------------

...and...here is the script employing _BrowseForFolder()...

; -----------------------------------------------
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
; -----------------------------------------------
Opt("MustDeclareVars", 1)
; -----------------------------------------------
Global $_MasterEdlFile = "" ; This global variable must always be enabled!
; -----------------
Global $_sMasterType1Edl = "Type1.edl"
Global $_sMasterType2Edl = "Type2.edl"
Global $_sMasterType3Edl = "Type3.edl"
Global $_sMasterType4Edl = "Type4.edl"
; -----------------
Global $g_SetName = ""
; -----------------------------------------------
_BrowseForFolder()
; -----------------------------------------------
Func _BrowseForFolder()
    While 1
        Local $g_SetName = FileSelectFolder("Please select a valid Type_#\Set_Name folder...", "")
        ; -----------------------------------------------
        If @error Then
            MsgBox($MB_TOPMOST, "", "No valid Type_#\Set_Name folder was selected." & @CRLF & "Please select a valid Type_#\Set_Name folder")
            ContinueLoop
        EndIf
        ; -----------------------------------------------
        Local $_aGetType = StringSplit($g_SetName, "\")
        ; -----------------------------------------------
        Select
            Case $_aGetType[0] < 3
                MsgBox($MB_TOPMOST, "NOTICE!", "You must select a valid Type_#\Set_Name folder...")
                ContinueLoop
            Case $_aGetType[3] = "Type_1"
                MsgBox(0, "", "#1: _BrowseForFolder(): " & $g_SetName) ; NO 1!!!!
                _SelectWavData($g_SetName)
                ExitLoop
        EndSelect
    WEnd
EndFunc   ;==>_BrowseForFolder
; -----------------------------------------------
Func _SelectWavData($g_SetName)
    Local $_ConfirmCreate = MsgBox($MB_YESNO, "Notice!", "Create " & StringMid($g_SetName, 10, 6) & " Session Data from .wav file data?")
    MsgBox(0, "", "#2a: _SelectWavData(): " & $g_SetName)
    ; -----------------------------------------------
    If $_ConfirmCreate = $IDYES Then
        MsgBox(0, "", "#2b: _SelectWavData(): " & $g_SetName)
        Local $_WavFiles = _FileOpenDialog()
        MsgBox(0, "", "#2c: _SelectWavData(): " & $g_SetName)
        Local $_DestFolder = _FileSelectFolder()
        Local $_sWavFolder = $_WavFiles[1] ; Contains only a path, no matter if the user has selected one or more files.
        ; -----------------------------------------------
        For $i = 2 To $_WavFiles[0] ; First file name in element 2, and so on.
            Local $_WavFileName = $_sWavFolder & "\" & $_WavFiles[$i]
            Local $_WavBaseName = StringTrimRight($_WavFiles[$i], 4)
            ; -----------------
            Local $_NewEdlFile = $_DestFolder & "\" & $_WavBaseName & ".edl"
            ; -----------------
            FileCopy($_MasterEdlFile, $_NewEdlFile, $FC_NOOVERWRITE)
        Next
        ; -----------------
        MsgBox($MB_ICONINFORMATION, "Success!", "The " & StringMid($g_SetName, 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
        MsgBox(0, "", "#3: _FileOpenDialog(): " & $g_SetName)
        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, $g_SetName & "\wav", "Wave Data (*.wav)", BitOR($FD_FILEMUSTEXIST, $FD_MULTISELECT))
            ; -----------------------------------------------
            If @error Then
                MsgBox($MB_ICONINFORMATION, "Notice!", "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 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 $_Message = "Please select the Destination folder for the Session .edl file(s)..."
        Local $_ConfirmFileSelect = MsgBox($MB_YESNO, "Notice!", $_Message)
        ; -----------------------------------------------
        If $_ConfirmFileSelect = $IDYES Then
            Local $_DestFolder = FileSelectFolder($_Message, $g_SetName)
            ; -----------------------------------------------
            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($g_SetName, 10, 6) = "Type_1" Then
                $_MasterEdlFile = "G:\Session_Master\Show\Session_Data\" & $_sMasterType1Edl
                ; -----------------
            ElseIf StringMid($g_SetName, 10, 6) = "Type_2" Then
                $_MasterEdlFile = "G:\Session_Master\Show\Session_Data\" & $_sMasterType2Edl
                ; -----------------
            ElseIf StringMid($g_SetName, 10, 6) = "Type_3" Then
                $_MasterEdlFile = "G:\Session_Master\Show\Session_Data\" & $_sMasterType3Edl
                ; -----------------
            ElseIf StringMid($g_SetName, 10, 6) = "Type_4" Then
                $_MasterEdlFile = "G:\Session_Master\Show\Session_Data\" & $_sMasterType4Edl
                ; -----------------
            Else
                MsgBox($MB_ICONERROR, "Notice!", "The " & $_MasterEdlFile & " Session .edl file was not found.")
                ContinueLoop ; While 1
            EndIf
            ; -----------------
            Return $_DestFolder
            ; -----------------
        Else ; $IDNO
            MsgBox($MB_ICONINFORMATION, "Notice!", "The operation was cancelled by the user. Exiting!")
            Exit
        EndIf
    WEnd
EndFunc   ;==>_FileSelectFolder
; -----------------------------------------------

The Main Issue
In the _EnterSetName() script, the Global variable $g_SetName is passing the correct source path, whilst in the _BrowseForFolder() script, the Global variable $g_SetName IS NOT passing the correct source path. And yet, from what I can observe, the scripts are identical!?!

Any assistance in this matter would be greatly appreciated!

Thank you for your time! Appreciated!

Important Note
As an aside, the current combination of _EnterSetName() amd _SelectWavData...so the first script, appears to work as expected. Therefore, it is the second that appears to be the primary issues. The question is "Why?" Thanks!

 

 

 

Edited by mr-es335
Link to comment
Share on other sites

  • mr-es335 changed the title to _SelectWavData Script Issues

Put a ConsoleWrite below the _EnterSetName() in the _EnterSetName.au3 like:
_EnterSetName()
ConsoleWrite("$g_SetName=" & $g_SetName & @CRLF)

and

Put a ConsoleWrite below the _BrowseForFolder() in the _BrowseForFolder.au3 like:
_BrowseForFolder()
ConsoleWrite("$g_SetName=" & $g_SetName & @CRLF)

and check if there is any difference

Tip:
avoid the parameters of a function having the same name as global variables in the definition
during the call there is no problem


in function Func _SelectWavData($g_SetName)
change $g_SetName to $SetName so that the parameter does not have synonyms with the global variable

 

Edited by ioa747
corrected _BrowseForFolder

I know that I know nothing

Link to comment
Share on other sites

remove the Local  in _BrowseForFolder.au3 in line 21
Local $g_SetName = FileSelectFolder("Please select a valid Type_#\Set_Name folder...", "")

Edited by ioa747

I know that I know nothing

Link to comment
Share on other sites

  • Solution
7 minutes ago, mr-es335 said:

Like this?

No

 

like this
; _BrowseForFolder.au3

; -----------------------------------------------
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
; -----------------------------------------------
Opt("MustDeclareVars", 1)
; -----------------------------------------------
Global $_MasterEdlFile = "" ; This global variable must always be enabled!
; -----------------
Global $_sMasterType1Edl = "Type1.edl"
Global $_sMasterType2Edl = "Type2.edl"
Global $_sMasterType3Edl = "Type3.edl"
Global $_sMasterType4Edl = "Type4.edl"
; -----------------
Global $g_SetName = ""
; -----------------------------------------------
_BrowseForFolder()
ConsoleWrite("$g_SetName=" & $g_SetName & @CRLF)
; -----------------------------------------------
...
...

and this
; _EnterSetName.au3

; -----------------------------------------------
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
; -----------------------------------------------
Opt("MustDeclareVars", 1)
; -----------------------------------------------
Global $_MasterEdlFile = "" ; This global variable must always be enabled!
; -----------------
Global $_sMasterType1Edl = "Type1.edl"
Global $_sMasterType2Edl = "Type2.edl"
Global $_sMasterType3Edl = "Type3.edl"
Global $_sMasterType4Edl = "Type4.edl"
; -----------------
Global $g_SetName = ""
; -----------------------------------------------
_EnterSetName()
ConsoleWrite("$g_SetName=" & $g_SetName & @CRLF)
; -----------------------------------------------
...
...

 

I know that I know nothing

Link to comment
Share on other sites

ioa747,

You have NO idea how grateful I am!

All because of a five character word...I have spend the better part of ten+hours on this endeavour!!

It would "appear" ...[...and please correct me if I wrong here...though I believe NOT...]...In the original Function, though a Global variable was declared, I assigned that Global variable as Local! what a "DuFuss!"

Anyhow...we move on and hopefully...learn from our mistakes!!

Thanks again, ioa747...you have come to my rescue again!

Appreciated!

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