Member Avatar for grgrl

hi im a noob in vb and i need some help i want to read from the files teachers code and from the file studentscourse bu i only want to get the results if fileds(1) of teacherscourse is equal to the loggin basicly i a teacher to enter his Teacher id number and only get the classes that are register for him
thank you in advance

Private Sub ComboboxStudentCao(ByVal _filepath2 As String, ByVal _filapeat1 As String, ByRef cbx As ComboBox)
        Dim sreader As New StreamReader(Application.StartupPath & "\TeachersCourses.dat")
        Dim fields() As String
        Dim line As String
        line = sreader.ReadLine
        Dim Sreader1 As New StreamReader(Application.StartupPath & "\StudentsCourses.dat")
        Dim fields1() As String
        Dim line1 As String
        line1 = Sreader1.ReadLine
        Do Until line = Nothing
            fields = line.Split(CChar(","))
            If (MaskedTextBoxLogin.Text = fields(1)) Then
                Do Until line1 = Nothing
                    fields1 = line1.Split((CChar(",")))
                    cbx.Items.Add(fields1(0) & "," & fields1(1) & "," & fields1(2))
                    line1 = Sreader1.ReadLine
                Loop
                Sreader1.Close()
            End If
            line = sreader.ReadLine
        Loop
        sreader.Close()
    End Sub

Recommended Answers

All 2 Replies

Something like this might help. You might be able to notice, how much easier it is to read with all the dim statements together. This allows you to concentrate on the logic of your code much more easily.

    Private Sub ComboboxStudentCao(ByVal _filepath2 As String, ByVal _filapeat1 As String, ByRef cbx As ComboBox)
        Dim sreader As New StreamReader(Application.StartupPath & "\TeachersCourses.dat")
        Dim Sreader1 As New StreamReader(Application.StartupPath & "\StudentsCourses.dat")
        Dim fields() As String
        Dim line As String
        Dim fields1() As String
        Dim line1 As String

        Do While sreader.Peek() >= 0
            line = sreader.ReadLine     
            fields = line.Split(',')
            If (MaskedTextBoxLogin.Text = fields(1)) Then
                Do While Sreader1.Peek() >= 0
                    line1 = Sreader1.ReadLine               
                    fields1 = line1.Split(',')
                    cbx.Items.Add(fields1(0) & "," & fields1(1) & "," & fields1(2))
                    line1 = Sreader1.ReadLine
                Loop
                Sreader1.Close()
            End If
        Loop
        sreader.Close()
    End Sub

The main thing I see missing is a statement to filter the studentcourses.dat according to the teacherid. It's hard to figure this out without a sample of the file. Also is the teacherid in the first fields or the second fields? fields(1) is the second item.

The most important quality you will need as a professional programmer (or a professional anything) is the ability to communicate clearly. Reread your initial post and consider that.

Yes. This is a snotty comment. But it is an important lesson.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.