=====
20 DATETIME$="Current date and time:
"+MID$(DATE$,4,3)+LEFT$(DATE$,3)+RIGHT$(DATE$,4)+" at "+TIME$+" uur."
30 OPEN "A",#1,"C:\BATCH\CIGARETS.LOG"
40 PRINT#1,DATETIME$:CLOSE:END
50 REM
60 REM Running this programm results in a "Bad file number in 30" error.
70 REM The programm just has to write a extra line, with the current date
and time, at the bottom of the file.
=====
I try to run this with GWBASIC (the only language I know a little).
Line 20 is to convert from American notation to European (e.g. Dutch)
date-notation.
The file "C\BATCH\CIGARETS.LOG" exists already.
--
Does somebody knows a solution ?
Thank you
It works okay here. I pasted your code into GWBASIC and edited the OPEN line
to remove the path because I don't have that path here. When I ran the
program it created the file in the current directory, then ended as normal.
No errors.
--Ethan
I created the folder "batch" and ran it in gwbasic and it worked fine. It
creates the file "CIGARETS.LOG" in the "BATCH" folder with the following
text.
Current date and time: 07-06-2009 at 21:32:13 uur.
Subsiquent runs appends similar lines below it as intended.
Note, it is recommended to store date/time in a variable and then parse the
stored variable. Also, code is easier to read if you avoid jumbling a lot
into single lines.
10 d$ = DATE$
20 DATETIME$ = "Current date and time: "
21 DATETIME$ = DATETIME$ + MID$(d$, 4, 3) + LEFT$(d$, 3) + RIGHT$(d$, 4)
22 DATETIME$ = DATETIME$ + " at " + TIME$ + " uur."
30 OPEN "A", #1, "E:\BATCH\CIGARETS.LOG"
40 PRINT #1, DATETIME$
50 CLOSE
60 END
--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
> Hoi folks,
> a yell of despair from the Netherlands:
>
> 60 REM Running this programm results in a "Bad file number in 30"
> error.
Thanx for the quick reaction to you all.
The problem was NOT the single backslash.
I shortened the (duch) filename from 9.3 chars to 8.3 chars.
and put the file in the same directory as my GWBasic programm.
And IT WORKS.
--
Again: many thanx.
Jan Hendrik wamelink
Please, be aware that, depending on the times that you will be appending
information to this file, it could grow so much until it cannot store more
information. I don't know if you need to preserve all the dates created
there, but if you only need to store one, you can use "O" instead "A" to
avoid that this file grows so much.
If you insist, for any reason, to use "A", then you may need to create a
maintenance code to reduce your file size in a timely basis. The following
code will help you to do such thing:
10 GOTO 30
20 SAVE "MAINTAIN", A: END ' RUN 20 and it's saved. :)
30 ' Program to maintain my file "CIGARETS.LOG"
40 ' VAR
50 COUNT%=0:DUMMY$="":I%=0:HOWMANY%=0:SIZ!=0
60 :
70 CLS
80 PRINT "Program to maintain my file CIGARETS.LOG" : PRINT
90 ' Count the current records in the existing file
100 ' if file doesn't exists, then it exits.
110 ON ERROR GOTO 130
120 OPEN "C:\BATCH\CIGARETS.LOG" FOR INPUT AS #1
130 IF ERR<>0 THEN PRINT "No maintenance needed. File not found.": RESUME
640 ' Done
140 ON ERROR GOTO 0
150 CLS
160 PRINT
170 PRINT "Counting. Please, wait a moment";
180 COLOR 23
190 PRINT "..."
200 COLOR 7
210 WHILE NOT EOF(1)
220 LINE INPUT #1, DUMMY$
230 COUNT% = COUNT% + 1
240 WEND
250 SIZ! = LOF(1)
260 CLOSE #1
270 :
280 ' Asks how many records have to be left in the file
290 ' those will be the last ones.
300 CLS
310 PRINT "Currently are" + STR$(COUNT%) + " records and file size is" +
STR$(SIZ!)+ " bytes."
320 INPUT "How many of the last records will remain in file"; HOWMANY%
330 :
340 ' Evaluates: If HOWMANY% is => COUNT%, then nothing is done,
350 ' if HOWMANY% <= 0, then records are fully removed after a
confirmation,
360 ' if HOWMANY% < COUNT% then only last HOWMANY% records will remain.
370 IF HOWMANY% => COUNT% THEN PRINT "No maintenance needed.": GOTO 640 '
Done
380 IF HOWMANY% >0 THEN 430 ' Main program
390 INPUT "Are you sure that you want to delete all records (Y/N)";DUMMY$
400 IF UCASE$(DUMMY$)="Y" THEN OPEN "C:\BATCH\CIGARETS.LOG" FOR OUTPUT AS
#1: CLOSE #1
410 GOTO 640 ' Done
420 :
430 ' Main program: It will count the records until reach the number desired
440 PRINT
450 PRINT "Working. Please wait";
460 COLOR 23
470 PRINT "..."
480 COLOR 7
490 OPEN "C:\BATCH\CIGARETS.LOG" FOR INPUT AS #1
500 OPEN "C:\BATCH\CIGARETS.DUM" FOR OUTPUT AS #2
510 WHILE NOT EOF(1)
520 LINE INPUT #1, DUMMY$
530 I% = I% + 1
540 IF (COUNT% - I%) < HOWMANY% THEN PRINT #2, DUMMY$
550 WEND
560 CLOSE #1, #2
570 :
580 ' Gets rid of the original file
590 KILL "C:\BATCH\CIGARETS.LOG"
600 ' Renames the file as the original file
610 CLS
620 PRINT "The last"+STR$(HOWMANY%)+" records have been left in the file
successfully."
630 NAME "C:\BATCH\CIGARETS.DUM" AS "C:\BATCH\CIGARETS.LOG"
640 ' Program End
650 PRINT
660 PRINT "Done."
670 END
Hope this helps.
--
From the guts of progralogics and mechatronics
Tron.BAS