ExamResults Read Program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cdove
    New Member
    • Mar 2007
    • 2

    #1

    ExamResults Read Program

    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:

    Code:
    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
    Last edited by Killer42; Apr 1 '07, 01:46 AM. Reason: Please use [CODE]...[/CODE] tags around your code.
  • vijaydiwakar
    Contributor
    • Feb 2007
    • 579

    #2
    Originally posted by cdove
    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\Programmi ng\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

    Comment

    • cdove
      New Member
      • Mar 2007
      • 2

      #3
      Well, it doesnt work. i was hoping someone could correct it for me.

      Comment

      • SanjuMtr
        New Member
        • Mar 2007
        • 47

        #4
        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,7 0





        Code:
               Dim filesys As New FileSystemObject
                Dim txtfl As TextStream
                Dim ReadData As String
                Dim Name As String
                Dim Grade As String
                'Check That The File is Already in Specific Path or Not
                If filesys.FileExists("c\ca_advic\output\chklist.txt") = False Then
                    MsgBox("File Not Found")
                    Exit Sub
                End If
                Name = InputBox("Enter Name")
        
                If Name.Length = 0 Then
                    MsgBox("U should give Proper name")
                    Exit Sub
                End If
        
                txtfl = filesys.OpenTextFile("c:\ca_advic\output\chklist.txt", IOMode.ForReading)
                txtfl.ReadLine()
                While txtfl.AtEndOfStream <> True
                    ReadData = txtfl.ReadLine()
                    Dim ReadCol() As String = Split(ReadData, ",", -1, Microsoft.VisualBasic.CompareMethod.Binary)
                    If ReadCol(0) = Name Then
                        If ReadCol(2) >= 40 And ReadCol(2) < 45 Then
                            Grade = "E"
                        ElseIf ReadCol(2) >= 45 And ReadCol(2) < 50 Then
                            Grade = "D"
                        ElseIf ReadCol(2) >= 50 And ReadCol(2) < 60 Then
                            Grade = "C"
                        ElseIf ReadCol(2) >= 60 And ReadCol(2) < 70 Then
                            Grade = "B"
                        ElseIf ReadCol(2) >= 70 Then
                            Grade = "A"
                        End If
                        MsgBox("Student " & Name & "  Grade is " & Grade)
                        txtfl.Close()
                        Exit Sub
                    End If
                End While
                txtfl.Close()
        Last edited by Killer42; Apr 1 '07, 01:50 AM. Reason: Please use [CODE]...[/CODE] tags around your code.

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          Originally posted by cdove
          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...

          Originally posted by FAQ
          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

          Comment

          • Killer42
            Recognized Expert Expert
            • Oct 2006
            • 8429

            #6
            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.

            Comment

            Working...