Jump to content
JamesBong

Ajutor Program Visual Basic

Recommended Posts

Salut

 

Am de facut ca proiect pentru facultate un formular de inregistrare pentru studenti. Ne-a fost schimbat profesorul si acesta nu explica prea bine iar documentatie nu prea gasesc.

Stiu chestii basic in C# dar asta este cam grea.

Ma puteti ajuta cu niste sfaturi sau de unde sa incep?

 

 

 

anvcbem.jpg8fN9Ez5.jpg

Link to comment
Share on other sites

56 minutes ago, Erase said:

Pentru a face asa ceva n-ar trebui sa ai nevoie de documentatie ci de putin creier.

Incepi prin a invata despre arrays si cum se manipuleaza acestea apoi lucrezi cu controalele din IDE.

Ce sa faceti si voi daca dormiti la ore acum trebuie sa reluati materia la un proiect banal.

Sunt oameni care nu stiu nici sa citeasca/afiseze un vector la facultate de programare.

Ce sa mai zic de unul care n-are treaba cu programarea :))?

Link to comment
Share on other sites

41 minutes ago, JamesBong said:

Am citit si nu am gasit ceea ce cautam. Vreau sa iau ce e in textbox si sa stochez in array. Prima data merge iar apoi cand apas din nou pe register imi da eroare...

Ar fi mai usor daca as folosi database pentru stocarea datelor ?

Sigur e mai usor sa te conectezi la un db decat sa folosesti un array.

Fa DEBUG.

N-ai gasit problema?Inseamna ca ai facut DEBUG prost.

Link to comment
Share on other sites

Cerinta este sa folosesti un array.

 

The indexes of an array range from 0 to one less than the total number of elements in the array. When you use Visual Basic syntax to define the size of an array, you specify its highest index, not the total number of elements in the array.

 

 

 

  • Like 1
Link to comment
Share on other sites

2fC2mZC.jpg

Multumesc pentru ajutor. Am rezolvat cu salvarea datelor in array.

 

Acum incerc sa fac sa mearga cele doua sagetute sa pot da scroll printre studenti si nu reusesc.

 

Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
        Dim m As Integer
        m = 0
        TextBox1.Text = fn(m)
        m = m + 1
    End Sub

Link to comment
Share on other sites

Si cu partea de search am probleme :))

Trebuie sa caut in array dupa numarul de telefon si tot ce imi da este Not Found, nu merge decat prima valoare.

 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
          
        Dim k As Integer = 0
        Dim search As String = TextBox2.Text
       
        If search = tel(k) Then

            MessageBox.Show("Student found")
            TextBox1.Text = fn(k)
            TextBox3.Text = sn(k)
            ComboBox1.Text = course(k)
            
        Else
            MessageBox.Show("Not found")
            k = k + 1

        End If

    End Sub

 

Link to comment
Share on other sites

17 hours ago, JamesBong said:

Si cu partea de search am probleme :))

Trebuie sa caut in array dupa numarul de telefon si tot ce imi da este Not Found, nu merge decat prima valoare.


 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
          
        Dim k As Integer = 0
        Dim search As String = TextBox2.Text
       
        If search = tel(k) Then

            MessageBox.Show("Student found")
            TextBox1.Text = fn(k)
            TextBox3.Text = sn(k)
            ComboBox1.Text = course(k)
            
        Else
            MessageBox.Show("Not found")
            k = k + 1

        End If

    End Sub

 

Pai vezi man ca la tine k e mereu 0.

Nu iterezi si tu deloc prin vector?

Baga un for:

For i = 0 To ubound(stringArray)

plus un if search == tel(i)

 

scuze nu ma pricep la sintaxa de vb

Edited by gigiRoman
Link to comment
Share on other sites

mersi pt ajutor, am rezolvat cu partea de search. 

   Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
       
        Dim search As String = TextBox2.Text
        Dim i As Long
        Dim LU, LL As Long

        LU = UBound(tel)
        LL = LBound(tel)

        For i = LL To LU
            If tel(i) = search Then
                MessageBox.Show("Student found")
                TextBox1.Text = fn(i)
                TextBox3.Text = sn(i)
                ComboBox1.Text = course(i)
            End If
        Next
    End Sub

Nu prea gasesc informatii despre partea cum sterg un string din un array...

Link to comment
Share on other sites

 

Ceva de genu:

 

Public Class Student
    Public firstName As String = String.Empty
    Public surname As String = String.Empty
    Public tel As String = String.Empty
    Public course As String = String.Empty
