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 :)

Attachments
Don't Print Me      Tucson    065205552212
How Bout Me         Huntley   075205551112
Izzy Fureal         Huntley   085205551212
Sammy Wong          Huntley   085205557677
Mike R. Fone        Huntley   085205557233
Amy Day             Huntley   085205557662
Sara Li             Huntley   085205557677
Wendy Day           Huntley   085205557662
Ono Delish          Tucson    085205556178
Yvonne Zychjesy     Huntley   085205551238
Prince Albert       Huntley   085205556261
TAFKA Prince Albert Huntley   085205556261
Buffy Summers       Huntley   085205556261
Willow Rosenberg    Huntley   085205556261
Itchy               Huntley   085205557263
Scratchy            Huntley   085205557263
Homer               Huntley   085205559999
Marge               Huntley   085205559999
J. J. J. Smith      Tucson    085205556178
Bart                Huntley   085205559999
Lisa                Huntley   085205559999
Maggie              Huntley   085205559999
Santa's Li'l Helper Huntley   085205559999
Snowball II         Huntley   085205559999
Ned Flanders        Huntley   085205558888
Maude Flanders      Huntley   085205558888
Milhaus             Huntley   085205558787
Nelson Munz         Huntley   085205557272
Tommy Who           Tucson    085205556178
Dr.  Who            Tucson    085205556178
Dolpf               Huntley   085205552622
Kearny              Huntley   085205552422
Jimbo Jones         Huntley   085205552223
Seymour Skinner     Huntley   085205558787
Edna Krabapple      Huntley   085205557272
Bleeding Gums MurphyHuntley   085205552622
Ralph Wiggum        Huntley   085205552422
Cheif Wiggum        Huntley   085205552223
Professor Frink     Huntley   085205552223
Lenny               Huntley   085205558787
Carl                Huntley   085205557272
C. Montgomery Burns Huntley   085205552622
Waylen Smithers     Huntley   085205552422
Karl                Huntley   085205552223
Mindy Simmons       Huntley   085205552422
Art T. Choke        Tucson    085205556178
Reverend Lovejoy    Huntley   085205552223
Mrs. Lovejoy        Huntley   085205552223
Mr. Androids DungeonHuntley   085205558787
Miss Hoover         Huntley   085205557272
Apu NahaspimapetulonHuntley   085205552622
Moe Syzlak          Huntley   085205552422
Groundskeeper Willy Huntley   085205552223
Muddy Waters        Huntley   095205552422
B.B. King           Huntley   095205552662
Lightnin' Hopkins   Huntley   095205552422
Blind Lemon JefersonHuntley   095205552662
Tom Robbins         Huntley   105205552462
Thomas Pynchon      Huntley   105205552232
Robert Heinlein     Huntley   105205552112
Aleister Crowley    Huntley   105205552992
Willow Braungch     Tucson    185205556178
R. We Don Yet       Huntley   235205551982

Nevermind. I solved it. For those who are looking for an answer to a similar problem and also havn't been answered:

There should be a loop after the decision produces "false" to be certain that the next student to be listed is also a local student.

This article has been dead for over six months. Start a new discussion instead.