Jump to content

Error on my script can't make sense!


speck
 Share

Recommended Posts

The script works on my computer ... everything ok until here!ok

I've send it via msn to my buddy who doesn't have autoit3 installed on his computer...

Here the problem starts...

The gui starts every button works ok!

but when he clicked the button to dowload the file (inetget command) an error pop up box came up....

Line -1:

Error: Subscript is used with non-array variable.

What i must do to fix this???????

here is the code

Func _INetGetSource($s_URL, $s_Header = '')

    If StringLeft($s_URL, 7) <> 'http://' And StringLeft($s_URL, 8) <> 'https://' Then $s_URL = 'http://' & $s_URL

    Local $h_DLL = DllOpen("wininet.dll")

    Local $ai_IRF, $s_Buf = ''

    Local $ai_IO = DllCall($h_DLL, 'int', 'InternetOpen', 'str', "AutoIt v3", 'int', 0, 'int', 0, 'int', 0, 'int', 0)
    If @error Or $ai_IO[0] = 0 Then
        DllClose($h_DLL)
        SetError(1)
        Return ""
    EndIf

    Local $ai_IOU = DllCall($h_DLL, 'int', 'InternetOpenUrl', 'int', $ai_IO[0], 'str', $s_URL, 'str', $s_Header, 'int', StringLen($s_Header), 'int', 0x80000000, 'int', 0)
    If @error Or $ai_IOU[0] = 0 Then
        DllCall($h_DLL, 'int', 'InternetCloseHandle', 'int', $ai_IO[0])
        DllClose($h_DLL)
        SetError(1)
        Return ""
    EndIf

    Local $v_Struct = DllStructCreate('udword')
    DllStructSetData($v_Struct, 1, 1)

    While DllStructGetData($v_Struct, 1) <> 0
        $ai_IRF = DllCall($h_DLL, 'int', 'InternetReadFile', 'int', $ai_IOU[0], 'str', '', 'int', 256, 'ptr', DllStructGetPtr($v_Struct))
        $s_Buf &= StringLeft($ai_IRF[2], DllStructGetData($v_Struct, 1))
    WEnd

    DllCall($h_DLL, 'int', 'InternetCloseHandle', 'int', $ai_IOU[0])
    DllCall($h_DLL, 'int', 'InternetCloseHandle', 'int', $ai_IO[0])
    DllClose($h_DLL)
    Return $s_Buf
EndFunc
;--------------------------------------------------------------------------------------------------------------------------------------------------
Func _StringBetween($sString, $sStart, $sEnd, $vCase = -1, $iSRE = -1)
    If $iSRE = -1 Or $iSRE = Default Then
        If $vCase = -1 Or $vCase = Default Then
            $vCase = 0
        Else
            $vCase = 1
        EndIf
        Local $sHold = '', $sSnSStart = '', $sSnSEnd = ''
        While StringLen($sString) > 0
            $sSnSStart = StringInStr($sString, $sStart, $vCase)
            If Not $sSnSStart Then ExitLoop
            $sString = StringTrimLeft($sString, ($sSnSStart + StringLen($sStart)) - 1)
            $sSnSEnd = StringInStr($sString, $sEnd, $vCase)
            If Not $sSnSEnd Then ExitLoop
            $sHold &= StringLeft($sString, $sSnSEnd - 1) & Chr(1)
            $sString = StringTrimLeft($sString, $sSnSEnd)
        WEnd
        If Not $sHold Then Return SetError(1, 0, 0)
        $sHold = StringSplit(StringTrimRight($sHold, 1), Chr(1))
        Local $avArray[UBound($sHold) - 1]
        For $iCC = 1 To UBound($sHold) - 1
            $avArray[$iCC - 1] = $sHold[$iCC]
        Next
        Return $avArray
    Else
        If $vCase = Default Or $vCase = -1 Then
            $vCase = '(?i)'
        Else
            $vCase = ''
        EndIf
        Local $aArray = StringRegExp($sString, '(?s)' & $vCase & $sStart & '(.*?)' & $sEnd, 3)
        If IsArray($aArray) Then Return $aArray
        Return SetError(1, 0, 0)
    EndIf
