Page 1 of 1 1
Topic Options
#3216 - 2000-05-31 03:33 PM Counter Script
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 Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
try this...

$Que = 1+$QUe

_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#3218 - 2000-06-01 01:54 PM Re: Counter Script
Anonymous
Unregistered


Gives me this:
-------------------------------12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514 614714814915015115215315412345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714 814915015115215315412345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915 015115215315412345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115 2153154
------------------------------------
DOH!

------------------
THANKS
MARK =)

Top
#3219 - 2000-06-01 03:17 PM Re: Counter Script
BoxKite Offline
Da Box
*****

Registered: 2000-05-17
Posts: 282
Loc: Vacaville,CA,USA
Try this;

code:
$n = 1
while $n < 156
select
case len("$n") = 1
$a = "apps00"
case len("$n") = 2
$a = "apps0"
case len("$n") = 3
$a = "apps"
endselect
$x = "$a" + "$n"
shell "%comspec% /c echo $x >> file.txt"
$n = 1 + $n
loop

or this;


code:
? "Enter a number less than 155: " gets $n
$n = val("$n")
while $n < 156
select
case len("$n") = 1
$a = "apps00"
case len("$n") = 2
$a = "apps0"
case len("$n") = 3
$a = "apps"
endselect
$x = "$a" + "$n"
shell "%comspec% /c echo $x >> file.txt"
$n = 1 + $n
loop
exit

------------------
BoxKite
FACTA NON VERBA

_________________________
Box
FACTA NON VERBA

Top
#3220 - 2000-06-01 03:19 PM Re: Counter Script
BoxKite Offline
Da Box
*****

Registered: 2000-05-17
Posts: 282
Loc: Vacaville,CA,USA
oops!

Forgot the exit in the top example

------------------
BoxKite
FACTA NON VERBA

_________________________
Box
FACTA NON VERBA

Top
#3221 - 2000-06-07 04:19 PM Re: Counter Script
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
you need to use the val() command, otherwise kix will treat $QUe like a string and not an integer.

code:

?" ENTER THE QUE IE. AMAPPP"
?""
GETS $QUe
$QUe = val("$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
endif

:END
EXIT


Bryce (glad to have the BB back! and not gald that my vacation is over )

Top
#3222 - 2000-06-15 06:16 PM Re: Counter Script
MCA Offline
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.

_________________________
email scripting@wanadoo.nl homepage scripting@wanadoo.nl | Links | Summary of Site Site KiXforms FAQ kixtart.org library collection mirror MCA | FAQ & UDF help file UDF kixtart.org library collection mirror MCA | mirror USA | mirror europe UDF scriptlogic library collection UDFs | mirror MCA

Top
#3223 - 2000-06-16 02:00 AM Re: Counter Script
BoxKite Offline
Da Box
*****

Registered: 2000-05-17
Posts: 282
Loc: Vacaville,CA,USA
WOW! And I though Mark just wanted a simple counter script.
_________________________
Box
FACTA NON VERBA

Top
#3224 - 2000-06-16 11:19 PM Re: Counter Script
MCA Offline
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).]

_________________________
email scripting@wanadoo.nl homepage scripting@wanadoo.nl | Links | Summary of Site Site KiXforms FAQ kixtart.org library collection mirror MCA | FAQ & UDF help file UDF kixtart.org library collection mirror MCA | mirror USA | mirror europe UDF scriptlogic library collection UDFs | mirror MCA

Top
#3225 - 2000-06-16 11:23 PM Re: Counter Script
MCA Offline
KiX Supporter
*****

Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
-

[This message has been edited by MCA (edited 16 June 2000).]

_________________________
email scripting@wanadoo.nl homepage scripting@wanadoo.nl | Links | Summary of Site Site KiXforms FAQ kixtart.org library collection mirror MCA | FAQ & UDF help file UDF kixtart.org library collection mirror MCA | mirror USA | mirror europe UDF scriptlogic library collection UDFs | mirror MCA

Top
#3226 - 2000-06-16 11:24 PM Re: Counter Script
MCA Offline
KiX Supporter
*****

Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
-

[This message has been edited by MCA (edited 16 June 2000).]

_________________________
email scripting@wanadoo.nl homepage scripting@wanadoo.nl | Links | Summary of Site Site KiXforms FAQ kixtart.org library collection mirror MCA | FAQ & UDF help file UDF kixtart.org library collection mirror MCA | mirror USA | mirror europe UDF scriptlogic library collection UDFs | mirror MCA

Top
#3227 - 2000-06-23 07:41 PM Re: Counter Script
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
The only unanswered question now is :

Mark, are You Happy ???

_________________________



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
1 registered (mole) and 1441 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

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

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