Results 1 to 3 of 3

Thread: VB6.0 to VB.Net HELP!!

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2004
    Posts
    12

    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!!!!

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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:
    1. Dim filepath As String = "C:\Code\Practice\TestBed9\bin\grades.txt"
    2.  
    3.         'create arrays (or in this case arraylists)
    4.         Dim labs As New ArrayList
    5.         Dim questions As New ArrayList
    6.         Dim tests As New ArrayList
    7.         Dim participations As New ArrayList
    8.  
    9.         'open file
    10.         Dim fs As New IO.FileStream(filepath, FileMode.Open)
    11.         'create reader for file
    12.         Dim sr As New IO.StreamReader(fs)
    13.         'read until there is no more to read
    14.         Do While sr.Peek > -1
    15.             'read one line at a time
    16.             Dim line As String = sr.ReadLine
    17.             'parse into fields
    18.             Dim fields() As String = line.Split(Char.Parse(","))
    19.             'test for student match
    20.             If fields(0) = cboStudent.Text Then 'name
    21.                 Select Case fields(1) 'type
    22.                     Case "Lab"
    23.                         labs.Add(fields(2)) 'grade
    24.  
    25.                     Case "Questions"
    26.                         questions.Add(fields(2)) 'grade
    27.  
    28.                     Case "Tests"
    29.                         tests.Add(fields(2)) 'grade
    30.  
    31.                     Case "Participation"
    32.                         participations.Add(fields(2)) 'grade
    33.  
    34.                 End Select
    35.             End If
    36.  
    37.         Loop
    38.         'close and release file
    39.         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.

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2004
    Posts
    12

    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
  •  



Click Here to Expand Forum to Full Width