You are on page 1of 2

Public Class Form1

Private Sub btningresar_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btningresar.Click

For i = 0 To ListBox1.Items.Count - 1
If ListBox1.Items(i) = txtnombre.Text Then
MsgBox("El Nombre ya existe", MsgBoxStyle.Exclamation, "Aviso")
txtnombre.Clear()
txtnombre.Focus()
Return

End If

Next

If txtnombre.Text = "" Then


MsgBox("Por favor ingrese nombre", MsgBoxStyle.Exclamation, "Aviso")
txtnombre.Focus()

Return

End If

Call adicionar(txtnombre.Text)
txtnombre.Clear()

End Sub
Private Sub adicionar(ByVal nom As String)
ListBox1.Items.Add(nom)

End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ListBox1.SelectedIndexChanged

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button2.Click

Dim index As String


index = ListBox1.SelectedIndex
If index >= 0 Then
ListBox1.Items.RemoveAt(index)

End If

End Sub
End Class

You might also like