Ejercicio de Vectores en VB

Ejercicio de Vectores en Visual Basic, de la calse del profesro Valdivia


Sub main()
Dim nombres() As String
Dim total As Integer

Lectura nombres, total
Procesar nombres, total
Presenta nombres, total
End Sub
Sub Lectura(nombres() As String, total As Integer)
Dim cad As String
Dim sw As String

Do
cad = InputBox("Ingrese nombre: ")
Agregar nombres, total, cad

Do
sw = InputBox("Desea continuar?" & vbCrLf & "Si" & vbCrLf & "No")
Loop Until (sw = "si" Or sw = "no")

Loop Until sw = "no"
End Sub

Sub Agregar(nombres() As String, total As Integer, cad As String)

ReDim Preserve nombres(total)
nombres(total) = cad
total = total + 1
End Sub

Sub Presenta(nombres() As String, total As Integer)
Dim i As Integer
Dim cad As String

For i = 0 To total - 1
cad = cad & nombres(i) & vbCrLf
Next
MsgBox (cad)

End Sub

Sub Procesar(nombres() As String, total As Integer)
Dim i As Integer
Dim j As Integer
Dim aux As String

For i = 0 To total - 2
For j = i + 1 To total - 1
If nombres(i) > nombres(j) Then
aux = nombres(i)
nombres(i) = nombres(j)
nombres(j) = aux
End If
Next
Next

End Sub

No hay comentarios:

Publicar un comentario