Jump to content
Sign in to follow this  

Array trouble

Recommended Posts

Riddle me this. How come the script below works when I run the ArrayCompare function but not if I dont? The array does not change as a result of the compare. It merely checks to see if my clean region did what I intended it to do.

Background: First array is my start data (scraped from an intranet reservations website). This array is static for now so I can test. Second array is what the output of the first array should be after the first array has been "cleaned". I then run a compare against the second to confirm its been done correctly. (This will obviously go in the final version)

So as it sits, I can get the script to clean the first array, then use it to create a reservation in another reservation website (represented by the attached HTML file), so long as I run the compare on it. If I dont run the compare, it wont work. Do changed array variables have to "saved" or "applied" somehow? what is the compare doing that makes it work?

I have to get rid of the compare because the first array cant remain static in the final version. Anyone got any ideas?

#include <Ie.au3>
#include <Array.au3>

Dim $StrLen, $cutpoint, $HTMLclip, $CheckBoxName, $PageHTML, $string, $CheckBoxName, $Result
Dim $BridgeURL = "file:///c:/pre-configured participants.htm"

#region $RSEndpoints
dim $RSEndpoints[5]
$RSEndpoints[0] = "DHCC/ECC/JPPN/MSAC: MSB 210 *"
$RSEndpoints[1] = "UBC: VGH 1916"
$RSEndpoints[2] = "UHNBC (Hosp): VGH 1912"
$RSEndpoints[3] = "UNBC (Univ): VGH 1914"
$RSEndpoints[4] = "UNBC (Univ): MSB 131"

#region $RSEndpoints
dim $RSEndpoints2[5]
$RSEndpoints2[0] = "MSB 210"
$RSEndpoints2[1] = "VGH 1916"
$RSEndpoints2[2] = "VGH 1912"
$RSEndpoints2[3] = "VGH 1914"
$RSEndpoints2[4] = "MSB 131"

$oIE= _IECreate ( $BridgeURL )
_IELoadWait ($oIE)

#region Clean
for $i = 0 to UBound ( $RSEndpoints ) - 1 
    dim $string = $RSEndpoints[$i]
    dim $cutpoint = StringInStr($string, ":")
    if $cutpoint <> 0  then $RSEndpoints[$i] = StringTrimLeft($string,($cutpoint+1)) ; trims string to start one char after the colon ":"
    If StringRight($RSEndpoints[$i],2) = " *" Then $RSEndpoints[$i] = StringTrimRight($RSEndpoints[$i],2) ; Removes traling " *" if it exists
    ;msgbox (0, "newstring", $RSEndpoints[$i])
_ArrayDisplay ($RSEndpoints)


for $i = 0 to UBound ( $RSEndpoints ) - 1 
    If $Result <> 0 then _SelectCheckBox4MatchedRoom($CheckBoxName)  ; if hit in HTML, Select its Checkbox

Func _ArrayCompare($_Array1,$_Array2)
    Dim $Array1 = $_Array1
    DIM $Array2 = $_Array2
    for $i = 0 to UBound ( $Array1 ) - 1 
        dim $string = $Array1[$i]
        if stringcompare ($Array1[$i], $Array2[$i]) = 0 then 
            ConsoleWrite ("Array line " & $i & " is True"& @CR)
            ConsoleWrite ("Array line " & $i & " is False"& @CR)
            ConsoleWrite (@TAB & "Array line " & $i & " is " & $Array1[$i] & @CR & @TAB & "Array2 Line " & $i & " is " & $Array2[$i] & @CR)

Func _SelectCheckBox4MatchedRoom($_RoomCheckBox)
    Dim $RoomCheckBox = $_RoomCheckBox
    If $RoomCheckBox <> "" then
        $colForms = _IEFormGetCollection ($oIE )
        For $oForm In $colForms
        $colElements = _IETagNameAllGetCollection ( $oForm )
            For $oElement In $colElements
            If StringInStr ( $oElement.getAttribute ( "name", 2 ), $RoomCheckBox ) <> 0 Then
                _IEAction ( $oElement, "click" )

Func _MatchRSRoom2BridgeRoom($_string)
    dim $RoomSearch = $_string
    _SearchText ($string)  ; searches HTML for string.  
    $CheckBoxName=0  ; resets variable
    $StrLen = StringLen ($RoomSearch)   ; Gets length of search string
    $cutpoint = (StringInStr ($PageHTML,$RoomSearch) + $StrLen)  ; gets position of end of search string in HTML
    $HTMLclip = StringMid ($PageHTML,($cutpoint-150),150) ; Trims HTML at right of search string, and grabs 150 chars prior
    $CheckBoxName=StringTrimLeft($HTMLclip,(StringInStr ($HTMLclip, "h323_",0,-1))-1)  ; gets first instance of "h323" from right to left and trims left
    $CheckBoxName=StringTrimRight($CheckBoxName,((StringLen ($CheckBoxName)-7))) ; grabs first 7 chars and trims rest - Looking for "h323_xx(x)" - last x must be char
    $CheckBoxName=StringStripWS($CheckBoxName, 2)  ; Removes trailing space if it exists
    If StringRight($CheckBoxName,1) = ">" Then $CheckBoxName = StringTrimRight($CheckBoxName,1) ; removes trailing ">" if it exists
    ;Msgbox (0, "CheckBoxName", $CheckBoxName)

Func _SearchText ($_TextString)
    dim $TextString = $_TextString
    $PageHTML = _IEDocReadHTML($oIE)
    $Result = StringInStr ($PageHTML, $TextString)


pre-configured participants.htm

Share this post

Link to post
Share on other sites

Killing the compare and just writing to console with the following doesnt work either, but does confirm that the clean is working and the arrays appear to be identical.

for $i = 0 to UBound ( $RSEndpoints ) - 1 
    ConsoleWrite (@TAB & "$RSEndpoints line " & $i & " is " & $RSEndpoints[$i] & @CR & @TAB & "$RSEndpoints2 Line " & $i & " is " & $RSEndpoints2[$i] & @CR & @CR)


$RSEndpoints line 0 is MSB 210

$RSEndpoints2 Line 0 is MSB 210

$RSEndpoints line 1 is VGH 1916

$RSEndpoints2 Line 1 is VGH 1916

$RSEndpoints line 2 is VGH 1912

$RSEndpoints2 Line 2 is VGH 1912

$RSEndpoints line 3 is VGH 1914

$RSEndpoints2 Line 3 is VGH 1914

$RSEndpoints line 4 is MSB 131

$RSEndpoints2 Line 4 is MSB 131

So dispite the cleaned array being identical to compare array, the rest of my script doesnt like it. Enable the compare again and it works. Still hunting for the reason but nada so far.

Share this post

Link to post
Share on other sites


Bad coding :unsure:

_SearchText ($String) ; searches HTML for string.

Should have been:

_SearchText ($RoomSearch) ; searches HTML for string.

Not sure why it worked at all with the compare running. Nice to find my own solution.

(ill try to do better due dilligence in the future - sorry)

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...