Jump to content

Can't figure out my error - Variable used without being declared


leke
 Share

Recommended Posts

Hi, My .ts ripping app works the first time it's executed, but then fails for some reason with an error. I can't figure out why I'm getting this message though. The variables used on line 55 should be declared. $TsPath is declared as a Global before the error is called. 

This is line 55...

ElseIf $TsPath == 2 Then ; Cancelled

 The error and source code (also attached)...

Line 55

Error: Variable used without being declared. 

; ffmpeg info:
; also: http://forum.videohelp.com/threads/289790-mencoder-ts-to-avi-%28x264%29-with-multiple-audio-stream
; http://linuxers.org/tutorial/ffmpeg-basics-beginners
; ffmpeg -i test.ts -t 10 -b 1000k -vcodec libx264 output.mp4

; MsgBox(0, "Debug", @ScriptDir)


$ini_ffmpeg_location = IniRead("ts-ripper-config.ini", "Settings", "ffmpeg location", "NotFound") ; Get path of ffmpeg.exe from config file
$ini_default_path = IniRead("ts-ripper-config.ini", "Settings", "Default location", @ScriptDir) ; Read last user defined location from the db.


If FileExists($ini_ffmpeg_location & "\ffmpeg.exe") Then
    Call("PrepareRip")
Else
    Call("LocateFfmpeg")
EndIf


Func LocateFfmpeg() ; locates the ffmpeg.exe if not found.
    Local $LocateFfmpegQuestion = MsgBox(1, "Whoops!", "ffmpeg.exe was not found." & @CRLF & @CRLF & "Click Ok to search for ffmpeg.exe")
    Switch $LocateFfmpegQuestion
        Case 1; Ok
            Global $WhereIsFfmpeg = FileOpenDialog("Locate your ffmpeg.exe", @ScriptDir & "\", "Exe (*.exe)", 1 + 4)
            If @error Then
                MsgBox(0, "!", "No File chosen - I quit!")
                Exit
            ElseIf $WhereIsFfmpeg == 2 Then ; Cancelled
                MsgBox(0, "!", "No File chosen - I quit!")
                Exit
            Else
                $FfmpegFolder = StringLeft($WhereIsFfmpeg, StringInStr($WhereIsFfmpeg, '\', 0, -1) - 1) ; copy the folder only from $TsPath
                IniWrite(@ScriptDir & "\ts-ripper-config.ini", "Settings", "ffmpeg location", $FfmpegFolder) ; Write last user defined folder location of ffmpeg.exe the db.
                If FileExists($FfmpegFolder & "\ffmpeg.exe") Then
                    Call("PrepareRip")
                Else
                    Call("LocateFfmpeg")
                EndIf
            EndIf
        Case 2; Cancel -> Exit program
            MsgBox(0, "!", "No File chosen - I quit!")
            Exit
    EndSwitch
EndFunc

Func PrepareRip() ; locate the file to rip.
    Local $PrepareRipQuestion = MsgBox(1, "Step 1:", "Select your .ts video file")
    Switch $PrepareRipQuestion
        Case 1; Ok
            Global $TsPath = FileOpenDialog("Locate your .ts file", $ini_default_path & "\", "Video (*.ts)", 1 + 4)
            If @error Then
                MsgBox(0, "!", "No File chosen - I quit!")
                Exit
            ElseIf $TsPath == 2 Then ; Cancelled
                MsgBox(0, "!", "No File chosen - I quit!")
                Exit
            Else
                $TsFolder = StringLeft($TsPath, StringInStr($TsPath, '\', 0, -1) - 1) ; copy the folder only from $TsPath
                IniWrite(@ScriptDir & "\ts-ripper-config.ini", "Settings", "Default location", $TsFolder) ; Write last user defined location from the db.
                Call("RipIt")
            EndIf
        Case 2; Cancel -> Exit program
            MsgBox(0, "!", "No File(s) chosen - I quit!")
            Exit
    EndSwitch
EndFunc

Func RipIt()
    ; Creates rip in same folder as original.
    $ffmpeg_command = $WhereIsFfmpeg & " -i " & $TsPath & " -b:v 1200k -vcodec libx264 " & $TsPath & ".mp4" ; The ffmpeg rip settings.
    Run($ffmpeg_command, "", @SW_MAXIMIZE) ; the ffmpeg command.
EndFunc

 Does anyone know how to fix this? 

Thanks :)

Source code.au3

Edited by leke
Link to comment
Share on other sites

Do not define a global variable in a function. Define it at the top of the script.
If the function where the global variable is being defined never gets called but the variable gets referenced then you see the error you get.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Do not define a global variable in a function. Define it at the top of the script.
If the function where the global variable is being defined never gets called but the variable gets referenced then you see the error you get.

Ok, thanks. I passed the variables as function arguments and it seems to work :)

Link to comment
Share on other sites

:)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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

×
×
  • Create New...