hola a todos, necesito una manito con este programa XD este es el diseño:
(http://img7.imageshack.us/img7/9440/gv27.jpg)
mi codigo hasta ahora es este :( :
Private Sub cmdañadir_Click()
lstnumero.AddItem (txtnumero)
End Sub
Private Sub cmdordenar_Click()
If optascendente Then
End If
End Sub
la función que quiero que haga este programa es que cuando le des click al botom añadir, añada el numero que pongas en el primer text y cuando le des a ascendente o descendente los ordene de forma ascendente o descendente XD espero me entiende y gracias de antemano.
saludos cordiales!
Ya te ideaste un algoritmo?
no T-T
ahí tienes.
http://es.wikipedia.org/wiki/Ordenamiento_de_burbuja
saludos
esta un poco largo pero lo vere XD gracias :)
la documentación es larga pero el algoritmo te quedara en menos de 15 lineas.
culaquier duda pregunta.
saludos
Es más sencillo si aplicas el ordenamiento por Inserción
http://es.wikipedia.org/wiki/Ordenamiento_por_inserci%C3%B3n
Private Sub insertionSort(ByVal numbers() As Integer) ' Es una función,
'debemos pasarle el array de números desde el Sub Main()
Dim i, j, index As Integer
i = 1
Do
index = numbers(i)
j = i - 1
While ((j >= 0) And (numbers(j) > index))
numbers(j + 1) = numbers(j)
j = j - 1
End While
numbers(j + 1) = index
i = i + 1
Loop Until i > (UBound(v))
End Sub
Tambien tienes el ordenamiento por Selección
For i = 1 To n - 1
minimo = i
For j = i + 1 To n
If x(minimo) > x(j) Then
minimo = j
End If
Next j
temp = x(i)
x(i) = x(minimo)
x(minimo) = temp
Next i
Que se supone que es numbers si se podria saber?
No me funciona :(
Que no te funciona?
T_____T otro programa, en el cual tengo que pedir ayuda :( perdonen las molestias enserio :( T_T el codigo no me funciona me da error al principio :(
El insertionSort esta hecho en vb.net.
pero que has hecho que no te funciona?
entonces el codigo de arriba no funciona?
Solo quiero que me ordene los numeros añadidos al listbox si le doy al optionbotom ascendente me los ordenara de manera ascendente pero si le doy a descendente me los ordenara de manera descendente
A ver.
Te la pongo facil.
usa este algoritmo
'true ascendente, false descendente
Public Sub BubbleSort(ByRef iaArray() As Long, Optional ByVal tipo As Boolean = True)
Dim n As Integer, i As Integer, j As Integer
n = UBound(iaArray)
For i = (n - 1) To 0 Step -1
For j = 0 To i
If tipo = True Then
If iaArray(j) > iaArray(j + 1) Then
Swap iaArray(j), iaArray(j + 1)
End If
Else
If iaArray(j) < iaArray(j + 1) Then
Swap iaArray(j), iaArray(j + 1)
End If
End If
Next j
Next i
End Sub
que tienes que hacer. lo siguiente.
coger todos los elementos del listbox en un array.
luego
limpiar el listbox
luego llamar la rutina
Call BubbleSort(arreglo(), True)
luego llenar el listbox otra vez.
saludos
me da error :( dice que se esperaba endsub T___T
saludos!
Muestra tu código completo :rolleyes:
jajajaja perdona se me olvido recargar la pagina :) mira el codigo
Private Sub cmdañadir_Click()
lstnumero.AddItem (txtnumero)
End Sub
Private Sub cmdordenar_Click()
Public Sub BubbleSort(ByRef iaArray() As Long, Optional ByVal tipo As Boolean = True)
Dim n As Integer, i As Integer, j As Integer
n = UBound(iaArray)
For i = (n - 1) To 0 Step -1
For j = 0 To i
If tipo = True Then
If iaArray(j) > iaArray(j + 1) Then
Swap iaArray(j), iaArray(j + 1)
End If
Else
If iaArray(j) < iaArray(j + 1) Then
Swap iaArray(j), iaArray(j + 1)
End If
End If
Next j
Next i
End Sub
Estas declarando un rutina dentro de otra :S
debería ser algo así.
Private Sub Ordenar_Click()
Dim i As Long
Dim arreglo() As Long
ReDim arreglo(List1.ListCount - 1)
For i = 0 To List1.ListCount - 1
arreglo(i) = Int(List1.List(i))
Next
For i = 0 To UBound(arreglo)
Next
Call BubbleSort(arreglo(), True)
List1.Clear
For i = 0 To UBound(arreglo)
List1.AddItem arreglo(i)
Next
End Sub
'true ascendente, false descendente
Public Sub BubbleSort(ByRef iaArray() As Long, Optional ByVal tipo As Boolean = True)
Dim n As Integer, i As Integer, j As Integer
n = UBound(iaArray)
For i = (n - 1) To 0 Step -1
For j = 0 To i
If tipo = True Then
If iaArray(j) > iaArray(j + 1) Then
Swap iaArray(j), iaArray(j + 1)
End If
Else
If iaArray(j) < iaArray(j + 1) Then
Swap iaArray(j), iaArray(j + 1)
End If
End If
Next j
Next i
End Sub
Private Sub Swap(ByRef xArg1, ByRef xArg2)
Dim xTmp
xTmp = xArg2
xArg2 = xArg1
xArg1 = xTmp
End Sub
PD: te recomiendo que leas mas sobre vb6( al menos lo básico ¬¬) lo estas haciendo al azar.
saludos
este es el codigo que puse y me da un errorsillo:
Private Sub cmdañadir_Click()
lstnumero.AddItem (txtnumero)
End Sub
Private Sub cmdordenar_Click()
Dim i As Long
Dim arreglo() As Long
ReDim arreglo(List1.ListCount - 1)
For i = 0 To List1.ListCount - 1
arreglo(i) = Int(List1.List(i))
Next
For i = 0 To UBound(arreglo)
Next
Call BubbleSort(arreglo(), True)
List1.Clear
For i = 0 To UBound(arreglo)
List1.AddItem arreglo(i)
Next
End Sub
'true ascendente, false descendente
Public Sub BubbleSort(ByRef iaArray() As Long, Optional ByVal tipo As Boolean = True)
Dim n As Integer, i As Integer, j As Integer
n = UBound(iaArray)
For i = (n - 1) To 0 Step -1
For j = 0 To i
If tipo = True Then
If iaArray(j) > iaArray(j + 1) Then
Swap iaArray(j), iaArray(j + 1)
End If
Else
If iaArray(j) < iaArray(j + 1) Then
Swap iaArray(j), iaArray(j + 1)
End If
End If
Next j
Next i
End Sub
Private Sub Swap(ByRef xArg1, ByRef xArg2)
Dim xTmp
xTmp = xArg2
xArg2 = xArg1
xArg1 = xTmp
End Sub
error 424 se requiere un objeto :(
Ya te dije tienes que leer mas.
el error es por el nombre de los controles que alguno no coincide. ademas falta terminarlo así no va a andar.