I have a project due involving a problem from my textbook. In the text they want a list of all students for a carpool. They want me to get the info from an input file and print only the students from the local city (Huntley). They also want me to start a new screen after 20 students are listed on the screen -or- if the class hour changes. Also, I have to indicate what hour the classes on each page start at (I put this in the top header).
This should be a sequential input from a file. My problem is that it skips every other line when it reads input. I dont think it's performing the City = LocalCity decision correctly either.
This is confusing and I've tried several different methods. Please see if you know what is wrong.
Here is the input file info
Field Positions Type Decimals
Fullname 1-20 Char
City 21-30 Char
Time 31-32 Num 0
Phone 33-42 Num 0
Here is what I have for the code:
'Specify the positions and lengths of data in the input file.
CONST FullNamePos = 1
CONST FullNameLen = 20
CONST CityPos = 21
CONST CityLen = 10
CONST TimePos = 31
CONST TimeLen = 2
CONST PhonePos = 33
CONST PhoneLen = 10
'Declare Variables
DIM MasterSchedule AS STRING
DIM FullName AS STRING
DIM City AS STRING
DIM strTime AS STRING
DIM Time AS SINGLE
DIM OldTime AS SINGLE
DIM Phone AS STRING
DIM LineCount AS SINGLE
DIM LocalCity AS STRING
DIM ReportHead AS STRING
DIM ColumnHead AS STRING
'Set the local carpool city. Always capitalize the first letter of the city name.
LocalCity = "Huntley"
'Define headers
ReportHead = "Hourly Local Student Schedule:"
ColumnHead = "Name Phone Number"
'Start a fresh LineCount
LineCount = 0
'start program
SCREEN 12
CALL Setup(MasterSchedule, FullName, City, strTime, Time, OldTime, Phone, ReportHead, ColumnHead, LocalCity, LineCount)
DO WHILE NOT EOF(1)
CALL ListStudents(MasterSchedule, FullName, City, strTime, Time, OldTime, Phone, LineCount, ReportHead, ColumnHead)
CALL GetInput(MasterSchedule, FullName, City, strTime, Time, OldTime, Phone)
CALL WhatCity(MasterSchedule, FullName, City, strTime, Time, OldTime, Phone, LocalCity)
LOOP
COLOR 9
LOCATE 26, 1
PRINT "End of the data file. All records processed."
'End Program. Done!
END
SUB GetInput (MasterSchedule AS STRING, FullName AS STRING, City AS STRING, strTime AS STRING, Time AS SINGLE, OldTime AS SINGLE, Phone AS STRING)
LINE INPUT #1, MasterSchedule
FullName = MID$(MasterSchedule, FullNamePos, FullNameLen)
City = MID$(MasterSchedule, CityPos, CityLen)
strTime = MID$(MasterSchedule, TimePos, TimeLen)
Time = VAL(strTime)
Phone = MID$(MasterSchedule, PhonePos, PhoneLen)
END SUB
SUB HourPageBreak (FullName AS STRING, City AS STRING, Time AS SINGLE, OldTime AS SINGLE, Phone AS STRING, LineCount AS SINGLE, ReportHead AS STRING, ColumnHead AS STRING)
'Update the comparison hour to match the newest one read
OldTime = Time
CALL PageBreak(FullName, City, Time, OldTime, Phone, LineCount, ReportHead, ColumnHead)
END SUB
SUB ListStudents (MasterSchedule AS STRING, FullName AS STRING, City AS STRING, strTime AS STRING, Time AS SINGLE, OldTime AS SINGLE, Phone AS STRING, LineCount AS SINGLE, ReportHead AS STRING, ColumnHead AS STRING)
IF Time = OldTime THEN
IF LineCount = 20 THEN
CALL PageBreak(FullName, City, Time, OldTime, Phone, LineCount, ReportHead, ColumnHead)
END IF
ELSE
CALL HourPageBreak(FullName, City, Time, OldTime, Phone, LineCount, ReportHead, ColumnHead)
END IF
PRINT FullName; " "; Phone
LineCount = LineCount + 1
END SUB
SUB PageBreak (FullName AS STRING, City AS STRING, Time AS SINGLE, OldTime AS SINGLE, Phone AS STRING, LineCount AS SINGLE, ReportHead AS STRING, ColumnHead AS STRING)
PRINT "Press ENTER to list more."
wait$ = INPUT$(1)
CLS
COLOR 11
'print the title and column headings. Include the class hour with the title!
PRINT ReportHead; " Displaying Students who Start at"; Time; "o'clock"
COLOR 14
'print the title and column headings. Include the class hour with the title!
PRINT ColumnHead
COLOR 15
LineCount = 0
END SUB
SUB Setup (MasterSchedule AS STRING, FullName AS STRING, City AS STRING, strTime AS STRING, Time AS SINGLE, OldTime AS SINGLE, Phone AS STRING, ReportHead AS STRING, ColumnHead AS STRING, LocalCity AS STRING, LineCount AS SINGLE)
OPEN "A:\Project2.dat" FOR INPUT AS #1
CALL GetInput(MasterSchedule, FullName, City, strTime, Time, OldTime, Phone)
CALL WhatCity(MasterSchedule, FullName, City, strTime, Time, OldTime, Phone, LocalCity)
'Update the comparison hour to match the one just read
OldTime = Time
'print the title and column headings. Include the class hour with the title!
COLOR 11
PRINT ReportHead; " Displaying Students who Start at"; Time; "o'clock"
COLOR 14
PRINT ColumnHead
COLOR 15
END SUB
SUB WhatCity (MasterSchedule AS STRING, FullName AS STRING, City AS STRING, strTime AS STRING, Time AS SINGLE, OldTime AS SINGLE, Phone AS STRING, LocalCity AS STRING)
IF City = LocalCity THEN
'Do nothing
ELSE
CALL GetInput(MasterSchedule, FullName, City, strTime, Time, OldTime, Phone)
END IF
END SUB
I will attach the input file given to me by the instructor. The filename should be Project2.dat but I had to add .txt for the forum to accept it.
Thanks :)