End Class
Public Class Form1

    Dim cursuri As New List(Of String)(New String() {"Computing Technology", "Grafician in caramida"})
    Dim dataBase As New Dictionary(Of String, List(Of Student))
    Dim dbDir = "cursuri"
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        If Not System.IO.Directory.Exists(dbDir) Then
            System.IO.Directory.CreateDirectory(dbDir)
        End If

        For Each curs As String In cursuri
            cbCourse.Items.Add(curs)
            createField(curs)
            If (System.IO.File.Exists(dbDir & "\" & curs & ".txt")) Then
                For Each line As String In System.IO.File.ReadAllLines(dbDir & "\" & curs & ".txt")
                    If Not String.IsNullOrEmpty(line) AndAlso line.Contains(":") Then
                        Dim info() As String = line.Split(":")
                        Dim student As Student = New Student()
                        student.firstName = info(0).Trim
                        student.surname = info(1).Trim
                        student.tel = info(2).Trim
                        student.course = curs
                        addStudent(student)
                    End If
                Next
            End If
        Next
    End Sub

    Private Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click
        If Not String.IsNullOrEmpty(tbTel.Text) Then
            If searchForStudent(tbTel.Text) = True Then
                Dim student As Student = getStudent(tbTel.Text)
                tbFirstName.Text = student.firstName
                tbSurname.Text = student.surname
                tbTel.Text = student.tel
                cbCourse.SelectedText = student.course
            Else
                MessageBox.Show(Me, "Studentul nu exista in baza de date", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End If
        Else
            MessageBox.Show(Me, "Studentii se cauta dupa numarul de telefon", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If
    End Sub

    Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click
        If Not String.IsNullOrEmpty(tbTel.Text) Then
            If searchForStudent(tbTel.Text) = True Then
                removeStudent(getStudent(tbTel.Text))
                MessageBox.Show(Me, "Studentul a fost sters din baza de date", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Else
                MessageBox.Show(Me, "Studentul nu exista in baza de date", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End If
        Else
            MessageBox.Show(Me, "Studentii se sterg dupa numarul de telefon", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If
    End Sub

    Private Sub btnRegister_Click(sender As Object, e As EventArgs) Handles btnRegister.Click
        If Not String.IsNullOrEmpty(tbFirstName.Text) AndAlso Not String.IsNullOrEmpty(tbFirstName.Text) AndAlso Not String.IsNullOrEmpty(tbTel.Text) AndAlso cbCourse.SelectedIndex > -1 Then
            If searchForStudent(tbTel.Text) = False Then
                Dim student As Student = New Student()
                student.firstName = tbFirstName.Text
                student.surname = tbSurname.Text
                student.tel = tbTel.Text
                student.course = cbCourse.SelectedItem.ToString
                addStudent(student)
                MessageBox.Show(Me, tbFirstName.Text & " " & tbSurname.Text & " a fost adaugat in baza de date", "Succes", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Else
                MessageBox.Show(Me, "Acest student exista in baza de date", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End If
        Else
            MessageBox.Show(Me, "Te rugam sa completezi toate campurile", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If
    End Sub

    Private Sub btnList_Click(sender As Object, e As EventArgs) Handles btnList.Click
        couseList.Items.Clear()
        listStudents(cbCourse.SelectedItem.ToString)
    End Sub

    Private Sub listStudents(ByVal course As String)
        MsgBox(course)
        If dataBase.ContainsKey(course) Then
            If dataBase(course).Count > 0 Then
                For Each student As Student In dataBase(course)
                    couseList.Items.Add(student.firstName & " " & student.surname)
                Next
            Else
                MessageBox.Show(Me, "Nu exista studenti pentru cursul selectat", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Error) ' ??
            End If
        Else
            MessageBox.Show(Me, "Nu exista cursul selectat", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Error) ' ??
        End If
    End Sub
    Private Function searchForStudent(ByVal tel As String) As Boolean
        For Each pair In dataBase
            For Each student As Student In pair.Value
                If student.tel = tel Then
                    Return True
                End If
            Next
        Next
        Return False
    End Function

    Private Function getStudent(ByVal tel As String) As Student
        For Each pair In dataBase
            For Each student As Student In pair.Value
                If student.tel = tel Then
                    Return student
                End If
            Next
        Next
        Return Nothing
    End Function

    Private Function getStudentByIndex(ByVal course As String, ByVal index As Integer) As Student
        If dataBase.ContainsKey(course) Then
            If dataBase(course).Count >= index Then
                Return dataBase(course).Item(index)
            End If
        End If
    End Function

    Private Sub removeStudent(ByVal student As Student)
        For index As Integer = 0 To dataBase(student.course).Count - 1
            If dataBase(student.course)(index).tel = student.tel Then
                dataBase(student.course).RemoveAt(index)
            End If
        Next
    End Sub
    Private Sub addStudent(ByVal student As Student)
        If dataBase.ContainsKey(student.course) Then
            dataBase.Item(student.course).Add(student)
        Else
            createField(student.course)
            dataBase.Item(student.course).Add(student)
        End If
    End Sub

    Private Sub createField(ByVal fieldName As String)
        dataBase.Add(fieldName, New List(Of Student))
    End Sub

    Private Sub couseList_SelectedIndexChanged(sender As Object, e As EventArgs) Handles couseList.SelectedIndexChanged
        If couseList.SelectedIndex > -1 Then

        End If
    End Sub
    Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
        For Each pair In dataBase
            Dim O As New System.IO.StreamWriter(dbDir & "\" & pair.Key & ".txt", False)
            For Each student As Student In pair.Value
                O.WriteLine(student.firstName & ":" & student.surname & ":" & student.tel)
            Next
            O.Close()
        Next
    End Sub


End Class

A mai ramas putin de lucrat la el; si evident ca poate fi simplificat

Edited by Maximus
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...