Sign in to follow this  
Followers 0
ajenkins

array error

6 posts in this topic

I am getting this error, It happens after running my script for 2-30 seconds. Then my gui crashes.

"Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
Return $aTime[1]/$aTime[2]*100
Return $aTime[1]/^ ERROR"

ripgui()
Func ripgui()
#Region ### START Koda GUI section ### Form=j:\my builds\all-rip\all-rip.kxf
$QuickQualityEncode = GUICreate("ALL-RIP", 350, 197, 223, 219)
GUISetBkColor(0x000000)
$RIP_Button1 = GUICtrlCreateButton("RIP", 255, 110, 75, 25)
GUICtrlSetColor(-1, 0x808080)
$Pic1 = GUICtrlCreatePic(@TempDir & "\ALL-RIP\risa1.jpg", 0, 2, 100, 140)
GUICtrlSetState(-1, $GUI_DISABLE)
$INPUT_Button1 = GUICtrlCreateButton("INPUT", 255, 10, 75, 25)
GUICtrlSetColor(-1, 0x808080)
$OUTPUT_Button1 = GUICtrlCreateButton("OUTPUT", 255, 60, 75, 25)
GUICtrlSetColor(-1, 0x808080)
Global $Progress1 = GUICtrlCreateProgress(10, 160, 325, 25, $WS_BORDER)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $INPUT_Button1
            Global $input = FileSelectFolder("Select Input Location", "")
            $INPUT_Label1 = GUICtrlCreateLabel($input, 105, 10, 148, 25)
            GUICtrlSetColor(-1, 0xFFFFFF)
        Case $OUTPUT_Button1
            Global $output = FileSelectFolder("Select Output Location", "")
            $OUTPUT_Label1 = GUICtrlCreateLabel($output, 105, 60, 148, 25)
            GUICtrlSetColor(-1, 0xFFFFFF)
        Case $RIP_Button1
            rip()
    EndSwitch
WEnd
EndFunc

Func rip()
    $prog = @TempDir & "\ALL-RIP\makemkvcon.exe"
    $sStdErr = ""
    $iTicksDuration = 0

        $hPid = Run('"' & $prog & '" --robot --messages=-stderr --minlength=3600 mkv --progress=-same file:' & $input & ' all ' & $output,$output,@SW_HIDE,$STDIN_CHILD + $STDERR_CHILD)

            $nBegin = TimerInit()
            While 1
                $nMsg = GUIGetMsg()
                Switch $nMsg
                Case $GUI_EVENT_CLOSE
                    exitprog()
                EndSwitch

                If TimerDiff($nBegin) > 500 Then
                    $sStdErr &= StderrRead($hPid)
                    If @error Then ExitLoop
                    If StringLen($sStdErr) > 0 Then
                        $iTicksDuration = _GetDuration($sStdErr)
                        If Not @error Then $sStdErr = ""
                        GUICtrlSetData($Progress1, $iTicksDuration)
                    EndIf
                $nBegin = TimerInit()
                EndIf
            WEnd
            ProgressOff()
EndFunc

Func _GetDuration($sStdErr)

        If Not StringInStr($sStdErr, "PRGV:") Then Return SetError(1, 0, 0)
        Local $aRegExp = StringRegExp($sStdErr, "(?i)PRGV.+?([0-9,]+)", 3)
        If @error Or Not IsArray($aRegExp) Then Return SetError(1, 0, 0)
        Local $sTime = $aRegExp[UBound($aRegExp) - 1]
        Local $aTime = StringSplit($sTime, ",", 2)
        If @error Or Not IsArray($aTime) Then Return SetError(1, 0, 0)
        Return $aTime[1]/$aTime[2]*100

EndFunc   ;==>_GetDuration

Func exitprog()

    if ProcessExists("makemkvcon.exe") Then
        ProcessClose("makemkvcon.exe")
    EndIf
    if ProcessExists("cmd.exe") Then
        ProcessClose("cmd.exe")
    EndIf
    FileDelete(@TempDir&"\All-RIP")
Exit
EndFunc   ;==>exitprog

I have been at it for a whille and at this point it feels like im running in circles. So any help would be great!

Thanks.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

ajenkins,

Change this function like this...

Func _GetDuration($sStdErr)

        If Not StringInStr($sStdErr, "PRGV:") Then Return SetError(1, 0, 0)
        Local $aRegExp = StringRegExp($sStdErr, "(?i)PRGV.+?([0-9,]+)", 3)
        If @error Or Not IsArray($aRegExp) Then Return SetError(1, 0, 0)
        Local $sTime = $aRegExp[UBound($aRegExp) - 1]
        Local $aTime = StringSplit($sTime, ",", 2)
        ;If @error Or Not IsArray($aTime) Then Return SetError(1, 0, 0)
        If @error Or ubound($sTime) < 2 Then Return SetError(1, 0, 0)  ; <----- may be an array of 1 element
        Return $aTime[1]/$aTime[2]*100

EndFunc   ;==>_GetDuration

kylomas

edit: stringpslit will always return an array.  From the Help file...

If no delimiters were found then the @error flag is set to 1, count is equal to 1 ($aArray[0]) and the full string is returned ($aArray[1]).

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Thanks for the help FUBAR, I am always amazed how fast people reply on this forum. I see what you mean about stringsplit returns an array. I tried your edited script, the gui doesn't crash now, but the progress bar doesn't mov anymore. I am working on figuring it out now.

Share this post


Link to post
Share on other sites

this is working without error, but the progress bar keeps dropping back and forth. any ideas?

Func _GetDuration($sStdErr)

        If Not StringInStr($sStdErr, "PRGV:") Then Return SetError(1, 0, 0)
        Local $aRegExp = StringRegExp($sStdErr, "(?i)PRGV.+?([0-9,]+)", 3)
        If @error Or Not IsArray($aRegExp) Then Return SetError(1, 0, 0)
        Local $sTime = $aRegExp[UBound($aRegExp) - 1]
        Local $aTime = StringSplit($sTime, ",", 2)
        If @error Or ubound($aTime) < 3 Then Return SetError(1, 0, 0)
    If Not @error Then Return $aTime[1]/$aTime[2]*100

EndFunc   ;==>_GetDuration

Share this post


Link to post
Share on other sites

works great, thanks for all the help guys.

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
Sign in to follow this  
Followers 0