leke

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

4 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
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.

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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 :)

Share this post


Link to post
Share on other sites

:)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

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

  • Similar Content

    • Leo1906
      By Leo1906
      Hey there,
      I didn't really know how to name the titel .. so let me explain it a bit further.
      You all might know that a compiled Autoit-Exe gives an error message containing the Error and the line when it crashes. Often those messages aren't usefull because it states the line in the compiled script is not the line in your script if you have used includes. Decompiling the exe often doesn't help either. Well .. I don't want to start a discussion about the benefits of those messages.
      I just want to disable them. I want my exe to just fail an crash and that's it. Nothing more. When there's an error there's an error. Autoit is the only language I have ever noticed those message boxes.
      I think now you can understand me ..
      Do you know any way to do this?
      Some compiler options or so? Or is it that deep implemented in Autoit that it can't be removed?
      Thanks for your help!
      Leo1906