Test Foro de elhacker.net SMF 2.1

Programación => .NET (C#, VB.NET, ASP) => Programación General => Programación Visual Basic => Mensaje iniciado por: themindmaster en 13 Octubre 2013, 17:02 PM

Título: Ayuda ordenar un list de manera ascendente o descendente
Publicado por: themindmaster en 13 Octubre 2013, 17:02 PM
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 :( :
Código (vb) [Seleccionar]
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!
Título: Re: Ayuda ordenar un list de manera ascendente o descendente
Publicado por: Danyfirex en 13 Octubre 2013, 19:09 PM
Ya te ideaste un algoritmo?
Título: Re: Ayuda ordenar un list de manera ascendente o descendente
Publicado por: themindmaster en 13 Octubre 2013, 19:30 PM
no T-T
Título: Re: Ayuda ordenar un list de manera ascendente o descendente
Publicado por: Danyfirex en 13 Octubre 2013, 19:38 PM
ahí tienes.


http://es.wikipedia.org/wiki/Ordenamiento_de_burbuja


saludos
Título: Re: Ayuda ordenar un list de manera ascendente o descendente
Publicado por: themindmaster en 13 Octubre 2013, 19:53 PM
esta un poco largo pero lo vere XD gracias :)
Título: Re: Ayuda ordenar un list de manera ascendente o descendente
Publicado por: Danyfirex en 13 Octubre 2013, 19:55 PM
la documentación es larga pero el algoritmo te quedara en menos de 15 lineas.

culaquier duda pregunta.

saludos
Título: Re: Ayuda ordenar un list de manera ascendente o descendente
Publicado por: Mad Antrax en 13 Octubre 2013, 19:57 PM
Es más sencillo si aplicas el ordenamiento por Inserción

http://es.wikipedia.org/wiki/Ordenamiento_por_inserci%C3%B3n

Código (vb) [Seleccionar]
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

Código (vb) [Seleccionar]
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
Título: Re: Ayuda ordenar un list de manera ascendente o descendente
Publicado por: themindmaster en 13 Octubre 2013, 20:02 PM
Que se supone que es numbers si se podria saber?
Título: Re: Ayuda ordenar un list de manera ascendente o descendente
Publicado por: themindmaster en 13 Octubre 2013, 20:15 PM
No me funciona :(
Título: Re: Ayuda ordenar un list de manera ascendente o descendente
Publicado por: Danyfirex en 13 Octubre 2013, 20:31 PM
Que no te funciona?
Título: Re: Ayuda ordenar un list de manera ascendente o descendente
Publicado por: themindmaster en 13 Octubre 2013, 20:33 PM
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 :(
Título: Re: Ayuda ordenar un list de manera ascendente o descendente
Publicado por: Danyfirex en 13 Octubre 2013, 20:38 PM
El insertionSort esta hecho en vb.net.

pero que has hecho que no te funciona?
Título: Re: Ayuda ordenar un list de manera ascendente o descendente
Publicado por: themindmaster en 13 Octubre 2013, 20:50 PM
entonces el codigo de arriba no funciona?
Título: Re: Ayuda ordenar un list de manera ascendente o descendente
Publicado por: themindmaster en 13 Octubre 2013, 20:54 PM
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
Título: Re: Ayuda ordenar un list de manera ascendente o descendente
Publicado por: Danyfirex en 13 Octubre 2013, 21:05 PM
A ver.

Te la pongo facil.

usa este algoritmo

Código (vb) [Seleccionar]
'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



Título: Re: Ayuda ordenar un list de manera ascendente o descendente
Publicado por: themindmaster en 13 Octubre 2013, 21:15 PM
me da error :( dice que  se esperaba endsub T___T
saludos!
Título: Re: Ayuda ordenar un list de manera ascendente o descendente
Publicado por: Danyfirex en 13 Octubre 2013, 21:20 PM
Muestra tu código completo  :rolleyes:
Título: Re: Ayuda ordenar un list de manera ascendente o descendente
Publicado por: themindmaster en 13 Octubre 2013, 21:37 PM
jajajaja perdona se me olvido recargar la pagina :)  mira el codigo
Código (vb) [Seleccionar]
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
Título: Re: Ayuda ordenar un list de manera ascendente o descendente
Publicado por: Danyfirex en 13 Octubre 2013, 21:46 PM
Estas declarando un rutina dentro de otra :S

debería ser algo así.

Código (vb) [Seleccionar]




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
Título: Re: Ayuda ordenar un list de manera ascendente o descendente
Publicado por: themindmaster en 13 Octubre 2013, 21:57 PM
este es el codigo que puse y me da un errorsillo:
Código (vb) [Seleccionar]
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 :(
Título: Re: Ayuda ordenar un list de manera ascendente o descendente
Publicado por: Danyfirex en 13 Octubre 2013, 22:43 PM
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.