Jump to content
Sign in to follow this  
NicePerson

Error: Subscript used with non-Array Variable

Recommended Posts

NicePerson

This script works fine before compiling but why it does not work after compiling?

After compiling when i run this error comes:

Error: Subscript used with non-Array Variable

#include <INet.au3>

$aPasses = StringRegExp(_INetGetSource('http://www.sitename.com'),"update=..", 3)
If StringReplace($aPasses[0],'update="', "") = 1 Then
MsgBox(0, "", "Update is available")
_Update()
Else
    MsgBox(0, "", "Update is not available")
EndIf


Func _Update()
    Local $hDownload = InetGet("http://www.sitename.com/NewVersion.exe", @ScriptDir & "\NewVersion.exe", 1, 1)
Do
    Sleep(250)
Until InetGetInfo($hDownload, 2)    ; Check if the download is complete.
InetClose($hDownload)   ; Close the handle to release resourcs.
Run(@ScriptDir & "\NewVersion.exe")
EndFunc
Edited by RMR

Share this post


Link to post
Share on other sites
trancexx

Because $aPasses is not an array then.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
FlyinRiz

My guess is it's failing at the StringReplace because the StringRegExp never returned a match (and therefore an array)

Try adding...

If @error = 0 Then
    MsgBox(0, "", "Keyword Update not found")
EndIf

...right after the StringRegExp statement like this...

$aPasses = StringRegExp(_INetGetSource('http://www.sitename.com'),"update=..", 3)
If @error = 0 Then
    MsgBox(0, "", "Keyword Update not found")
EndIf
If StringReplace($aPasses[0],'update="', "") = 1 Then
MsgBox(0, "", "Update is available")
_Update()
Else
    MsgBox(0, "", "Update is not available")
EndIf

That should tell you if it's failing or not.

-Aaron

Share this post


Link to post
Share on other sites
NicePerson

Because $aPasses is not an array then.

Any other way?

Share this post


Link to post
Share on other sites
Tvern

Any other way?

No. If that's your whole script that is definately the problem. Look at FlyinRiz' post for a solution.

<h3></h3>

Edit: Where did the header tags come from?

Edited by Tvern

Share this post


Link to post
Share on other sites
FlyinRiz

@error = 0 means that that the array is valid.

Look at the helpfile for @error codes, but you definately should have error checking.

Yea thx...I'm not reading that well...working on an all night server rebuild at work. ;)

Share this post


Link to post
Share on other sites
NicePerson

My guess is it's failing at the StringReplace because the StringRegExp never returned a match (and therefore an array)

Try adding...

If @error = 0 Then
    MsgBox(0, "", "Keyword Update not found")
EndIf

...right after the StringRegExp statement like this...

$aPasses = StringRegExp(_INetGetSource('http://www.sitename.com'),"update=..", 3)
If @error = 0 Then
    MsgBox(0, "", "Keyword Update not found")
EndIf
If StringReplace($aPasses[0],'update="', "") = 1 Then
MsgBox(0, "", "Update is available")
_Update()
Else
    MsgBox(0, "", "Update is not available")
EndIf

That should tell you if it's failing or not.

-Aaron

I tried this but problem not solved!!

Now what i should do?

Share this post


Link to post
Share on other sites
4ggr35510n

#include <INet.au3>

Global $actual_version_of_program = "1.01"

$aPasses = StringRegExp(_INetGetSource('http://www.sitename.com'),'update.?=.?([0-9]\x2e[0-9]{2})', 3)
If IsArray($aPasses) Then
MsgBox(0,"Preparing for update...","Your version of program is " & $actual_version_of_program & @LF & @LF & "On server there is version " & $aPasses[0])
Else
MsgBox(0,"Error", "Server webpage in unavaible or doesn't containt string 'update'")
EndIf

Pattern 'update.?=.?([0-9]\x2e[0-9]{2})' will returns every number followed by dot followed by two numbers, IF there is string update followed by any character or "=" followed by any character or not...

In example:

Update = 1.05 ---> returns 1.05

Update=1.23 ---> returns 1.23

Update?=#1.00 ---> returns 1.00

Update 1.43 ---> DOESNT MATCH

Updte = 1.11 ---> DOESNT MATCH

Update=_1.11 ---> returns 1.11

Edited by 4ggr35510n

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.