473,320 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

ExamResults Read Program

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
5 1569
vijaydiwakar
579 512MB
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
cdove
2
Well, it doesnt work. i was hoping someone could correct it for me.
Mar 30 '07 #3
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
Killer42
8,435 Expert 8TB
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
Killer42
8,435 Expert 8TB
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

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

Similar topics

2
by: Gunnar | last post by:
Hello, I've just written a CPP program that reads integers from a binary file, and used this code while (my_ifstram.read( (char* ) &number, sizeof(int)) { // do something with number } My...
3
by: lpe540 | last post by:
Hi, I'm having trouble using istream to read in a file in its entirety on UNIX. I've written a dummy program that essencially reads in a file from stdin and writes it out to a file. When I cat a...
2
by: hvaisane | last post by:
Valgrind says ==11604== Invalid read of size 4 ==11604== at 0x8048ABB: main (foo.cc:36) ==11604== Address 0x1B92415C is 4 bytes inside a block of size 8 free'd ==11604== at 0x1B90514F:...
4
by: Ollie Cook | last post by:
Hi, I am having some difficulty with read(2) and interrupting signals. I expect I am misunderstanding how the two work together, so would appreciate some guidance. I am trying to 'time out' a...
4
by: kj | last post by:
I consider myself quite proficient in C and a few other programming languages, but I have never succeeded in understanding a largish program (such as zsh or ncurses) at the source level. ...
2
by: Rajen | last post by:
Suppose the field length is 25 characters. After entering the 25th character, it should be available to process. Program should not wait for the user to press enter/return key. Thank you.
0
by: heplesser | last post by:
Summary: Does the C++ standard require std::basic_istream<>::operator>>(double&) to leave the input stream untouched in case of a read failure? Details: I noticed an unexpected behavior of...
5
by: CSharp-Jay | last post by:
So I have been programming in C# on a personal level as of lately, and am curious about something. Lately I have been experimenting around with file create/write, etc. I can open and read the...
1
by: Sachin Garg | last post by:
I have a program which opens a fstream in binary input+output mode, creating the file if it doesn't exists. But writing doesn't works after reading, it must be something obvious that I am not aware...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.