Page 1 of 1
open and input help
Posted: Tue Nov 22, 2005 2:01 pm
by JTShadow
I'm trying to make a program that opens up a file and reads a name, followed by a number, then followed by a dollar amount but I'm having trouble setting this up, any ideas? Basically i'm trying to run a check off the number and anything that is greater than the number is going to be printed out.
Posted: Tue Nov 22, 2005 2:21 pm
by Z!re
1) Listen to your teacher
2) Read the textbook (if any)
3) Look in the QB help index
4) Attempt to write the program yourself
5) Go to a forum and ask for help when you're too lazy and wish to work at McDonalds sweeping floors for the rest of your life.
6) Show what you've written so far, and ask people to help you correct it
Now, the correct order to follow is:
1, 2, 3, 4, 6
The wrong order is any which include step 5..
So.. are you lazy, or were you just misstaken and you can infact handle this yourself?
Posted: Tue Nov 22, 2005 2:30 pm
by Guest
1. Teacher doesn't really teach, he walks in the room, tells us what to do, then leaves.
2. No textbook, the course requires VB.NET but the teacher prefers QBASIC and its an intro to computers class.
3. Tried the help file, but the program didn't work.
4. Tried writting it and...
6. This is what I got....
CNT%=0, ACCUM%=0
OPEN "F:/TEST.TXT" FOR INPUT AS 1
DO UNTIL EOF(1)
READ NAM$, SSN$, WAGE!
IF SSN$ > 599999999 THEN
ACCUM%=ACCUM%+WAGE!
END IF
WEND
CLOSE #1
CLS: TOTAL WAGES: ACCUM%
END
Sadly this is due tomorrow, as I have to leave the school earlier in the semester to move across country due to my wifes military orders. I really do appreciate any help, and I'm not lazy about it, just lost.
Re: open and input help
Posted: Tue Nov 22, 2005 3:50 pm
by moneo (login problems)
JTShadow wrote:I'm trying to make a program that opens up a file and reads a name, followed by a number, then followed by a dollar amount but I'm having trouble setting this up, any ideas? Basically i'm trying to run a check off the number and anything that is greater than the number is going to be printed out.
The most important information you need is the format of the the file.
The record, or each record if more than one, consists of 3 fields: name, SSN number, and dollar amount. What is the format, or how do these 3 fields appear in the record? Are the 3 fields fixed length? Otherwise, what is the delimeter used to separate one field from the other?
You need to know exactly how the 3 data fields appear on the record in order to properly be able to read the 3 fields in.
Here's some comments/suggestions on your code:
1) Define your variables at the top of the program. This way you don't need to be putting the % or the ! in the variable name every time you use it. Example:
dim ACCUM as integer
dim WAGE as single
2) Your OPEN statement needs to end with "AS #1".
3) A "DO UNTIL" is terminiated by a "LOOP" not by a "WEND".
4) A "READ" statement is for reading values from a DATA statement. Your want to read form the file opened as #1, so replace the READ with INPUT #1 ....
5) If the SSN is a string, then you need to compare it to a string value of "599999999".
6) If WAGE is a single precision number, and can have decimals, then you cant mix variable types in the arithmetic when you add. Define ACCUM as single, just like WAGE, and then:
ACCUM=ACCUM+WAGE
7) At the end, I think you wanted:
CLS
PRINT "TOTAL WAGES "; ACCUM

If you're finished, you don't need to CLOSE the file. It will be closed when the program terminates.
If you don't agree with any of my comments, let's talk about it.
*****
Posted: Tue Nov 22, 2005 7:04 pm
by moneo
What's going on?
I made the above post while I was signed on, and it now shows as GUEST.
*****
Posted: Tue Nov 22, 2005 10:08 pm
by Z!re
Cookie problems moneo?
I've had some problems staying online too lately.. might have something to do with Pete upgrading the forum, try removing all cookies then log back on..
EDIT: I'm trying to fix up the topic though, removing a few posts..
I'll save them if I remove the wrong ones by misstake.
If anything's missing moneo, let me know
Posted: Wed Nov 23, 2005 1:09 am
by JTShadow
The records are fixed length, the name is 15 characters big. well it looks kinda like this....
"JOHN DOE ","123456789",4256.91
followed by 9 other entries going down the list for a total of 10.
So now the code is looking like....
ACCUM!=0
OPEN "G:/TEST.TXT" FOR INPUT AS #1
CLS
PRINT TAB(10); "Selected Employees (SSN > 599999999)"
Print "Name",,"SSN"," Wage"
Print "----",,"---"," ----"
DO UNTIL EOF(1)
INPUT #1, NAM$, SSN$, WAGE!
IF SSN$ > "599999999" THEN
ACCUM!=ACCUM!+WAGE!
PRINT NAM$, SSN$, WAGE!
END IF
LOOP
PRINT "TOTAL WAGES: ";,,, ACCUM!
CLOSE #1
END
I really do appreciate all the help. It would be nice too if i could change the ssn from the "123456789" format to the "123-45-6789" format, but i have no idea where to start with that... Also, I noticed that the wage fields don't line up right with the decimals places, is there a way to fix that?
Posted: Wed Nov 23, 2005 3:36 pm
by Guest
By the way, the records are NOT fixed length since NAM$ and WAGE! can vary in length.
To format the SSN$, you could use a PRINT USING, but another simple way is is to break it up into 3 fields separated by a dash. See below.
To format the WAGE!, you need to use PRINT USING. I'll set it up for a max wage of 999,999. See below.
The NAM$ probably varies in length, so I'll set it for a maximum of 30 characters. See below.
Replace "PRINT NAM$, SSN$, WAGE!" with the following:
PRINT LEFT$(NAM$+SPACE$(30),30);
PRINT SPACE$(2);
PRINT LEFT$(SSN$,3)+"-"+MID$(SSN$,4,2)+"-"+MID$(SSN$,6);
PRINT SPACE$(2);
PRINT USING "###,###.##";WAGE!
Do the first test, and then align your heading to coincide with the new format of the printed data fields.
*****
Posted: Wed Nov 23, 2005 3:39 pm
by moneo
Log in problems again. Above Guest post is by me (Moneo).
*****
Posted: Wed Nov 23, 2005 3:57 pm
by Zam(login problems too!)
I love it, somebody comes and asks a question and everybody automaticaly knows that its for homework. (hehe)
Posted: Wed Nov 23, 2005 8:00 pm
by moneo
Z!re wrote:Cookie problems moneo?
I've had some problems staying online too lately.. might have something to do with Pete upgrading the forum, try removing all cookies then log back on..
EDIT: I'm trying to fix up the topic though, removing a few posts..
I'll save them if I remove the wrong ones by misstake.
If anything's missing moneo, let me know
Z!re, thanks for you continued help plus cleaning up the posts.
I log in every single time, so the problem should not be related to cookies.
*****