#3216 - 2000-05-31 03:33 PM
Counter Script
|
Anonymous
Anonymous
Unregistered
|
Hey All, I would like build a script that does something like this. -------------------------------------- ?" ENTER THE QUE IE. AMAPPP" ?"" GETS $QUe goto COUNTER:COUNTER $Que = $QUe +1 if $QUe="155" goto END else $q = open(1,"c:\QUE.TXT",5) $q = WRITELINE(1,"$QUe") goto COUNTER :END endif EXIT ------------------------------------ Basicly I want the script to count from 001 to 155, with an output like: amappp001 amappp002 amappp003 through amappp155 the script i have builds this amappp1 amappp11 amappp111 amappp1111 as oyu can imagine in 20 seconds you get a file about 7MB in size with ALOT of 1'S. How should I rethink my math functions? Thanks in Advance!
------------------ THANKS MARK =)
|
|
Top
|
|
|
|
#3217 - 2000-05-31 06:33 PM
Re: Counter Script
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
|
|
Top
|
|
|
|
#3218 - 2000-06-01 01:54 PM
Re: Counter Script
|
Anonymous
Anonymous
Unregistered
|
Gives me this: -------------------------------12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514 614714814915015115215315412345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714 814915015115215315412345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915 015115215315412345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115 2153154 ------------------------------------ DOH! 
------------------ THANKS MARK =)
|
|
Top
|
|
|
|
#3222 - 2000-06-15 06:16 PM
Re: Counter Script
|
MCA
KiX Supporter
   
Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
|
We look also at your code. A little redesign, because we don't like GOTO at all. Other things I saw:
- a lot of GOTO statements. code which is very hard to maintain.
- possible to get a deadlock situation, when you enter a number
greater then 155. program never ends.
- each time you open the same file results in an enormous amount of
registry calls, which isn't necessary.
- you don't check of file "c:\que.txt" was correct open.
code:
IF .... GOTO end ELSE :end ENDIF
very original design. "GOTO end" statement not necessary. position of ":end" needs no explanation.
- using SELECT/ENDSELECT structure possible, but the same effect can be created by one single statement.
- usage of SHELL slows down performance, because each time a DOS virtual environment must be created.
Our version:
- an initialization block,
- a check of inconsistent settings,
- an input block,
- the real program with additional 'debug' code (= print statements).
code:
; ; - initialize variables - ; $file="counter.txt" ; (I) ; filename $prefix="amappp" ; (I) ; start of string $suffix="" ; (I) ; end of string $format=5 ; (I) ; max width of number range $max_que=250 ; (I) ; max number of range ; ; - check variables - ; IF ($max_que > substr("999999",1,$format)) ; correct of $max_que to max width of number range $max_que=substr("999999",1,$format) ; position STOP ENDIF ; ? "Enter QUE ie."+LCASE($prefix)+" (max.value "+$max_que+") " ? GETS $que ; $i=val("$que") ; position START IF ($i <= $max_que) ? "Informative COUNT: start '$que' till '$max_que' on file '$file' ("+@time+")" ? IF (OPEN(1,$file,5) = 0) WHILE ($i <= $max_que) $info=$prefix+substr("000000",1,$format-len("$i"))+$i+$suffix+chr(13)+chr(10) IF (WriteLine(1,$info) <> 0) ? @serror ENDIF ? " "+substr(" ",1,$format-len("$i"))+$i+".."+$max_que+" -> "+LCASE($prefix+substr("000000",1,$format-len("$i"))+$i+$suffix) $i=$i+1 LOOP IF Close(1) <> 0 ENDIF ENDIF ? ? "Informative COUNT: ("+$que+".."+$max_que+") completed. ("+@time+")" ELSE ? "Abort COUNT: out of range" ENDIF EXIT
Example of output after entering value '3': code:
Enter QUE ie.amappp (max.value 250)Informative COUNT: start '3' till '250' on file 'counter.txt' (05:15:16) 3..250 -> amappp00003 4..250 -> amappp00004 5..250 -> amappp00005 6..250 -> amappp00006 7..250 -> amappp00007 8..250 -> amappp00008 9..250 -> amappp00009 10..250 -> amappp00010 ... 240..250 -> amappp00240 241..250 -> amappp00241 242..250 -> amappp00242 243..250 -> amappp00243 244..250 -> amappp00244 245..250 -> amappp00245 246..250 -> amappp00246 247..250 -> amappp00247 248..250 -> amappp00248 249..250 -> amappp00249 250..250 -> amappp00250 Informative COUNT: (3..250) completed. (05:15:24)
Another run after changing variables of initialization block. code:
$file="counter.txt" ; (I) ; filename $prefix="Count-" ; (I) ; start of string $suffix=".txt" ; (I) ; end of string $format=4 ; (I) ; max width of number range $max_que=250 ; (I) ; max number of range
Example of output after entering value '235': code:
Enter QUE ie.count- (max.value 250) Informative COUNT: start '235' till '250' on file 'counter.txt' (05:18:26) 235..250 -> count-0235.txt 236..250 -> count-0236.txt 237..250 -> count-0237.txt 238..250 -> count-0238.txt 239..250 -> count-0239.txt 240..250 -> count-0240.txt 241..250 -> count-0241.txt 242..250 -> count-0242.txt 243..250 -> count-0243.txt 244..250 -> count-0244.txt 245..250 -> count-0245.txt 246..250 -> count-0246.txt 247..250 -> count-0247.txt 248..250 -> count-0248.txt 249..250 -> count-0249.txt 250..250 -> count-0250.txt Informative COUNT: (235..250) completed. (05:18:27)
Same source without a great amount of comment statements. Manipulation will be harder. code:
$file="counter.txt" ; (I) ; filename $prefix="Count-" ; (I) ; start of string $suffix=".txt" ; (I) ; end of string $format=4 ; (I) ; max width of number range $max_que=250 ; (I) ; max number of range/position STOP ; IF ($max_que > substr("999999",1,$format)) $max_que=substr("999999",1,$format) ENDIF ? "Enter QUE ie."+LCASE($prefix)+" (max.value "+$max_que+") " ? GETS $que ; $i=val("$que") ; position START IF ($i <= $max_que) IF (OPEN(1,$file,5) = 0) WHILE ($i <= $max_que) $info=$prefix+substr("000000",1,$format-len("$i"))+$i+$suffix+chr(13)+chr(10) IF (WriteLine(1,$info) <> 0) ENDIF $i=$i+1 LOOP IF Close(1) <> 0 ENDIF ENDIF ENDIF EXIT
Same source without any comment and without any structure. Manipulation will be harder. code:
$file="counter.txt" $prefix="Count-" $suffix=".txt" $format=4 $max_que=250 IF ($max_que > substr("999999",1,$format)) $max_que=substr("999999",1,$format) ENDIF ? "Enter QUE ie."+LCASE($prefix)+" (max.value "+$max_que+") " ? GETS $que $i=val("$que") IF ($i <= $max_que) IF (OPEN(1,$file,5) = 0) WHILE ($i <= $max_que) $info=$prefix+substr("000000",1,$format-len("$i"))+$i+$suffix+chr(13)+chr(10) IF (WriteLine(1,$info) <> 0) ENDIF $i=$i+1 LOOP IF Close(1) <> 0 ENDIF ENDIF ENDIF EXIT
The most interesting part for me was the way of convertion of strings to numbers. Greetings.
|
|
Top
|
|
|
|
#3224 - 2000-06-16 11:19 PM
Re: Counter Script
|
MCA
KiX Supporter
   
Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
|
I think also, but when I was looking for a simple piece of code we discover the enormous amount of freedom in Kixtart syntax. A simple type-error creates:
- an endless loop
- an automatic reboot
- a DrWatson error
By a short program it isn't difficult to repair. By Windows NT you can mostly easily end the task. By Windows 9x you must reboot it. When it only runs on mine system it isn't a problem, but company width this kind of errors can be a disaster. So, Mark's question was an interesting study. Greetings.BTW: a simple script is when it is one line. see last piece of code. Mark's didn't ask for something which isn't possible to maintain. A new version we can run is: code:
begin. ¶ìš–锡ê깿ôýÑ…–µ˜Úä¾™€’�Â÷‹²ã�ß·ÝñŠé¸âùéç̌–ÎË‘õà®ÔæÒ´è‡‘á“°< ׎·›•éšë¿‰ØêïÂŒï†éˆÓÎ髸•â�Ц¿Ý�÷¡ûô€í„åÙɧøÑŒÖ÷�Þ÷¤“žÊŸé‚Ī‹< è૵ˆ±‹Èøí£ÿ—ðÝ›àýäþ£�©ÜØ¡åÜÊÙ˜å¿Õ帑śꮣ“òâ˜�Ç£„¿ÉÏÕø¿ðÖÈÓ‰’< ·¼ýõÐù˜¯òæ÷–¡Á€¸ÿç›Â΋´Ìû¼’ôƒÕ½ƒãÏÌ’€¸å¼¬•õšÐê¹È‚í¿Ý™îнÇÕŒ´�< ”÷§ÀéÏÎâÔ—ƒøé�§¦¯×úõôó;’®ñâÓÿ䯔À�‹î„Š•ŸŒÏŒÆ�ØóÿÀ¦‹ø³‘à†ÃÂ�¹½< Å”Œ¡™¦�š¡ö”£ýâÐҫ于×ÞÕÙŒŸ²Ä´Š¾¤‹–¡ÁùÖññÕåûÎ…ÑœéŽì¾¯ßä·¨�•ή< ¹ÅïÆÿ�„ºž‰ªêŠ¿Å°Ýñ‹ÙÉŸõžŒÅ�Õ”·¶ý•Ü•µ”< end: completed.
- it isn't readable.
- can not be changed.
- you can protect is to run on other servers and workstations.
More information about this kind of kixtart manipulation at http://kixtart.org/board/Forum2/HTML/000392.html [This message has been edited by MCA (edited 16 June 2000).]
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 1014 anonymous users online.
|
|
|