Page 1 of 1 1
Topic Options
#208176 - 2013-12-18 10:29 PM "Loop without WHILE!" Error
JustMark Offline
Fresh Scripter

Registered: 2013-03-20
Posts: 7
Loc: Arizona
Hello, in my code below I look for a text file. If it exists, it reads all 3 lines and sets variables.
It then looks for a file, if it exists, then it renames all of the files in the IF statement. If it doesn't find the file (it may still be in the process of being created) then it will sleep and loop again.
The program runs, it even renames the files like it's supposed to, but then it gives me:
ERROR : Loop without WHILE!
Script : (script name)
Line : 39 (which is the line with the word "LOOP")

Can someone tell me what's wrong with the code? I thought it was pretty straight up.
 Code:
IF Open(1,"L:\Sigrity_UPD\master_strips\Unit_Array\unit_array_info.txt", 0) = 0
	$DWG_NUMBER = ReadLine(1)
	$DWG_REVISION = ReadLine(1)
	$SOURCE_FOLDER = ReadLine(1)
ELSE
	? ('Cannot find the file')
ENDIF
Close (1)
; gerber name = 123456GBL010A.GBR

$CheckFile = $SOURCE_FOLDER + 'unit.dxf'

;Rename the gerber files
$TIME_OUT = 0
WHILE $TIME_OUT < 300
	IF EXIST ( $CheckFile )	;Check for unit.dxf
		IF EXIST ( $SOURCE_FOLDER + 'EB01.gbr' ) MOVE $SOURCE_FOLDER + 'EB01.gbr' $SOURCE_FOLDER + $DWG_NUMBER + 'GBEB01' + $DWG_REVISION + '.gbr'
		IF EXIST ( $SOURCE_FOLDER + 'EB04.gbr' ) MOVE $SOURCE_FOLDER + 'EB04.gbr' $SOURCE_FOLDER + $DWG_NUMBER + 'GBEB04' + $DWG_REVISION + '.gbr'
		IF EXIST ( $SOURCE_FOLDER + 'INNER.gbr' ) MOVE $SOURCE_FOLDER + 'INNER.gbr' $SOURCE_FOLDER + $DWG_NUMBER + 'GBINNER' + $DWG_REVISION + '.gbr'
		IF EXIST ( $SOURCE_FOLDER + 'L01.gbr' ) MOVE $SOURCE_FOLDER + 'L01.gbr' $SOURCE_FOLDER + $DWG_NUMBER + 'GBL01' + $DWG_REVISION + '.gbr'
		IF EXIST ( $SOURCE_FOLDER + 'L04.gbr' ) MOVE $SOURCE_FOLDER + 'L04.gbr' $SOURCE_FOLDER + $DWG_NUMBER + 'GBL04' + $DWG_REVISION + '.gbr'
		IF EXIST ( $SOURCE_FOLDER + 'S01.gbr' ) MOVE $SOURCE_FOLDER + 'S01.gbr' $SOURCE_FOLDER + $DWG_NUMBER + 'GBS01' + $DWG_REVISION + '.gbr'
		IF EXIST ( $SOURCE_FOLDER + 'S04.gbr' ) MOVE $SOURCE_FOLDER + 'S04.gbr' $SOURCE_FOLDER + $DWG_NUMBER + 'GBS04' + $DWG_REVISION + '.gbr'
		$TIME_OUT = 300
	ELSE
		sleep 20
		$TIME_OUT = $TIME_OUT + 20
	ENDIF
LOOP


Thanks,
Mark


Edited by Mart (2013-12-19 10:09 AM)
Edit Reason: Added code tags.

Top
#208177 - 2013-12-18 10:41 PM Re: "Loop without WHILE!" Error [Re: JustMark]
JustMark Offline
Fresh Scripter

Registered: 2013-03-20
Posts: 7
Loc: Arizona
Ok, never mind, I got it. I just added "ENDIF" to each of the "IF EXIST" lines.
 Code:
		IF EXIST ( $SOURCE_FOLDER + 'EB01.gbr' ) MOVE $SOURCE_FOLDER + 'EB01.gbr' $SOURCE_FOLDER + $DWG_NUMBER + 'GBEB01' + $DWG_REVISION + '.gbr' ENDIF
		IF EXIST ( $SOURCE_FOLDER + 'EB04.gbr' ) MOVE $SOURCE_FOLDER + 'EB04.gbr' $SOURCE_FOLDER + $DWG_NUMBER + 'GBEB04' + $DWG_REVISION + '.gbr' ENDIF
		IF EXIST ( $SOURCE_FOLDER + 'INNER.gbr' ) MOVE $SOURCE_FOLDER + 'INNER.gbr' $SOURCE_FOLDER + $DWG_NUMBER + 'GBINNER' + $DWG_REVISION + '.gbr' ENDIF
		IF EXIST ( $SOURCE_FOLDER + 'L01.gbr' ) MOVE $SOURCE_FOLDER + 'L01.gbr' $SOURCE_FOLDER + $DWG_NUMBER + 'GBL01' + $DWG_REVISION + '.gbr' ENDIF
		IF EXIST ( $SOURCE_FOLDER + 'L04.gbr' ) MOVE $SOURCE_FOLDER + 'L04.gbr' $SOURCE_FOLDER + $DWG_NUMBER + 'GBL04' + $DWG_REVISION + '.gbr' ENDIF
		IF EXIST ( $SOURCE_FOLDER + 'S01.gbr' ) MOVE $SOURCE_FOLDER + 'S01.gbr' $SOURCE_FOLDER + $DWG_NUMBER + 'GBS01' + $DWG_REVISION + '.gbr' ENDIF
		IF EXIST ( $SOURCE_FOLDER + 'S04.gbr' ) MOVE $SOURCE_FOLDER + 'S04.gbr' $SOURCE_FOLDER + $DWG_NUMBER + 'GBS04' + $DWG_REVISION + '.gbr' ENDIF

Sheesh :-)


Edited by Mart (2013-12-19 10:10 AM)
Edit Reason: Added code tags.

Top
#208178 - 2013-12-19 01:33 AM Re: "Loop without WHILE!" Error [Re: JustMark]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
Welcome to KORG! Sometimes all it takes is explaining the problem to see it yourself! (glad we all could help! \:D )

Couple of suggestions - you might want to implement better error control/traps.. consider
 Code:
$OK = 1		; assume success
If Open(1, "L:\Sigrity_UPD\master_strips\Unit_Array\unit_array_info.txt", 0) = 0
 $DWG_NUMBER = ReadLine(1)
 $DWG_REVISION = ReadLine(1)
 $SOURCE_FOLDER = ReadLine(1)
Else
  ('Cannot find the file') ?
  $OK = 0	; no file, no success!
EndIf

Close (1)
; gerber name = 123456GBL010A.GBR

If $OK		; process only if file was found

  $CheckFile = $SOURCE_FOLDER + 'unit.dxf'

  ;Rename the gerber files
  $TIME_OUT = 0
  WHILE $TIME_OUT < 300
    If Exist($CheckFile ) ;Check for unit.dxf
      If Exist($SOURCE_FOLDER + 'EB01.gbr' ) MOVE $SOURCE_FOLDER + 'EB01.gbr' $SOURCE_FOLDER + $DWG_NUMBER + 'GBEB01' + $DWG_REVISION + '.gbr' EndIf
      If Exist($SOURCE_FOLDER + 'EB04.gbr' ) MOVE $SOURCE_FOLDER + 'EB04.gbr' $SOURCE_FOLDER + $DWG_NUMBER + 'GBEB04' + $DWG_REVISION + '.gbr' EndIf
      If Exist($SOURCE_FOLDER + 'INNER.gbr' ) MOVE $SOURCE_FOLDER + 'INNER.gbr' $SOURCE_FOLDER + $DWG_NUMBER + 'GBINNER' + $DWG_REVISION + '.gbr' EndIf
      If Exist($SOURCE_FOLDER + 'L01.gbr' ) MOVE $SOURCE_FOLDER + 'L01.gbr' $SOURCE_FOLDER + $DWG_NUMBER + 'GBL01' + $DWG_REVISION + '.gbr' EndIf
      If Exist($SOURCE_FOLDER + 'L04.gbr' ) MOVE $SOURCE_FOLDER + 'L04.gbr' $SOURCE_FOLDER + $DWG_NUMBER + 'GBL04' + $DWG_REVISION + '.gbr' EndIf
      If Exist($SOURCE_FOLDER + 'S01.gbr' ) MOVE $SOURCE_FOLDER + 'S01.gbr' $SOURCE_FOLDER + $DWG_NUMBER + 'GBS01' + $DWG_REVISION + '.gbr' EndIf
      If Exist($SOURCE_FOLDER + 'S04.gbr' ) MOVE $SOURCE_FOLDER + 'S04.gbr' $SOURCE_FOLDER + $DWG_NUMBER + 'GBS04' + $DWG_REVISION + '.gbr' EndIf
      $TIME_OUT = 300
    Else
      sleep 20
      $TIME_OUT = $TIME_OUT + 20
    EndIf
  Loop
EndIf
You could also simply replace the $OK=0 with a Close(1) and an Exit 2, eliminating the If $OK block. Either way, you would not process the main code if the first file wasn't able to be opened.

Look at the Sanity() UDF or grab the Kix Development Kit from my web site and use KGen to scan your script for common errors like this.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
Page 1 of 1 1


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

Who's Online
0 registered and 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.058 seconds in which 0.031 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org