Page 1 of 1 1
Topic Options
#79454 - 2003-01-30 04:15 PM While Loop
krabourn Offline
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
#79455 - 2003-01-30 04:17 PM Re: While Loop
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
You can't use GOTO in a LOOP !!!!!!!
_________________________



Top
#79456 - 2003-01-30 04:18 PM Re: While Loop
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
I'd say it's because of your GOTOs in the code. GOTOs are bad and should not be used at all, especially in loops!

Adn please fix those long lines!

[ 30. January 2003, 16:19: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#79457 - 2003-01-30 04:22 PM Re: While Loop
krabourn Offline
Hey THIS is FUN
*****

Registered: 2000-12-11
Posts: 244
Loc: San Antonio, Texas, USA
I agree and I am going to see if I can rewrite it in a better fashion.

But, that does not change the fact that it used to work in 4.12 and now it does not.

BBChecker is too fast. You responded while I was fixing it.
_________________________
Kelly

Top
#79458 - 2003-01-30 04:30 PM Re: While Loop
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
You might also want to take a look at the JOIN() and SPLIT() functions. Or reformat it into a.INI format

[ 30. January 2003, 16:32: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#79459 - 2003-01-30 04:31 PM Re: While Loop
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
who is using checker?
_________________________
!

download KiXnet

Top
#79460 - 2003-01-30 04:34 PM Re: While Loop
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I suspect Ruud will give a better explanation, but my guess is that the GOTO is doing a stack cleanup. In the absence of an elegant EXIT for the loop, GOTO has been designed to cleanup the stack to prevent stack overflows. Perhaps it is a bit more agressive in 4.20.

Ruud,
We need an EXIT LOOP. [Big Grin]
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#79461 - 2003-01-30 04:37 PM Re: While Loop
krabourn Offline
Hey THIS is FUN
*****

Registered: 2000-12-11
Posts: 244
Loc: San Antonio, Texas, USA
How short do you want them? They fit on my screen. Of course that is 1280x1024. [Smile]

Seriously, how long should a line be? I would think that is kinda relative.
_________________________
Kelly

Top
#79462 - 2003-01-30 04:40 PM Re: While Loop
krabourn Offline
Hey THIS is FUN
*****

Registered: 2000-12-11
Posts: 244
Loc: San Antonio, Texas, USA
Actually, I never leave the loop, but that would make sense. I have added another While Loop inside the get rid of the Goto and it works.
_________________________
Kelly

Top
#79463 - 2003-01-30 04:46 PM Re: While Loop
JimRobinson Offline
Fresh Scripter

Registered: 2003-01-10
Posts: 42
Loc: Tempe, AZ
I'm going to have to quit using it. I installed it mostly to look at the code, and the darn thing is addictive! I can't get any work done 'cause I'm waiting for that new post thing to float down my desktop!

Jim
_________________________
Jim
--------------------

Top
#79464 - 2003-01-31 05:17 PM Re: While Loop
Glenn Barnas Administrator Offline
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! \:D

Top
#79465 - 2003-01-31 05:31 PM Re: While Loop
krabourn Offline
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
Page 1 of 1 1


Moderator:  ShaneEP, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 765 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.064 seconds in which 0.027 seconds were spent on a total of 12 queries. Zlib compression enabled.