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.