Lines are being skipped in the input file.

Reply

Join Date: Feb 2005
Posts: 2
Reputation: echelon is an unknown quantity at this point 
Solved Threads: 0
echelon echelon is offline Offline
Newbie Poster

Lines are being skipped in the input file.

 
0
  #1
Feb 20th, 2005
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
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Field Positions Type Decimals
  2. Fullname 1-20 Char
  3. City 21-30 Char
  4. Time 31-32 Num 0
  5. Phone 33-42 Num 0

Here is what I have for the code:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. 'Specify the positions and lengths of data in the input file.
  2. CONST FullNamePos = 1
  3. CONST FullNameLen = 20
  4. CONST CityPos = 21
  5. CONST CityLen = 10
  6. CONST TimePos = 31
  7. CONST TimeLen = 2
  8. CONST PhonePos = 33
  9. CONST PhoneLen = 10
  10.  
  11. 'Declare Variables
  12. DIM MasterSchedule AS STRING
  13. DIM FullName AS STRING
  14. DIM City AS STRING
  15. DIM strTime AS STRING
  16. DIM Time AS SINGLE
  17. DIM OldTime AS SINGLE
  18. DIM Phone AS STRING
  19. DIM LineCount AS SINGLE
  20. DIM LocalCity AS STRING
  21. DIM ReportHead AS STRING
  22. DIM ColumnHead AS STRING
  23.  
  24. 'Set the local carpool city. Always capitalize the first letter of the city name.
  25. LocalCity = "Huntley"
  26.  
  27. 'Define headers
  28. ReportHead = "Hourly Local Student Schedule:"
  29. ColumnHead = "Name Phone Number"
  30.  
  31.  
  32. 'Start a fresh LineCount
  33. LineCount = 0
  34.  
  35. 'start program
  36. SCREEN 12
  37. CALL Setup(MasterSchedule, FullName, City, strTime, Time, OldTime, Phone, ReportHead, ColumnHead, LocalCity, LineCount)
  38. DO WHILE NOT EOF(1)
  39. CALL ListStudents(MasterSchedule, FullName, City, strTime, Time, OldTime, Phone, LineCount, ReportHead, ColumnHead)
  40. CALL GetInput(MasterSchedule, FullName, City, strTime, Time, OldTime, Phone)
  41. CALL WhatCity(MasterSchedule, FullName, City, strTime, Time, OldTime, Phone, LocalCity)
  42. LOOP
  43. COLOR 9
  44. LOCATE 26, 1
  45. PRINT "End of the data file. All records processed."
  46. 'End Program. Done!
  47. END
  48.  
  49. SUB GetInput (MasterSchedule AS STRING, FullName AS STRING, City AS STRING, strTime AS STRING, Time AS SINGLE, OldTime AS SINGLE, Phone AS STRING)
  50. LINE INPUT #1, MasterSchedule
  51. FullName = MID$(MasterSchedule, FullNamePos, FullNameLen)
  52. City = MID$(MasterSchedule, CityPos, CityLen)
  53. strTime = MID$(MasterSchedule, TimePos, TimeLen)
  54. Time = VAL(strTime)
  55. Phone = MID$(MasterSchedule, PhonePos, PhoneLen)
  56. END SUB
  57.  
  58. 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)
  59. 'Update the comparison hour to match the newest one read
  60. OldTime = Time
  61. CALL PageBreak(FullName, City, Time, OldTime, Phone, LineCount, ReportHead, ColumnHead)
  62. END SUB
  63.  
  64. 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)
  65. IF Time = OldTime THEN
  66. IF LineCount = 20 THEN
  67. CALL PageBreak(FullName, City, Time, OldTime, Phone, LineCount, ReportHead, ColumnHead)
  68. END IF
  69. ELSE
  70. CALL HourPageBreak(FullName, City, Time, OldTime, Phone, LineCount, ReportHead, ColumnHead)
  71. END IF
  72. PRINT FullName; " "; Phone
  73. LineCount = LineCount + 1
  74. END SUB
  75.  
  76. 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)
  77. PRINT "Press ENTER to list more."
  78. wait$ = INPUT$(1)
  79. CLS
  80. COLOR 11
  81. 'print the title and column headings. Include the class hour with the title!
  82. PRINT ReportHead; " Displaying Students who Start at"; Time; "o'clock"
  83. COLOR 14
  84. 'print the title and column headings. Include the class hour with the title!
  85. PRINT ColumnHead
  86. COLOR 15
  87. LineCount = 0
  88. END SUB
  89.  
  90. 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)
  91. OPEN "A:\Project2.dat" FOR INPUT AS #1
  92. CALL GetInput(MasterSchedule, FullName, City, strTime, Time, OldTime, Phone)
  93. CALL WhatCity(MasterSchedule, FullName, City, strTime, Time, OldTime, Phone, LocalCity)
  94. 'Update the comparison hour to match the one just read
  95. OldTime = Time
  96. 'print the title and column headings. Include the class hour with the title!
  97. COLOR 11
  98. PRINT ReportHead; " Displaying Students who Start at"; Time; "o'clock"
  99. COLOR 14
  100. PRINT ColumnHead
  101. COLOR 15
  102. END SUB
  103.  
  104. 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)
  105. IF City = LocalCity THEN
  106. 'Do nothing
  107. ELSE
  108. CALL GetInput(MasterSchedule, FullName, City, strTime, Time, OldTime, Phone)
  109. END IF
  110. 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 :)
Attached Files
File Type: txt project2.dat.txt (2.7 KB, 4 views)
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 2
Reputation: echelon is an unknown quantity at this point 
Solved Threads: 0
echelon echelon is offline Offline
Newbie Poster

Re: Lines are being skipped in the input file.

 
0
  #2
Feb 20th, 2005
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC