| | |
Lines are being skipped in the input file.
![]() |
•
•
Join Date: Feb 2005
Posts: 2
Reputation:
Solved Threads: 0
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
Here is what I have for the code:
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 :)
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
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
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:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
'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 :)
![]() |
Similar Threads
- Some help (counting lines from an input file) (C++)
- Help with calculating avrg from input file. (C++)
- Reading a input file (C)
- input from file into class (C++)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: How can I pass values to Crystal 9 “Formulas� and “Selection Formula� with VB6
- Next Thread: Showing quotes from sequential files
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age application basic beginner birth bmp calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver subroutine tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





