Jump to content

Loop wont quit


Recommended Posts

I have an odd problem. Im sure my coding is correct, but my script is not happy and I have to force close it (no console errors).

Synopsis:

Hard coded array, scanning array for strings, if found, remove array entry. Loop until no more entries found.

; Includes:
#include <Array.au3>

Dim $Array[16]
$Array[0]='16'
$Array[1]='ARC/CGH: CGH ICU-2 (+bk w/owner)'
$Array[2]='ARC/CGH: SMH 1752'
$Array[3]='ARC/HA: Duncan (+chk w/owner)'
$Array[4]='ARC/HA: NRGH 2053'
$Array[5]='ARC: MMH - Terrace'
$Array[6]='CWH/RCH/SPH: RCH 017'
$Array[7]='DHCC/ECC/JPPN/MSAC: DHCC 11268'
$Array[8]='KGH/RIH: KEL CAC 235'
$Array[9]='KGH/RIH: RIH B1 (+bk w/owner)'
$Array[10]='RJH/VGH: RJH CA 130'
$Array[11]='RJH/VGH: VGH 1914'
$Array[12]='High Def (Y1, Y2 Curr): ID 30101'
$Array[13]='VC: External Site A'
$Array[14]='UHNBC (Hosp): UHNBC 5011'
$Array[15]='VC: External Site B'

;----------------Clean-------------------
_ArrayDisplay($Array, "before clean")

DIM $External
While 1
    $External = _IsArrayItemInString ($Array, "External Site" )  
    if $External = "False" then 
        ExitLoop
    Else 
        MsgBox (0,"External Sites", $External)
        _ArrayDelete($Array, $External)
    EndIf
WEnd

_ArrayDisplay($Array, "after clean")
;/----------------Clean-------------------
Exit

Func _IsArrayItemInString ( $_Array, $_Item )     
    For $_A = 1 To UBound ( $_Array ) - 1         
        If $_Array[$_A] <> '' And StringInStr ( $_Array[$_A], $_Item ) <> 0 Then Return $_A
        Next
    Return False
EndFunc ;==> _IsArrayItemInString ( )

Any help appreciated.

Link to comment
Share on other sites

Hint #1: False <> "False"

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

I should have mentioned that it all works ecept for:

if $External = "False" then

ExitLoop

The only thing I can think of is that when there are no hits, $External does not actually = "False". And then tries to _ArrayDelete($Array, "False" ) it probably wont compute very well. But the MsgBox showing the value says it = "False"... If its not "False" then what is it?

Thanks all.

Link to comment
Share on other sites

Hint #2: better code

#include <Array.au3>

Dim $Array[16] = [ _
    '16', _                             ; is this count really required?
    'ARC/CGH: CGH ICU-2 (+bk w/owner)', _
    'ARC/CGH: SMH 1752', _
    'ARC/HA: Duncan (+chk w/owner)', _
    'ARC/HA: NRGH 2053', _
    'ARC: MMH - Terrace', _
    'CWH/RCH/SPH: RCH 017', _
    'DHCC/ECC/JPPN/MSAC: DHCC 11268', _
    'KGH/RIH: KEL CAC 235', _
    'KGH/RIH: RIH B1 (+bk w/owner)', _
    'RJH/VGH: RJH CA 130', _
    'RJH/VGH: VGH 1914', _
    'High Def (Y1, Y2 Curr): ID 30101', _
    'VC: External Site A', _
    'UHNBC (Hosp): UHNBC 5011', _
    'VC: External Site B' _
]

;----------------Clean-------------------
_ArrayDisplay($Array, "before clean")

DIM $External

While 1
    $External = _ArraySearch($Array, "External Site", 1, 0, 0, 1)
    If $External < 0 Then
        ExitLoop
    Else
        MsgBox (0,"External Sites", $External)
        _ArrayDelete($Array, $External)
        $Array[0] -= 1
    EndIf
WEnd

_ArrayDisplay($Array, "after clean")

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

No, its not. Its simulating an array I use to scrape the room bookings from the reservation site. Its easier to remove it from the array during the "clean" than to figure out why its showing up in the other array. It all works fine and I have bigger fish to fry. But once I get it operational and tidy things up, I may review that.

Does the "$Array[0] -= 1" re-inumerate the array?

thanks

Link to comment
Share on other sites

No problem with the count in [0]. Yes, you need to decrement it for every delete, or it won't mean much after that!

Lookup help of _ArrayDelete parameters if you ever need to change mind.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

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...