| | |
Making arrays from text files
Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Nov 2006
Posts: 19
Reputation:
Solved Threads: 0
I am having problems trying to create arrays from text files. The text files created from the program I am working on is like this:
Name Test1 Test2 Test3 Avg Grade
===================================
Student 999 999 999 999 X
The first two lines in this are headings that are added into the text file, and I need the student name, the test scores, avg and grade letter as seperate parts of a structure.
This is for a basic programming class, but the instructor hasn't really gotten into details about how to do this at all. What I have to do with this is search for the student name as you would do in a database to find a student's grade, and we are assuming that we do not know how many students there are in the file.
I am assuming that you would like to view the code I have to see where I am coming from. I have been googling arrays and using MSDN Libraries for help. To view the code, it is between the dashes:
---------------------------------------------------------------------------------
OptionExplicitOn
Imports System.Math
Imports System.IO
Imports System.IO.File
PublicClass Form1
Inherits System.Windows.Forms.Form
Structure StudentRec
Dim Name As String
Dim test1, test2, test3 As Double
Dim Avg As Double
End Structure
Dim AStudents() As StudentRec = {}
Friend max As Integer
Friend pointer As Short
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
btnDisplay.Hide() : btnAccept.Hide() : lstDisplay.Hide() : txtName.Hide() : txtScore1.Hide()
txtScore2.Hide() : txtScore3.Hide() : Label6.Hide() : Label2.Hide() : Label3.Hide() : Label4.Hide()
Label5.Hide() : lblStudentCount.Hide() : btnDisplay.Hide() : btnSave.Hide()
btnDisplay.Enabled = False : btnAccept.Enabled = False : lstDisplay.Enabled = False : txtName.Enabled = False
txtScore1.Enabled = False : txtScore2.Enabled = False : txtScore3.Enabled = False : Label6.Enabled = False
Label2.Enabled = False : Label3.Enabled = False : Label4.Enabled = False : Label5.Enabled = False
lblStudentCount.Enabled = False : btnDisplay.Enabled = False : btnSave.Enabled = False
btnDisplay.Enabled = False
btnAccept.Enabled = False
lblStudentCount.Text = 0
lstDisplay.Items.Add("Name Test 1 Test 2 Test 3 Average Grade")
lstDisplay.Items.Add("==============================================================================================")
End Sub
Private Sub txtName_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtName.Leave
If IsNumeric(txtName.Text) = True Then
txtName.Clear()
txtName.Focus()
MsgBox("I think you were trying to put a test score here, please put the student's name instead")
End If
If txtName.Text = "" Then
txtName.Focus()
End If
End Sub
Private Sub txtScore1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtScore1.Leave
If IsNumeric(txtScore1.Text) = False Then
MsgBox("You need to put the score for the first test")
txtScore1.Clear()
txtScore1.Focus()
Else
If CDbl(txtScore1.Text) > 100 Or CDbl(txtScore1.Text) < 0 Then
MsgBox("The test score is not correct")
txtScore1.Clear()
txtScore1.Focus()
End If
End If
End Sub
Private Sub txtScore2_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtScore2.Leave
If IsNumeric(txtScore2.Text) = False Then
MsgBox("You need to put the score for the second test")
txtScore2.Clear()
txtScore2.Focus()
Else
If CDbl(txtScore2.Text) > 100 Or CDbl(txtScore2.Text) < 0 Then
MsgBox("The test score is not correct")
txtScore2.Clear()
txtScore2.Focus()
End If
End If
btnAccept.Enabled = True
End Sub
Private Sub txtScore3_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtScore3.Leave
If IsNumeric(txtScore3.Text) = False Then
MsgBox("You need to put the score for the third test")
txtScore3.Clear()
txtScore3.Focus()
Else
If CDbl(txtScore3.Text) > 100 Or CDbl(txtScore3.Text) < 0 Then
MsgBox("The test score is not correct")
txtScore3.Clear()
txtScore3.Focus()
End If
End If
End Sub
Private Sub btnAccept_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAccept.Click
lstDisplay.Items.Clear()
lstDisplay.Items.Add("Name Test 1 Test 2 Test 3 Average Grade")
lstDisplay.Items.Add("==============================================================================================")
pointer = 1 + UBound(AStudents)
lblStudentCount.Text = pointer + 1
ReDim Preserve AStudents(pointer)
AStudents(pointer).Name = CStr(txtName.Text)
AStudents(pointer).test1 = CDbl(txtScore1.Text)
AStudents(pointer).test2 = CDbl(txtScore2.Text)
AStudents(pointer).test3 = CDbl(txtScore3.Text)
txtName.Clear()
txtScore1.Clear()
txtScore2.Clear()
txtScore3.Clear()
txtName.Focus()
btnAccept.Enabled = False
btnDisplay.Enabled = True
End Sub
Private Sub btnDisplay_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
lstDisplay.Items.Clear()
lstDisplay.Items.Clear()
lstDisplay.Items.Add("Name Test 1 Test 2 Test 3 Average Grade")
lstDisplay.Items.Add("==============================================================================================")
Dim avg, high, mid, low As Double
Dim Letter As String
For max = 0 To UBound(AStudents)
If AStudents(max).test1 > AStudents(max).test2 And AStudents(max).test1 > AStudents(max).test3 Then
high = AStudents(max).test1
If AStudents(max).test2 > AStudents(max).test3 Then
mid = AStudents(max).test2
low = AStudents(max).test3
Else
mid = AStudents(max).test3
low = AStudents(max).test2
End If
ElseIf AStudents(max).test2 > AStudents(max).test3 Then
high = AStudents(max).test2
If AStudents(max).test1 > AStudents(max).test3 Then
mid = AStudents(max).test1
low = AStudents(max).test3
Else
mid = AStudents(max).test3
low = AStudents(max).test1
End If
Else
high = AStudents(max).test3
If AStudents(max).test1 > AStudents(max).test2 Then
mid = AStudents(max).test1
low = AStudents(max).test2
Else
mid = AStudents(max).test2
low = AStudents(max).test1
End If
End If
avg = ((0.4 * high) + (0.35 * mid) + (0.25 * low))
If avg > 90 Then
Letter = "A"
ElseIf avg > 80 Then
Letter = "B"
ElseIf avg > 70 Then
Letter = "C"
ElseIf avg > 60 Then
Letter = "D"
Else
Letter = "F"
End If
lstDisplay.Items.Add(AStudents(max).Name.PadLeft(1) & AStudents(max).test1.ToString.PadLeft(25) & _
AStudents(max).test2.ToString.PadLeft(15) & AStudents(max).test3.ToString.PadLeft(20) & _
avg.ToString.PadLeft(20) & Letter.PadLeft(20))
Next
btnSave.Enabled = True
End Sub
Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
End
End Sub
Private Sub btnNew_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNew.Click
btnDisplay.Show() : btnAccept.Show() : lstDisplay.Show() : txtName.Show() : txtScore1.Show()
txtScore2.Show() : txtScore3.Show() : Label6.Show() : Label2.Show() : Label3.Show() : Label4.Show()
Label5.Show() : lblStudentCount.Show() : btnDisplay.Show() : btnSave.Show()
lstDisplay.Enabled = True : txtName.Enabled = True : txtScore1.Enabled = True
txtScore2.Enabled = True : txtScore3.Enabled = True : Label6.Enabled = True
Label2.Enabled = True : Label3.Enabled = True : Label4.Enabled = True : Label5.Enabled = True
lblStudentCount.Enabled = True : txtName.Focus()
End Sub
Private Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
MsgBox("Saving will overwrite old file", MsgBoxStyle.OkOnly)
Dim writer As StreamWriter
writer = New StreamWriter("Grades.txt")
For max = 0 To lstDisplay.Items.Count - 1
writer.WriteLine(lstDisplay.Items.Item(max))
Next
writer.Close()
End Sub
Private Sub btnOpen_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOpen.Click
lstDocument.Items.Clear()
Dim reader As StreamReader
Try
reader = New StreamReader("Grades.txt")
While reader.EndOfStream = False
lstDocument.Items.Add(reader.ReadLine)
End While
reader.Close()
Catch ex As Exception
MsgBox("File does not exist, please create a new file first")
End Try
End Sub
Structure FindStudent
Dim stuName As String
Dim stuTest1, stuTest2, stuTest3, stuAvg As Double
Dim stuGrade As String
End Structure
Private Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click
Dim stuSearch() As FindStudent = {}
Dim reader As StreamReader = File.OpenText("Grades.txt")
Dim loopcnt As Integer = 0
Dim foundname As String
Dim searchStu As Integer
stuSearch(loopcnt - 1).stuName = reader.ReadLine
Do While stuSearch(loopcnt - 1).stuName = reader.EndOfStream <> False
stuSearch(loopcnt - 1).stuTest1 = reader.ReadLine
stuSearch(loopcnt - 1).stuTest2 = reader.ReadLine
stuSearch(loopcnt - 1).stuTest3 = reader.ReadLine
stuSearch(loopcnt - 1).stuAvg = reader.ReadLine
stuSearch(loopcnt - 1).stuGrade = reader.ReadLine
loopcnt = loopcnt + 1
Loop
foundname = -1
If rdAll.Checked = True And txtNameLookup.Text <> "" Then
For searchStu = 0 To loopcnt
If txtNameLookup.Text = stuSearch(loopcnt).stuName Then
foundname = loopcnt
Exit For
End If
MsgBox("You Entered " & txtNameLookup.Text & " and the person found was " & stuSearch(foundname).stuName)
Next
ElseIf rdFinal.Checked = True And txtNameLookup.Text <> "" Then
For searchStu = 0 To loopcnt
If txtNameLookup.Text = stuSearch(loopcnt).stuName Then
foundname = loopcnt
Exit For
End If
MsgBox("You entered " & txtNameLookup.Text & " and their final grade was " & stuSearch(foundname).stuGrade)
Next
ElseIf rdGrades.Checked = True And txtNameLookup.Text <> "" Then
For searchStu = 0 To loopcnt
If txtNameLookup.Text = stuSearch(loopcnt).stuName Then
foundname = loopcnt
Exit For
End If
MsgBox("You entered " & txtNameLookup.Text & "and their grade letter was " & stuSearch(foundname).stuGrade)
Next
ElseIf rdPercent.Checked = True And txtNameLookup.Text <> "" Then
For searchStu = 0 To loopcnt
If txtName.Text = stuSearch(loopcnt).stuName Then
foundname = loopcnt
Exit For
End If
MsgBox("You entered " & txtName.Text & "and their percentage was " & stuSearch(foundname).stuAvg)
Next
Else
MsgBox("There is an error searching for the student, please try again")
txtName.Clear()
txtName.Focus()
End If
End Sub
EndClass
----------------------------------------------------------
If you have any ideas how to go about this, please let me know because I have been working on this for a very long time, try a week and a half now. To make matters worse, I have to do a similar thing for my linux class using the VIM editor, searching for an animal and then looking up what food it eats using sort, gep, etc without intermediate files and using pipes. I know this is a lot to ask for, but I am so new to this. Thank you in advance for your help.
Name Test1 Test2 Test3 Avg Grade
===================================
Student 999 999 999 999 X
The first two lines in this are headings that are added into the text file, and I need the student name, the test scores, avg and grade letter as seperate parts of a structure.
This is for a basic programming class, but the instructor hasn't really gotten into details about how to do this at all. What I have to do with this is search for the student name as you would do in a database to find a student's grade, and we are assuming that we do not know how many students there are in the file.
I am assuming that you would like to view the code I have to see where I am coming from. I have been googling arrays and using MSDN Libraries for help. To view the code, it is between the dashes:
---------------------------------------------------------------------------------
OptionExplicitOn
Imports System.Math
Imports System.IO
Imports System.IO.File
PublicClass Form1
Inherits System.Windows.Forms.Form
Structure StudentRec
Dim Name As String
Dim test1, test2, test3 As Double
Dim Avg As Double
End Structure
Dim AStudents() As StudentRec = {}
Friend max As Integer
Friend pointer As Short
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
btnDisplay.Hide() : btnAccept.Hide() : lstDisplay.Hide() : txtName.Hide() : txtScore1.Hide()
txtScore2.Hide() : txtScore3.Hide() : Label6.Hide() : Label2.Hide() : Label3.Hide() : Label4.Hide()
Label5.Hide() : lblStudentCount.Hide() : btnDisplay.Hide() : btnSave.Hide()
btnDisplay.Enabled = False : btnAccept.Enabled = False : lstDisplay.Enabled = False : txtName.Enabled = False
txtScore1.Enabled = False : txtScore2.Enabled = False : txtScore3.Enabled = False : Label6.Enabled = False
Label2.Enabled = False : Label3.Enabled = False : Label4.Enabled = False : Label5.Enabled = False
lblStudentCount.Enabled = False : btnDisplay.Enabled = False : btnSave.Enabled = False
btnDisplay.Enabled = False
btnAccept.Enabled = False
lblStudentCount.Text = 0
lstDisplay.Items.Add("Name Test 1 Test 2 Test 3 Average Grade")
lstDisplay.Items.Add("==============================================================================================")
End Sub
Private Sub txtName_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtName.Leave
If IsNumeric(txtName.Text) = True Then
txtName.Clear()
txtName.Focus()
MsgBox("I think you were trying to put a test score here, please put the student's name instead")
End If
If txtName.Text = "" Then
txtName.Focus()
End If
End Sub
Private Sub txtScore1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtScore1.Leave
If IsNumeric(txtScore1.Text) = False Then
MsgBox("You need to put the score for the first test")
txtScore1.Clear()
txtScore1.Focus()
Else
If CDbl(txtScore1.Text) > 100 Or CDbl(txtScore1.Text) < 0 Then
MsgBox("The test score is not correct")
txtScore1.Clear()
txtScore1.Focus()
End If
End If
End Sub
Private Sub txtScore2_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtScore2.Leave
If IsNumeric(txtScore2.Text) = False Then
MsgBox("You need to put the score for the second test")
txtScore2.Clear()
txtScore2.Focus()
Else
If CDbl(txtScore2.Text) > 100 Or CDbl(txtScore2.Text) < 0 Then
MsgBox("The test score is not correct")
txtScore2.Clear()
txtScore2.Focus()
End If
End If
btnAccept.Enabled = True
End Sub
Private Sub txtScore3_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtScore3.Leave
If IsNumeric(txtScore3.Text) = False Then
MsgBox("You need to put the score for the third test")
txtScore3.Clear()
txtScore3.Focus()
Else
If CDbl(txtScore3.Text) > 100 Or CDbl(txtScore3.Text) < 0 Then
MsgBox("The test score is not correct")
txtScore3.Clear()
txtScore3.Focus()
End If
End If
End Sub
Private Sub btnAccept_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAccept.Click
lstDisplay.Items.Clear()
lstDisplay.Items.Add("Name Test 1 Test 2 Test 3 Average Grade")
lstDisplay.Items.Add("==============================================================================================")
pointer = 1 + UBound(AStudents)
lblStudentCount.Text = pointer + 1
ReDim Preserve AStudents(pointer)
AStudents(pointer).Name = CStr(txtName.Text)
AStudents(pointer).test1 = CDbl(txtScore1.Text)
AStudents(pointer).test2 = CDbl(txtScore2.Text)
AStudents(pointer).test3 = CDbl(txtScore3.Text)
txtName.Clear()
txtScore1.Clear()
txtScore2.Clear()
txtScore3.Clear()
txtName.Focus()
btnAccept.Enabled = False
btnDisplay.Enabled = True
End Sub
Private Sub btnDisplay_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
lstDisplay.Items.Clear()
lstDisplay.Items.Clear()
lstDisplay.Items.Add("Name Test 1 Test 2 Test 3 Average Grade")
lstDisplay.Items.Add("==============================================================================================")
Dim avg, high, mid, low As Double
Dim Letter As String
For max = 0 To UBound(AStudents)
If AStudents(max).test1 > AStudents(max).test2 And AStudents(max).test1 > AStudents(max).test3 Then
high = AStudents(max).test1
If AStudents(max).test2 > AStudents(max).test3 Then
mid = AStudents(max).test2
low = AStudents(max).test3
Else
mid = AStudents(max).test3
low = AStudents(max).test2
End If
ElseIf AStudents(max).test2 > AStudents(max).test3 Then
high = AStudents(max).test2
If AStudents(max).test1 > AStudents(max).test3 Then
mid = AStudents(max).test1
low = AStudents(max).test3
Else
mid = AStudents(max).test3
low = AStudents(max).test1
End If
Else
high = AStudents(max).test3
If AStudents(max).test1 > AStudents(max).test2 Then
mid = AStudents(max).test1
low = AStudents(max).test2
Else
mid = AStudents(max).test2
low = AStudents(max).test1
End If
End If
avg = ((0.4 * high) + (0.35 * mid) + (0.25 * low))
If avg > 90 Then
Letter = "A"
ElseIf avg > 80 Then
Letter = "B"
ElseIf avg > 70 Then
Letter = "C"
ElseIf avg > 60 Then
Letter = "D"
Else
Letter = "F"
End If
lstDisplay.Items.Add(AStudents(max).Name.PadLeft(1) & AStudents(max).test1.ToString.PadLeft(25) & _
AStudents(max).test2.ToString.PadLeft(15) & AStudents(max).test3.ToString.PadLeft(20) & _
avg.ToString.PadLeft(20) & Letter.PadLeft(20))
Next
btnSave.Enabled = True
End Sub
Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
End
End Sub
Private Sub btnNew_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNew.Click
btnDisplay.Show() : btnAccept.Show() : lstDisplay.Show() : txtName.Show() : txtScore1.Show()
txtScore2.Show() : txtScore3.Show() : Label6.Show() : Label2.Show() : Label3.Show() : Label4.Show()
Label5.Show() : lblStudentCount.Show() : btnDisplay.Show() : btnSave.Show()
lstDisplay.Enabled = True : txtName.Enabled = True : txtScore1.Enabled = True
txtScore2.Enabled = True : txtScore3.Enabled = True : Label6.Enabled = True
Label2.Enabled = True : Label3.Enabled = True : Label4.Enabled = True : Label5.Enabled = True
lblStudentCount.Enabled = True : txtName.Focus()
End Sub
Private Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
MsgBox("Saving will overwrite old file", MsgBoxStyle.OkOnly)
Dim writer As StreamWriter
writer = New StreamWriter("Grades.txt")
For max = 0 To lstDisplay.Items.Count - 1
writer.WriteLine(lstDisplay.Items.Item(max))
Next
writer.Close()
End Sub
Private Sub btnOpen_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOpen.Click
lstDocument.Items.Clear()
Dim reader As StreamReader
Try
reader = New StreamReader("Grades.txt")
While reader.EndOfStream = False
lstDocument.Items.Add(reader.ReadLine)
End While
reader.Close()
Catch ex As Exception
MsgBox("File does not exist, please create a new file first")
End Try
End Sub
Structure FindStudent
Dim stuName As String
Dim stuTest1, stuTest2, stuTest3, stuAvg As Double
Dim stuGrade As String
End Structure
Private Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click
Dim stuSearch() As FindStudent = {}
Dim reader As StreamReader = File.OpenText("Grades.txt")
Dim loopcnt As Integer = 0
Dim foundname As String
Dim searchStu As Integer
stuSearch(loopcnt - 1).stuName = reader.ReadLine
Do While stuSearch(loopcnt - 1).stuName = reader.EndOfStream <> False
stuSearch(loopcnt - 1).stuTest1 = reader.ReadLine
stuSearch(loopcnt - 1).stuTest2 = reader.ReadLine
stuSearch(loopcnt - 1).stuTest3 = reader.ReadLine
stuSearch(loopcnt - 1).stuAvg = reader.ReadLine
stuSearch(loopcnt - 1).stuGrade = reader.ReadLine
loopcnt = loopcnt + 1
Loop
foundname = -1
If rdAll.Checked = True And txtNameLookup.Text <> "" Then
For searchStu = 0 To loopcnt
If txtNameLookup.Text = stuSearch(loopcnt).stuName Then
foundname = loopcnt
Exit For
End If
MsgBox("You Entered " & txtNameLookup.Text & " and the person found was " & stuSearch(foundname).stuName)
Next
ElseIf rdFinal.Checked = True And txtNameLookup.Text <> "" Then
For searchStu = 0 To loopcnt
If txtNameLookup.Text = stuSearch(loopcnt).stuName Then
foundname = loopcnt
Exit For
End If
MsgBox("You entered " & txtNameLookup.Text & " and their final grade was " & stuSearch(foundname).stuGrade)
Next
ElseIf rdGrades.Checked = True And txtNameLookup.Text <> "" Then
For searchStu = 0 To loopcnt
If txtNameLookup.Text = stuSearch(loopcnt).stuName Then
foundname = loopcnt
Exit For
End If
MsgBox("You entered " & txtNameLookup.Text & "and their grade letter was " & stuSearch(foundname).stuGrade)
Next
ElseIf rdPercent.Checked = True And txtNameLookup.Text <> "" Then
For searchStu = 0 To loopcnt
If txtName.Text = stuSearch(loopcnt).stuName Then
foundname = loopcnt
Exit For
End If
MsgBox("You entered " & txtName.Text & "and their percentage was " & stuSearch(foundname).stuAvg)
Next
Else
MsgBox("There is an error searching for the student, please try again")
txtName.Clear()
txtName.Focus()
End If
End Sub
EndClass
----------------------------------------------------------
If you have any ideas how to go about this, please let me know because I have been working on this for a very long time, try a week and a half now. To make matters worse, I have to do a similar thing for my linux class using the VIM editor, searching for an animal and then looking up what food it eats using sort, gep, etc without intermediate files and using pipes. I know this is a lot to ask for, but I am so new to this. Thank you in advance for your help.
•
•
Join Date: Nov 2006
Posts: 19
Reputation:
Solved Threads: 0
I am having problems with creating a second structure/array that data will be read into from a text file. The data is originally written from a listbox if that matters doing a line by line write. The other problem I am having is searching a student's name and trying to get that data from the array just created using the text file. I hope I am answering your question to my question, if not, could you clarify, thank you.
Each line will be fed into a class structure:
You would split the line using the space as a delimiter. Look up the split method.
Now you would feed these variables into your class.
I.e
To search for a name you would just look at the name attributes for all your data.
VB.NET Syntax (Toggle Plain Text)
Student 999 999 999 999 X
You would split the line using the space as a delimiter. Look up the split method.
Now you would feed these variables into your class.
I.e
VB.NET Syntax (Toggle Plain Text)
class student { string name double scoreOne double scoreTwo double scoreThree double scoreFour double average }
To search for a name you would just look at the name attributes for all your data.
*Voted best profile in the world*
•
•
Join Date: Nov 2006
Posts: 19
Reputation:
Solved Threads: 0
To explain my last post, it is the pointer of the structure array that is creating the error. The code that I have is listed below:
--------------------------------------------------------------------------------
count = 0
SearchStudents(count - 1).stuName = reader.ReadLine
Do While SearchStudents(count - 1).stuName <> "-1"
SearchStudents(count - 1).stuTest1 = CDbl(reader.ReadLine)
SearchStudents(count - 1).stuTest2 = CDbl(reader.ReadLine)
SearchStudents(count - 1).stuTest3 = CDbl(reader.ReadLine)
SearchStudents(count - 1).stuAvg = CDbl(reader.ReadLine)
SearchStudents(count - 1).stuGrade = CStr(reader.ReadLine)
count = count + 1
Loop
reader.Close()
---------------------------------------------------------
I have no idea why this is creating the error "IndexOutOfRangeException was unhandled", all I know is that it highlights the second line of code that I have given. The entire project is attached to this post so you could try to find what might really be throwing this error. Again thanks, and so you know, this attached file is newer than the first one that I attached earlier.
--------------------------------------------------------------------------------
count = 0
SearchStudents(count - 1).stuName = reader.ReadLine
Do While SearchStudents(count - 1).stuName <> "-1"
SearchStudents(count - 1).stuTest1 = CDbl(reader.ReadLine)
SearchStudents(count - 1).stuTest2 = CDbl(reader.ReadLine)
SearchStudents(count - 1).stuTest3 = CDbl(reader.ReadLine)
SearchStudents(count - 1).stuAvg = CDbl(reader.ReadLine)
SearchStudents(count - 1).stuGrade = CStr(reader.ReadLine)
count = count + 1
Loop
reader.Close()
---------------------------------------------------------
I have no idea why this is creating the error "IndexOutOfRangeException was unhandled", all I know is that it highlights the second line of code that I have given. The entire project is attached to this post so you could try to find what might really be throwing this error. Again thanks, and so you know, this attached file is newer than the first one that I attached earlier.
Can you post just the code here. I don't like downloading zip files in case they contains viruses and other known nasties.:cheesy:
A few hints.
If that's where the problem is try taking that line out altogether.
Why the (count - 1). try changing it to SearchStudents(count)
A few hints.
•
•
•
•
'SearchStudents(count - 1).stuName = reader.ReadLine
•
•
•
•
SearchStudents(count - 1).
Last edited by iamthwee; Nov 29th, 2006 at 3:16 am.
*Voted best profile in the world*
Another very good tip would be to create a completely new project.
Then just try to read that file into the structure and display it. That way if there are any errors you know it is only to do with that section of code. Trying to do that within a big project is bad, because you don't know if something else is causing the problem.
Isolate and deal with it.
Then just try to read that file into the structure and display it. That way if there are any errors you know it is only to do with that section of code. Trying to do that within a big project is bad, because you don't know if something else is causing the problem.
Isolate and deal with it.
Last edited by iamthwee; Nov 29th, 2006 at 3:29 am.
*Voted best profile in the world*
in this case, no. a zip file is better because it contains lots of files and some of them contain binary information. Besides, you should always be running a virus scanner which will catch viruses.
•
•
•
•
in this case, no. a zip file is better because it contains lots of files and some of them contain binary information. Besides, you should always be running a virus scanner which will catch viruses.
Also while I was away, I was thinking perhaps you're trying to read the whole file into your structure which is allocates space for only five lines.
*Voted best profile in the world*
![]() |
Similar Threads
- Need reference to Random Accessing of Text files (C++)
- A couple Qs (arrays, c++, and reading in text files) (C++)
- appending two java text files (Java)
- lost my notebook for making text files--how do I get it back? (Windows NT / 2000 / XP)
Other Threads in the VB.NET Forum
- Previous Thread: Can Someone Help
- Next Thread: Because of security restrictions, the type Remoting.myobj cannot be accessed
| Thread Tools | Search this Thread |
"crystal .net .net2005 30minutes 2008 access add arithmetic array assignment basic binary bing box button buttons c# center code combobox component connectionstring convert cpu data database databasesearch datagrid datagridview design dissertation dissertations dissertationthesis dosconsolevb.net editvb.net excel file-dialog firewall folder google hardcopy image images isnumericfuntioncall listview login math memory mobile ms mssqlbackend mysql navigate net networking opacity output pan peertopeervideostreaming picturebox picturebox1 plugin port print printpreview problemwithinstallation project record reports" reuse save savedialog serial server sorting sql storedprocedure string temp text textbox timer toolbox updown upload useraccounts usercontrol vb vb.net vb.netcode vb.nettoolboxvisualbasic2008sidebar vbnet view vista visual visualbasic visualbasic.net visualstudio web wpf






