Jump to content
Sign in to follow this  
Olsson

_StringBetween - Array error

Recommended Posts

Olsson

Hey guys!

While executing this command:

$b_html = _IEBodyReadHTML ($oIE)
$b_b = _StringBetween ($b_html, "document.snd.t"&$b_unit&".value=", ";")
$t_built = $t_built + $b_b[0]

I get this error:

dra2.au3 (138) : ==> Subscript used with non-Array variable.:
$t_built = $t_built + $b_b[0]
$t_built = $t_built + $b_b^ ERROR

I know "why" this is happening - This is reading from a website and inserting this info into another function. But $b_b is only a valid array when the _StringBetween is functional. So if the website takes to long to load, or it loads wrong, my program crashes. Is there any possible way to make it.. Not crash when this fails?

Thanks,

Olsson

Share this post


Link to post
Share on other sites
martin

Hey guys!

While executing this command:

$b_html = _IEBodyReadHTML ($oIE)
$b_b = _StringBetween ($b_html, "document.snd.t"&$b_unit&".value=", ";")
$t_built = $t_built + $b_b[0]

I get this error:

dra2.au3 (138) : ==> Subscript used with non-Array variable.:
$t_built = $t_built + $b_b[0]
$t_built = $t_built + $b_b^ ERROR

I know "why" this is happening - This is reading from a website and inserting this info into another function. But $b_b is only a valid array when the _StringBetween is functional. So if the website takes to long to load, or it loads wrong, my program crashes. Is there any possible way to make it.. Not crash when this fails?

Thanks,

Olsson

You can test to see $b_html contains the start and end string first, and you can test @error after calling _StringBetween before using $b_b as an array, or check that $b_b is an array.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
Olsson

You can test to see $b_html contains the start and end string first, and you can test @error after calling _StringBetween before using $b_b as an array, or check that $b_b is an array.

How do I test if it is an array? Then it should be able to just - If $b_b is an array, then execute, if it's not an array, then do nothing?

Share this post


Link to post
Share on other sites
Robjong

Hey,

here are some options

$b_html = _IEBodyReadHTML ($oIE)
$b_b = _StringBetween ($b_html, "document.snd.t"&$b_unit&".value=", ";")
If @error Then Exit 1; Return SetError(1, 0, 0) ; option 1
;~ If Not IsArray($b_B) Then Return SetError(1, 0, 0) ; Exit 1 ; option 2
;~ If Not @error Then $t_built = $t_built + $b_b[0] ; option 3
;~ If IsArray($b_B) Then $t_built = $t_built + $b_b[0] ; option 4
Edited by Robjong

Share this post


Link to post
Share on other sites
Olsson

@Robjong

Thanks, seems to work! Trying it out right now!

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  

×