Computing.Net > Forums > Programming > Qbasic program

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Qbasic program

Reply to Message Icon

Name: DMJ
Date: October 4, 2002 at 07:54:15 Pacific
OS: Windows 98
CPU/Ram: AMD Athlon 1000 / 320Mb
Comment:

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.



Sponsored Link
Ads by Google

Response Number 1
Name: Mat
Date: October 4, 2002 at 14:47:32 Pacific
Reply:

You say that you have files, and they have every time other name.

Try to add character before number.
(for example "A12345.TXT")


0

Response Number 2
Name: Jason
Date: October 4, 2002 at 16:14:42 Pacific
Reply:

CLS
ON ERROR GOTO 5000
INPUT "Enter a number (00000 - 99999) "; num

FOR 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 : LPRINT

1 CLOSE #1

NEXT i
END
5000 RESUME 1


0

Response Number 3
Name: DMJ
Date: October 7, 2002 at 02:29:10 Pacific
Reply:

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.



0

Response Number 4
Name: Jason
Date: October 7, 2002 at 06:23:50 Pacific
Reply:

CLS
ON ERROR GOTO 5000
INPUT "Enter a number (00000 - 99999) "; num

FOR 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 2

1 CLOSE #1

NEXT i
2 CLOSE #1: END
5000 RESUME 1


0

Response Number 5
Name: DMJ
Date: October 7, 2002 at 08:38:05 Pacific
Reply:

The last version you sent me by mail is PERFECT!
Thank you!!!


CLS
ON ERROR GOTO 5000

DO
INPUT "Enter a number (00000 - 99999) "; num
LOOP WHILE num 99999

FOR 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 2

1 CLOSE #1
NEXT i

2 CLOSE #1: END
5000 RESUME 1



0

Related Posts

See More



Response Number 6
Name: Aguti Beatrice
Date: November 18, 2002 at 00:32:36 Pacific
Reply:

I want an example of a Q@basic program and how it can be implemented and compiled.


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Qbasic program

qbasic programming question www.computing.net/answers/programming/qbasic-programming-question/7591.html

qbasic zip log files program help www.computing.net/answers/programming/qbasic-zip-log-files-program-help/12511.html

Qbasic programming www.computing.net/answers/programming/qbasic-programming/6255.html