EndFunc  
;------------------------------------------------------------------------------------------------------------------------------------------------------------------
; Events and messages
Global Const $GUI_EVENT_CLOSE = -3
Global Const $GUI_EVENT_MINIMIZE = -4
Global Const $GUI_EVENT_RESTORE = -5
Global Const $GUI_EVENT_MAXIMIZE = -6
Global Const $GUI_EVENT_PRIMARYDOWN = -7
Global Const $GUI_EVENT_PRIMARYUP = -8
Global Const $GUI_EVENT_SECONDARYDOWN = -9
Global Const $GUI_EVENT_SECONDARYUP = -10
Global Const $GUI_EVENT_MOUSEMOVE = -11
Global Const $GUI_EVENT_RESIZED = -12
Global Const $GUI_EVENT_DROPPED = -13

Global Const $GUI_RUNDEFMSG = 'GUI_RUNDEFMSG'

; State
Global Const $GUI_AVISTOP = 0
Global Const $GUI_AVISTART = 1
Global Const $GUI_AVICLOSE = 2

Global Const $GUI_CHECKED = 1
Global Const $GUI_INDETERMINATE = 2
Global Const $GUI_UNCHECKED = 4

Global Const $GUI_DROPACCEPTED = 8
Global Const $GUI_NODROPACCEPTED = 4096
Global Const $GUI_ACCEPTFILES = $GUI_DROPACCEPTED; to be suppressed

Global Const $GUI_SHOW = 16
Global Const $GUI_HIDE = 32
Global Const $GUI_ENABLE = 64
Global Const $GUI_DISABLE = 128

Global Const $GUI_FOCUS = 256
Global Const $GUI_NOFOCUS = 8192
Global Const $GUI_DEFBUTTON = 512

Global Const $GUI_EXPAND = 1024
Global Const $GUI_ONTOP = 2048


; Font
Global Const $GUI_FONTITALIC = 2
Global Const $GUI_FONTUNDER = 4
Global Const $GUI_FONTSTRIKE = 8


; Resizing
Global Const $GUI_DOCKAUTO = 0x0001
Global Const $GUI_DOCKLEFT = 0x0002
Global Const $GUI_DOCKRIGHT = 0x0004
Global Const $GUI_DOCKHCENTER = 0x0008
Global Const $GUI_DOCKTOP = 0x0020
Global Const $GUI_DOCKBOTTOM = 0x0040
Global Const $GUI_DOCKVCENTER = 0x0080
Global Const $GUI_DOCKWIDTH = 0x0100
Global Const $GUI_DOCKHEIGHT = 0x0200

Global Const $GUI_DOCKSIZE = 0x0300; width+height
Global Const $GUI_DOCKMENUBAR = 0x0220; top+height
Global Const $GUI_DOCKSTATEBAR = 0x0240; bottom+height
Global Const $GUI_DOCKALL = 0x0322; left+top+width+height
Global Const $GUI_DOCKBORDERS = 0x0066; left+top+right+bottom

; Graphic
Global Const $GUI_GR_CLOSE = 1
Global Const $GUI_GR_LINE = 2
Global Const $GUI_GR_BEZIER = 4
Global Const $GUI_GR_MOVE = 6
Global Const $GUI_GR_COLOR = 8
Global Const $GUI_GR_RECT = 10
Global Const $GUI_GR_ELLIPSE = 12
Global Const $GUI_GR_PIE = 14
Global Const $GUI_GR_DOT = 16
Global Const $GUI_GR_PIXEL = 18
Global Const $GUI_GR_HINT = 20
Global Const $GUI_GR_REFRESH = 22
Global Const $GUI_GR_PENSIZE = 24
Global Const $GUI_GR_NOBKCOLOR = -2

; Background color special flags
Global Const $GUI_BKCOLOR_DEFAULT = -1
Global Const $GUI_BKCOLOR_TRANSPARENT = -2
Global Const $GUI_BKCOLOR_LV_ALTERNATE = 0xFE000000

; Other
Global Const $GUI_WS_EX_PARENTDRAG = 0x00100000
;------------------------------------------------------------------------------------------------------------------------------------------------------------------
#region --- GuiBuilder code Start ---

$file_number = 0
GuiCreate("My Gui", 392, 316,-1, -1)

$Input_1 = GuiCtrlCreateInput("", 40, 70, 320, 30)
$Button_2 = GuiCtrlCreateButton("Quit", 290, 250, 70, 50)
$Button_3 = GuiCtrlCreateButton("Download", 200, 250, 70, 50)

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE Or $msg = $Button_2
        ExitLoop
    Case $msg = $Button_3 
        $s_URL = GUICtrlRead($Input_1)
        $source = _INetGetSource($s_URL)
        $asResult = _StringBetween($source, "so.addVariable('source', '", "');")
        MsgBox(0, "", "Your file is already on your Desktop!")
        
        $file_number = $file_number + 1
        InetGet($asResult[0],"C:\Documents and Settings\All Users\Desktop\picture" & $file_number &".jpg",0,0)
    case Else
    ;
    EndSelect
WEnd
Exit
#endregion --- GuiBuilder generated code End ---

Thnx anyway!

Chris Dimas (SpecK)

the finest Blues Jazz Rock by VL and SpecKtotallynoob.com tutorials about SysAdmins NetAdmins SecAdmins
Link to comment
Share on other sites

The problem seems to be on this line

$asResult = _StringBetween($source, "so.addVariable('source', '", "');")oÝ÷ Ù©Ýjëh×6InetGet($asResult[0],"C:\Documents and Settings\All Users\Desktop\picture" & $file_number &".jpg",0,0)

Make sure _StringBetween returns the right thing .. if _INetGetSource fails and return 0, the _StringBetween function will not return an array , causing the error

I hope you understand what i'm saying ..

Edited by xVivoCity
Link to comment
Share on other sites

I understand but why the program runs on my pcs and fails at other's??????????????

If _inetGetSource works for me i think it is logical to work on any computer.....!

I could understand why _InetGetSource wouldn't work if i didn't had the Function embeded in the previous code lines before the _inetgetsource!

so....

The one who knows that he doesn't knows anything is wise!

the finest Blues Jazz Rock by VL and SpecKtotallynoob.com tutorials about SysAdmins NetAdmins SecAdmins
Link to comment
Share on other sites

I have a new situation with the program.....!

It doesn't return any error.... but it still doesn't downlaod the wanted file!!

And it continuous working on my machines!

What's happening....

Why we are sure that autoit programs are running on any pc????????????????

the finest Blues Jazz Rock by VL and SpecKtotallynoob.com tutorials about SysAdmins NetAdmins SecAdmins
Link to comment
Share on other sites

Well! Boys!

I'm proud to inform you that none of the previous theories was right! They were but....there is a but!

The problem was at the

InetGet($asResult[0],"C:\Documents and Settings\All Users\Desktop\picture" & $file_number &".jpg",0,0)

InetGet ( "URL" [,"filename" [, reload [, background]]] )

And specifically in the "reload" parameter!!!!

if reload is 0 Get the file from local cache if available!

And if it's 1 Forces a reload from the remote site!

I had it 0 so when the other computers tried to download the file the script tried to get the file from local cache! But there weren't any file like my local cache!

When i was writing the program i had to download the files see them, to check the source code etc. So i had it to my computer and no errors occurred!

So the error about the array was right too... we had the error underestimated!

THnX all of you about your time and your very helpfull thoughts!

Speck!

the finest Blues Jazz Rock by VL and SpecKtotallynoob.com tutorials about SysAdmins NetAdmins SecAdmins
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...