Sign in to follow this  
Followers 0
VVDOOM

A Cludged Array - A Better Way???

2 posts in this topic

I have this piece of code. It works. However I am sure there should be an easier way to do this. The problem is that I don't know how to declare an array of variable length in AutoIT. If I could then I could make the npc_arr global instead of local. I want to turn this into a function where i pass a url ==> $url_01, $url_02, etc. and then get back the ncp_arr[]. could someone help me with how that would work? would it be like $duh = func_name($url_01) and then $duh would be the array same as $npc_arr???

Thanks for your help.

; This navigates to the page and reads page into $sHTML

_IENavigate($oIE, $url_01)

_IELoadWait($oIE)

$sHTML = _IEDocReadHTML ($oIE)

; This finds all instances of the 3 types of items I am looking for

$aArray1 = _StringBetween($sHTML, $npc1, ' class', -1)

$aArray2 = _StringBetween($sHTML, $npc2, ' class', -1)

$aArray3 = _StringBetween($sHTML, $npc3, ' class', -1)

; This gets the length of each array

$a1_size = UBound($Aarray1)

$a2_size = UBound($Aarray2)

$a3_size = UBound($Aarray3)

; Get total size or number of NPCs

$tot_arr_size = $a1_size + $a2_size + $a3_size

; Create the master array for NPCs

Local $npc_arr[$tot_arr_size]

; Use a master counter for the arrays

$i = 0

; Input the first array location into the master array

For $element IN $aArray1

$ttt = $element & ' onmouseover="return pos('

$aArrayZ = _StringBetween($sHTML, $ttt, ')')

$npc_arr[$i] = $aArrayZ[0]

$i = $i + 1

Next

; Input the second array location into the master array

For $element IN $aArray2

$ttt = $element & ' onmouseover="return pos('

$aArrayZ = _StringBetween($sHTML, $ttt, ')')

$npc_arr[$i] = $aArrayZ[0]

$i = $i + 1

Next

; Input the third array location into the master array

For $element IN $aArray3

$ttt = $element & ' onmouseover="return pos('

$aArrayZ = _StringBetween($sHTML, $ttt, ')')

$npc_arr[$i] = $aArrayZ[0]

$i = $i + 1

Next

_ArrayDisplay($npc_arr, 'Testing')

Share this post


Link to post
Share on other sites



There's no way of declaring a, 'dynamically growing array'. You can use Redim to resize an array if you'd like.

Your code could be cleaned up I suppose but I don't see anything terrible about it. If your $npc_arr array always end up roughly around the same size, you can always declare your array much larger then you would need to and redim it later. So if you always get around 25 total count in your array, size it originally to 100 and redim it later.

I'd suggest you take a look at byref in the help file, that might help you turn it into a function like you want to. Let us know how that works for you.


While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd

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