#79454 - 2003-01-30 04:15 PM
While Loop
|
krabourn
Hey THIS is FUN
   
Registered: 2000-12-11
Posts: 244
Loc: San Antonio, Texas, USA
|
It appears I have found a bug in 4.20 in regards to the "While Loop". I have tried my code against B1 thru RC2. This works in 4.12.
I get the following error when the Loop command is reached. quote: ERROR : LOOP without WHILE! Script: C:\Programs\Kix\kixforms\RTA\testloop.kix Line : 49
File: Test.txt
code:
Computer,Ping Status,Ping IP,Admin Access,WMI Access,SMS Client Problem,SMS Server GUID,SMS Client UI TESTNAME1,Off,20.185.232.137,,,,3478A6C0-8ECB-11D6-8134-00C04F375552, TESTNAME2,On,103.81.60.171,Access,Access,Match,HO10I0X6,HO10I0X6
Source Code: code:
BREAK ON
$FileComputerList = '.\Test.txt'
IF Open (10, $FileComputerList, 2) = 0 $TempComputerList = '' $LineComputerList = ReadLine (10) WHILE @Error = 0 :CheckLineComputerList SELECT CASE Substr ($LineComputerList, 1, 2) = '\\' $LineComputerList = Substr ($LineComputerList, 3, Len ($LineComputerList)) GOTO 'CheckLineComputerList' CASE Substr ($LineComputerList, 1, 1) = '\' $LineComputerList = Substr ($LineComputerList, 2, Len ($LineComputerList)) GOTO 'CheckLineComputerList' CASE Substr ($LineComputerList, 1, 1) = '"' $LineComputerList = Substr ($LineComputerList, 2, Len ($LineComputerList)) GOTO 'CheckLineComputerList' CASE InStr ($LineComputerList, '"') > 1 $LineComputerList = Substr ($LineComputerList, 1, InStr ($LineComputerList, '"') - 1) GOTO 'CheckLineComputerList' CASE Substr ($LineComputerList, 1, 1) = "'" $LineComputerList = Substr ($LineComputerList, 2, Len ($LineComputerList)) GOTO 'CheckLineComputerList' CASE InStr ($LineComputerList, "'") > 1 $LineComputerList = Substr ($LineComputerList, 1, InStr ($LineComputerList, "'") - 1) GOTO 'CheckLineComputerList' CASE InStr ($LineComputerList, ' ') > 1 $LineComputerList = Substr ($LineComputerList, 1, InStr ($LineComputerList, ' ') - 1) GOTO 'CheckLineComputerList' CASE InStr ($LineComputerList, Chr (9)) > 1 $LineComputerList = Substr ($LineComputerList, 1, InStr ($LineComputerList, Chr (9)) - 1) GOTO 'CheckLineComputerList' CASE InStr ($LineComputerList, ',') > 1 $LineComputerList = Substr ($LineComputerList, 1, InStr ($LineComputerList, ',') - 1) GOTO 'CheckLineComputerList' CASE InStr ($LineComputerList, ';') > 1 $LineComputerList = Substr ($LineComputerList, 1, InStr ($LineComputerList, ';') - 1) GOTO 'CheckLineComputerList' CASE InStr ($LineComputerList, '.') > 1 $LineComputerList = Substr ($LineComputerList, 1, InStr ($LineComputerList, '.') - 1) GOTO 'CheckLineComputerList' ENDSELECT IF $LineComputerList <> '' AND NOT InStr ($TempComputerList, $LineComputerList) AND Len ($LineComputerList) < 16 AND NOT InStr (Lcase ($LineComputerList), 'computer') AND NOT InStr (Lcase ($LineComputerList), 'workstation') AND NOT InStr (Lcase ($LineComputerList), 'rfid') AND Lcase (Substr ($LineComputerList, 1, 2)) <> 'pwr' $TempComputerList = $TempComputerList + $LineComputerList + ',' ENDIF $LineComputerList = ReadLine (10) LOOP $Nul = Close (10) ENDIF $ArrComputerList = Split (Substr ($TempComputerList, 1, Len ($TempComputerList) - 1), ',', -1) FOR EACH $Computer IN $ArrComputerList ? $Computer NEXT
QUIT 0
[ 30. January 2003, 16:19: Message edited by: krabourn ]
_________________________
Kelly
|
|
Top
|
|
|
|
#79464 - 2003-01-31 05:17 PM
Re: While Loop
|
Glenn Barnas
KiX Supporter
   
Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
|
Hmm..
The GOTO isn't exiting the loop, but is short-circuiting the SELECT.
Simple change:
While @ERROR=0 :TOP $FLAG=0 Select Case (whatever you need..) set some value... $FLAG=1 Case (something else...) More Code... $FLAG=1 EndSelect If $FLAG = 1 goto TOP
; if no chages via CASE, $FLAG will still be zero
More end of loop code....
Loop ; get next data
This lets the select / endselect work properly while preserving your logic.
Another method might be to embed a loop around the select, looping as long as changes are made. From your last message, it sounds like this may be what you did.
While @ERROR=0 $FLAG=1 ; continue subloop until cleared While $FLAG=1 Select Case test_1 do stuff... Case test_2 do different stuff.. Case 1 ; we didn't do anything, so clear FLAG $FLAG=0 EndSelect Loop ; while FLAG=1 Loop ; while ERROR=0
Remember that only the first match in a case is executed, even if others are true. Thus, after continuously chopping the leading chars off, when you no longer match anything, the "1" will match as a default - changing the FLAG value and terminating the inner loop. In both examples, the EndSelect is reached for each iteration. This is where the problem may have arisen - too many SELECTs were opened.
Glenn
_________________________
Actually I am a Rocket Scientist!
|
|
Top
|
|
|
|
#79465 - 2003-01-31 05:31 PM
Re: While Loop
|
krabourn
Hey THIS is FUN
   
