By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,098 Members | 1,405 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,098 IT Pros & Developers. It's quick & easy.

ExamResults Read Program

P: 2
I am an A-level IT student and i am trying to make a program that read results from a .txt file, displays the name, subject, mark and grade. The grade is supposed to be interpreted from the mark given in the .txt file. heres what ive got so far:

Expand|Select|Wrap|Line Numbers
  1. Sub main()
  2.  
  3.     Dim Name As String
  4.     Dim Name1 As String
  5.     Dim Mark As String
  6.     Dim Grade As String
  7.     Dim Count As Integer
  8.  
  9.     Open "J:\Applied IT\Re-Sit Units\Programming\K&N\Project\Read, Exam Results\Results\Results.txt" For Input As #1
  10.  
  11.     Name = InputBox("Enter Name")
  12.  
  13.     Count = 1
  14.     Grade = X
  15.     Mark = 99
  16.  
  17.     If Name = Name1 Then
  18.  
  19.     While Mark <> 0
  20.         Input #1, Name1, Subject, Mark, Grade
  21.         Count = Count + 1
  22.  
  23.         If Mark <= 40 Then
  24.             Grade = "FAIL"
  25.         End If
  26.  
  27.         If Mark >= 40 And Mark <= 45 Then
  28.             Grade = "E"
  29.         End If
  30.  
  31.         If Mark >= 45 And Mark <= 50 Then
  32.             Grade = "D"
  33.         End If
  34.  
  35.         If Mark >= 50 And Mark <= 60 Then
  36.             Grade = "C"
  37.         End If
  38.  
  39.         If Mark >= 60 And Mark <= 70 Then
  40.             Grade = "B"
  41.         End If
  42.  
  43.         If Mark >= 70 Then
  44.             Grade = "A"
  45.         End If
  46.  
  47.     MsgBox ("This students grade is " + Grade)
  48.         Wend
  49.     End If
  50. Close #1
  51. End Sub
Mar 30 '07 #1
Share this Question
Share on Google+
5 Replies


vijaydiwakar
100+
P: 579
I am an A-level IT student and i am trying to make a program that read results from a .txt file, displays the name, subject, mark and grade. The grade is supposed to be interpreted from the mark given in the .txt file. heres what ive got so far:

Sub main()

Dim Name As String
Dim Name1 As String
Dim Mark As String
Dim Grade As String
Dim Count As Integer

Open "J:\Applied IT\Re-Sit Units\Programming\K&N\Project\Read, Exam Results\Results\Results.txt" For Input As #1

Name = InputBox("Enter Name")

Count = 1
Grade = X
Mark = 99

If Name = Name1 Then

While Mark <> 0
Input #1, Name1, Subject, Mark, Grade
Count = Count + 1

If Mark <= 40 Then
Grade = "FAIL"
End If

If Mark >= 40 And Mark <= 45 Then
Grade = "E"
End If

If Mark >= 45 And Mark <= 50 Then
Grade = "D"
End If

If Mark >= 50 And Mark <= 60 Then
Grade = "C"
End If

If Mark >= 60 And Mark <= 70 Then
Grade = "B"
End If

If Mark >= 70 Then
Grade = "A"
End If

MsgBox ("This students grade is " + Grade)
Wend
End If
Close #1
End Sub
so what's the problem
Mar 30 '07 #2

P: 2
Well, it doesnt work. i was hoping someone could correct it for me.
Mar 30 '07 #3

P: 47
Hi,
Before U Open and Read the file.
you must specify the file format i.e column delimiter.
Suppose I assume "," as a delimiter.
Before U Using My Code. Add Reference: Microsoft Scripting runtime.(if VB.Net then U will Find this From COM )
Assume file format i.e.
Saikat Mitra,History,70





Expand|Select|Wrap|Line Numbers
  1.        Dim filesys As New FileSystemObject
  2.         Dim txtfl As TextStream
  3.         Dim ReadData As String
  4.         Dim Name As String
  5.         Dim Grade As String
  6.         'Check That The File is Already in Specific Path or Not
  7.         If filesys.FileExists("c\ca_advic\output\chklist.txt") = False Then
  8.             MsgBox("File Not Found")
  9.             Exit Sub
  10.         End If
  11.         Name = InputBox("Enter Name")
  12.  
  13.         If Name.Length = 0 Then
  14.             MsgBox("U should give Proper name")
  15.             Exit Sub
  16.         End If
  17.  
  18.         txtfl = filesys.OpenTextFile("c:\ca_advic\output\chklist.txt", IOMode.ForReading)
  19.         txtfl.ReadLine()
  20.         While txtfl.AtEndOfStream <> True
  21.             ReadData = txtfl.ReadLine()
  22.             Dim ReadCol() As String = Split(ReadData, ",", -1, Microsoft.VisualBasic.CompareMethod.Binary)
  23.             If ReadCol(0) = Name Then
  24.                 If ReadCol(2) >= 40 And ReadCol(2) < 45 Then
  25.                     Grade = "E"
  26.                 ElseIf ReadCol(2) >= 45 And ReadCol(2) < 50 Then
  27.                     Grade = "D"
  28.                 ElseIf ReadCol(2) >= 50 And ReadCol(2) < 60 Then
  29.                     Grade = "C"
  30.                 ElseIf ReadCol(2) >= 60 And ReadCol(2) < 70 Then
  31.                     Grade = "B"
  32.                 ElseIf ReadCol(2) >= 70 Then
  33.                     Grade = "A"
  34.                 End If
  35.                 MsgBox("Student " & Name & "  Grade is " & Grade)
  36.                 txtfl.Close()
  37.                 Exit Sub
  38.             End If
  39.         End While
  40.         txtfl.Close()
Mar 31 '07 #4

Expert 5K+
P: 8,434
Well, it doesnt work. i was hoping someone could correct it for me.
Can you give us something more specific than "doesn't work"? That really doesn't tell us much. It could mean anything, from "I don't like the format of the result" to "it blows up the computer and burns my house down".

Also, I feel I should point out the following...

The experts on this site are more than happy to help you with your problems but they cannot do your assignment/program for you. Attempt the assignment/program yourself first and post questions regarding any difficulties you have or about a particular function of the code that you don't know how to achieve.

Please read the Posting Guidelines and particularly the Coursework Posting Guidlines.

Then when you are ready post a new question in this thread.

MODERATOR
Apr 1 '07 #5

Expert 5K+
P: 8,434
I can point out one bug, though probably not a very serious one.

Certain marks are given two different grades. For an example, follow the logic through, statement by statement, and have a look at what would happen with a mark of 45.
Apr 1 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.