Page 1 of 1
help with college stats program
Posted: Tue Jun 28, 2005 3:22 pm
by ludacris
I have to create a program that retrieves information from a data file.
Ex. of questions that have to be answered:
How many colleges/universities are in NC?
what school has the most faculty members (all ranks)?
The data file has information on division I II and III colleges in the U.S. and is saved in a txt file.
The character positions of the data found within this file has been organized in the following manner:
1-5 FICE (Federal ID number)
7-37 College name
38-39- State (postal code)
40-43 Type (I, IIA, or IIB)
I need help trying to figure out how to at least start this program, so that when a question is asked the info is read from the file. My code so far looks like this
CLS
FILE$ = "A:\college.txt"
OPEN FILE$ FOR INPUT AS #1
PRINT "Search our database for information on colleges"
DO WHILE NOT EOF(1)
INPUT #1, FICE, COLLEGE$, STATE$
IF STATE$ = "NC" THEN
LET s = s + 1
END IF
PRINT s
Please help
What you need is random access files.
Posted: Tue Jun 28, 2005 7:16 pm
by Y-12
The best solution for you problem is random access files. You should read some good tutorial on random access files.
Here is a code that might help. This is for reading data:
CLS
TYPE URec
FICE AS SINGLE
COLLEGE AS STRING * 90
STATE AS STRING * 50
END TYPE
DIM orec AS URec
INPUT "Number of record>", rec%
OPEN "college.txt" FOR RANDOM AS #1 LEN = 145
GET #1, rec, orec
PRINT "FICE: "; orec.FICE
PRINT "COLLEGE: "; orec.COLLEGE
PRINT "STATE: "; orec.STATE
CLOSE #1
And this is for inputting data:
CLS
TYPE URec
FICE AS SINGLE
COLLEGE AS STRING * 90
STATE AS STRING * 50
END TYPE
DIM orec AS URec
FILE$ = "college.txt"
OPEN FILE$ FOR RANDOM AS #1 LEN = 145
INPUT "FICE>", orec.FICE
LINE INPUT "College>", orec.COLLEGE
LINE INPUT "State>", orec.STATE
PUT #1, , orec
CLOSE #1
I don't think this code answers your question exactly, but when you learn how to use random access files, you will be able to modify it.
?Y12
Posted: Tue Jun 28, 2005 8:09 pm
by ludacris
thanks, y-12 all info is useful!!
Posted: Tue Jun 28, 2005 8:19 pm
by MystikShadows
Hi ludacris,
You might be interested in reading my Random Access File Tutorial I wrote for the QB express Magazine #6 ...
http://www.petesqbsite.com/sections/exp ... ccessfiles
There's this issue of a grey rectangle hiding everything in firefox, I suggest you open it in Internet Explorer

.
or go to my website
http://www.ascii-world.com and click on intermediate techniques (menu on the left) and you'll see it there too, and the forumatting there doesn't cause this hiding grey area

...choice is yours

.
Hope this helps
Re: help with college stats program
Posted: Wed Jun 29, 2005 12:57 am
by guest
you forgot TYPE (I, IIA or IIB) in your input#1 line
that could cause some errors...
1-5 FICE (Federal ID number)
7-37 College name
38-39- State (postal code)
40-43 Type (I, IIA, or IIB)
CLS
FILE$ = "A:\college.txt"
OPEN FILE$ FOR INPUT AS #1
PRINT "Search our database for information on colleges"
DO WHILE NOT EOF(1)
INPUT #1, FICE, COLLEGE$, STATE$
IF STATE$ = "NC" THEN
LET s = s + 1
END IF
PRINT s
Please help[/quote]
Posted: Wed Jun 29, 2005 9:07 am
by {Nathan}
I am suprised this didn't turn into a flamewar about homework... even though I guess he did try... sorta...
Posted: Wed Jun 29, 2005 12:10 pm
by Y-12
People who really want to learn QBasic wouldn't use someone's code. They would try to some how understand it. I thought I should post the code because the OP started. I wouldn't post if he just said: "Make a database program for a college."
?Y-12
Posted: Wed Jun 29, 2005 5:28 pm
by ludacris
Nathan, Grow UP!
Posted: Thu Jun 30, 2005 12:04 am
by sid6.7
Y-12 wrote:People who really want to learn QBasic wouldn't use someone's code. They would try to some how understand it. I thought I should post the code because the OP started. I wouldn't post if he just said: "Make a database program for a college."
?Y-12
well said...
Posted: Sat Jul 02, 2005 3:31 pm
by {Nathan}
Hey... my post got deleted... oh... no... my internet connection shut down... so Ill post it again.
I won't grow up because I am only 12. I enjoy NOT growing up while I still can.