Registered: 2000-12-11
Posts: 244
Loc: San Antonio, Texas, USA
|
I did the loop around the select. I still want to find a way to make it faster, but that is a lower priority, at the moment. I wish I would not get so many reports formatted differently from people.
Thanks
code:
WHILE @Error = 0 $LineCheck = 1 WHILE $LineCheck = 1 SELECT CASE Substr ($LineComputerList, 1, 2) = '\\' $LineComputerList = Substr ($LineComputerList, 3, Len ($LineComputerList)) CASE Substr ($LineComputerList, 1, 1) = '\' $LineComputerList = Substr ($LineComputerList, 2, Len ($LineComputerList)) CASE Substr ($LineComputerList, 1, 1) = '"' $LineComputerList = Substr ($LineComputerList, 2, Len ($LineComputerList)) CASE InStr ($LineComputerList, '"') > 1 $LineComputerList = Substr ($LineComputerList, 1, InStr ($LineComputerList, '"') - 1) CASE Substr ($LineComputerList, 1, 1) = "'" $LineComputerList = Substr ($LineComputerList, 2, Len ($LineComputerList)) CASE InStr ($LineComputerList, "'") > 1 $LineComputerList = Substr ($LineComputerList, 1, InStr ($LineComputerList, "'") - 1) CASE InStr ($LineComputerList, ' ') > 1 $LineComputerList = Substr ($LineComputerList, 1, InStr ($LineComputerList, ' ') - 1) CASE InStr ($LineComputerList, Chr (9)) > 1 $LineComputerList = Substr ($LineComputerList, 1, InStr ($LineComputerList, Chr (9)) - 1) CASE InStr ($LineComputerList, ',') > 1 $LineComputerList = Substr ($LineComputerList, 1, InStr ($LineComputerList, ',') - 1) CASE InStr ($LineComputerList, ';') > 1 $LineComputerList = Substr ($LineComputerList, 1, InStr ($LineComputerList, ';') - 1) CASE InStr ($LineComputerList, '.') > 1 $LineComputerList = Substr ($LineComputerList, 1, InStr ($LineComputerList, '.') - 1) CASE 1 $LineCheck = 0 ENDSELECT LOOP IF $LineComputerList <> '' AND NOT InStr ($TempComputerList, $LineComputerList) AND Len ($LineComputerList) < 16 AND NOT InStr (Lcase ($LineComputerList), 'computer') AND NOT InStr (Lcase ($LineComputerList), 'workstation') AND NOT InStr (Lcase ($LineComputerList), 'rfid') AND Lcase (Substr ($LineComputerList, 1, 2)) <> 'pwr' $TempComputerList = $TempComputerList + $LineComputerList + ',' ENDIF $LineComputerList = ReadLine (10) LOOP
_________________________
Kelly
|
|
Top
|
|
|
|
Moderator: ShaneEP, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Ruud van Velsen, Mart
|
0 registered
and 765 anonymous users online.
|
|
|