Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I'm sorry for my english, but it is not my language, I hope I will be clear.
I would like to have help from you to finish a qbasic program.
I have a list of txt files named with 5 numbers each, for example: 00011.TXT, 12345.TXT, 22222.TXT, 55678.TXT.
I need to read a number from the keyboard and print one of that files.
If I digit 12345 I would have 12345.txt printed on printer (this is not a problem). Instead if I digit 15555, since the file 15555.txt does not exist, I would have printed the file with the nearest lower number, in this case 12345.txt.My idea to do this is to take the input of the number and try to open and print the file with this number, but if the file does not exist the number decreases untill it is the same of the existent file, so it could be printed. It is important to not go lower than zero (00000) and to maintain the 5 digits: even if the number is 123 I need 00123.
I don't know if my explanation was good enough.
I will be very thankful if you can help me.Thanks a lot.

You say that you have files, and they have every time other name.
Try to add character before number.
(for example "A12345.TXT")

CLS
ON ERROR GOTO 5000
INPUT "Enter a number (00000 - 99999) "; numFOR i = num TO 0 STEP -1
a$ = "00000"
b$ = STR$(i)
MID$(a$, LEN(a$) - LEN(b$) + 2, LEN(b$) - 1) = RIGHT$(b$, LEN(b$) - 1)
a$ = a$ + ".TXT"OPEN a$ FOR INPUT AS #1
LPRINT "File = "; a$: LPRINT
DO WHILE NOT EOF(1)
LINE INPUT #1, c$
LPRINT c$
LOOP
LPRINT : LPRINT1 CLOSE #1
NEXT i
END
5000 RESUME 1

Jason, thank you very very much for your help, you are wonderful.
Your program is perfect, you have centered exactly what I wanted to do, but there is also a problem.
If I have 11111.TXT 22222.TXT 33333.TXT and I input the number 34567, the printer prints 33333.TXT and all the smaller number files (22222 and 11111), not only 33333.TXT.
If the input number is more than 5 digits, all the files are printed.
Could you help me once more time please?
I also would like to print on screen a message (INVALID NUMBER) if the number is not 5 digits.Thanks a lot, I am very grateful.
Bye.

CLS
ON ERROR GOTO 5000
INPUT "Enter a number (00000 - 99999) "; numFOR i = num TO 0 STEP -1
a$ = "00000"
b$ = STR$(i)
MID$(a$, LEN(a$) - LEN(b$) + 2, LEN(b$) - 1) = RIGHT$(b$, LEN(b$) - 1)
a$ = a$ + ".TXT"OPEN a$ FOR INPUT AS #1
LPRINT "File = "; a$: LPRINT
DO WHILE NOT EOF(1)
LINE INPUT #1, c$
LPRINT c$
LOOP
LPRINT : GOTO 21 CLOSE #1
NEXT i
2 CLOSE #1: END
5000 RESUME 1

The last version you sent me by mail is PERFECT!
Thank you!!!
CLS
ON ERROR GOTO 5000DO
INPUT "Enter a number (00000 - 99999) "; num
LOOP WHILE num 99999FOR i = num TO 0 STEP -1
a$ = "00000"
b$ = STR$(i)
MID$(a$, LEN(a$) - LEN(b$) + 2, LEN(b$) - 1) = RIGHT$(b$, LEN(b$) - 1)
a$ = a$ + ".TXT"OPEN a$ FOR INPUT AS #1
LPRINT "File = "; a$: LPRINT
DO WHILE NOT EOF(1)
LINE INPUT #1, c$
LPRINT c$
LOOP
LPRINT : GOTO 21 CLOSE #1
NEXT i2 CLOSE #1: END
5000 RESUME 1

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |