SoloCodigo
CLR: .Net / Mono / Boo / Otros CLR => VB .NET => Mensaje iniciado por: akiestudio en Domingo 30 de Noviembre de 2008, 17:05
-
Este es el codigo , mediante un radiobuton necesito ordenar un array Agenda(,) , que se visualizara en dos listbox, uno para nombre y otro para telefono , como puedo hacerlo , algun consejo , muchas gracias
Public Class Form1
Structure stragenda
Dim nombre As String
Dim Telefono As String
End Structure
Dim Agenda(,) As stragenda = {}
Dim i, j As Integer
Private Sub BtnAñadir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAñadir.Click
Dim existe As Boolean
existe = False
'LstNombre.Items.Clear()
'LstTelefono.Items.Clear()
If TxtNombre.Text <> "" Then
If Me.LstNombre.Items.Contains(TxtNombre.Text) Then
MsgBox(" Ya existe esta persona")
existe = True
End If
If Not existe Then
' AÑADIMOS AL LISTBOX
Me.LstNombre.Items.Add(Trim(Me.TxtNombre.Text))
Me.LstTelefono.Items.Add(Trim(Me.TxtTelefono.Text))
' REDIMENSIONAMOS LA MATRIZ
ReDim Agenda(Agenda.GetUpperBound(0) + 1, Agenda.GetUpperBound(0) + 1)
' CARGAMOS LA MATRIZ
With Agenda(Agenda.GetUpperBound(0), Agenda.GetUpperBound(0))
.nombre = Trim(Me.TxtNombre.Text)
For i = 0 To Agenda.Length + 1
For j = 0 To Agenda.Length + 1
.Telefono = Trim(Me.TxtTelefono.Text)
j = j + 1
Next
i = i + 1
Next
End With
End If
'nombre = Split(TxtNombre.Text, vbNewLine)
'If TxtTelefono.Text <> "" And TxtTelefono.Text.ToString = False And TxtTelefono.Text.Length = 9 Then
' 'Telefono = Split(TxtTelefono.Text, vbNewLine)
'End If
Else
MsgBox("No es un nummero o es demasiado grande")
End If
End Sub
Private Sub BtnSalir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSalir.Click
End
End Sub
Private Sub RbOrdenar_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RbOrdenar.CheckedChanged
Dim i As Integer
Array.Sort(Agenda)
For i = 0 To Agenda.GetUpperBound(0)
Me.LstNombre.Items.Add(Agenda)
Me.LstTelefono.Items.Add(Agenda)
Next
End Sub
Private Sub BtnModificar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnModificar.Click
'If LstNombre.Text <> "" And LstTelefono.Text <> "" Then
If LstNombre.SelectedItem = Me.LstNombre.Text Then
'ReDim Preserve Agenda(Agenda.GetUpperBound(0) - 1, Agenda.GetUpperBound(0) - 1)
Me.LstNombre.Items.Remove(Me.LstNombre.Text)
End If
If LstTelefono.SelectedItem = Me.LstTelefono.Text Then
Me.LstTelefono.Items.Remove(Me.LstTelefono.Text)
End If
'End If
End Sub
End Class
-
¿No te sirve con crear un array para los nombres y otro para los teléfonos y ordenarlos? ¿O quizás lo que quieres es ordenar el Array agenda según teléfono o nombre?
Si es el segundo caso, aparte de crear el array de nombres o de telefonos en cuestión necesitas usar el método Array.Sort(array1,array2). Este método ordena array1 y pone en el mismo orden en el que éste se haya ordenado array2.
Espero que te sirva de ayuda.