|
-
Apr 10th, 2004, 12:58 PM
#1
Thread Starter
New Member
VB6.0 to VB.Net HELP!!
I am trying to learn VB.Net, I am pretty proficient in VB 6.0 and have been doing ok with it till now. I need to be able to have the program read a .txt file sequentially, compare one of the values on each line and if they match to my criteria then it will load the values for that line into variables. Problem is I know exactly how to do this in VB 6.0 but the concept of how the Stream Writer and Stream Reader works in .Net is really starting to confuse the daylights of me. I have read most of the help related information, check out what the Deitel book on VB.Net programming and checked some online information on it and I still am not putting it all together. This is how it would look if I did it in VB 6.0, if I can see how this would be wrote in .Net I should be able to grasp the concept……God I hope.
Open "C:\WINDOWS\Desktop\Grades.txt" For Input As #1
Do While Not EOF(1)
Input #1, strName, strType, curGrade
If strName = cboStudent.Text Then
Select Case strType
Case "Lab"
curLab(a) = curGrade
a = a + 1
Case "Questions"
curQuestions(b) = curGrade
b = b + 1
Case "Tests"
curTest(c) = curGrade
c = c + 1
Case "Participation"
curParticipation(d) = curGrade
d = d + 1
End Select
End If
Loop
Thanks ahead of time for any help!!!!
-
Apr 10th, 2004, 07:48 PM
#2
Here is a rought translation to .NET although you could use the Compatiblity namespace to use almost the same code you have there.
VB Code:
Dim filepath As String = "C:\Code\Practice\TestBed9\bin\grades.txt"
'create arrays (or in this case arraylists)
Dim labs As New ArrayList
Dim questions As New ArrayList
Dim tests As New ArrayList
Dim participations As New ArrayList
'open file
Dim fs As New IO.FileStream(filepath, FileMode.Open)
'create reader for file
Dim sr As New IO.StreamReader(fs)
'read until there is no more to read
Do While sr.Peek > -1
'read one line at a time
Dim line As String = sr.ReadLine
'parse into fields
Dim fields() As String = line.Split(Char.Parse(","))
'test for student match
If fields(0) = cboStudent.Text Then 'name
Select Case fields(1) 'type
Case "Lab"
labs.Add(fields(2)) 'grade
Case "Questions"
questions.Add(fields(2)) 'grade
Case "Tests"
tests.Add(fields(2)) 'grade
Case "Participation"
participations.Add(fields(2)) 'grade
End Select
End If
Loop
'close and release file
fs.Close()
Also there could be a number of improvements if you wanted to go OOP with it. You could then make a Grades or Student class/collection and just serialize/deserialize it to and from disc. Then there is no parsing required and you can keep the data in memory for faster access.
-
Apr 11th, 2004, 02:49 PM
#3
Thread Starter
New Member
Thanks
Thanks for the Help! I am not doing this for a project or anything. I am just trying to learn VB.Net and was having problems understanding how to read and write from a file, your code helped a lot and I have a firm grasp on it now.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|