elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Guía rápida para descarga de herramientas gratuitas de seguridad y desinfección


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  Ayuda ordenar un list de manera ascendente o descendente
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: 1 [2] 3 Ir Abajo Respuesta Imprimir
Autor Tema: Ayuda ordenar un list de manera ascendente o descendente  (Leído 11,418 veces)
themindmaster

Desconectado Desconectado

Mensajes: 32



Ver Perfil
Re: Ayuda ordenar un list de manera ascendente o descendente
« Respuesta #10 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 :(


En línea

El sabio no se sienta para lamentarse, sino que se pone alegremente a su tarea de reparar el daño hecho.
Danyfirex


Desconectado Desconectado

Mensajes: 493


My Dear Mizuho


Ver Perfil
Re: Ayuda ordenar un list de manera ascendente o descendente
« Respuesta #11 en: 13 Octubre 2013, 20:38 pm »

El insertionSort esta hecho en vb.net.

pero que has hecho que no te funciona?


En línea

themindmaster

Desconectado Desconectado

Mensajes: 32



Ver Perfil
Re: Ayuda ordenar un list de manera ascendente o descendente
« Respuesta #12 en: 13 Octubre 2013, 20:50 pm »

entonces el codigo de arriba no funciona?
En línea

El sabio no se sienta para lamentarse, sino que se pone alegremente a su tarea de reparar el daño hecho.
themindmaster

Desconectado Desconectado

Mensajes: 32



Ver Perfil
Re: Ayuda ordenar un list de manera ascendente o descendente
« Respuesta #13 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
En línea

El sabio no se sienta para lamentarse, sino que se pone alegremente a su tarea de reparar el daño hecho.
Danyfirex


Desconectado Desconectado

Mensajes: 493


My Dear Mizuho


Ver Perfil
Re: Ayuda ordenar un list de manera ascendente o descendente
« Respuesta #14 en: 13 Octubre 2013, 21:05 pm »

A ver.

Te la pongo facil.

usa este algoritmo

Código
  1. 'true ascendente, false descendente
  2. Public Sub BubbleSort(ByRef iaArray() As Long, Optional ByVal tipo As Boolean = True)
  3.  
  4. Dim n As Integer, i As Integer, j As Integer
  5.  
  6.    n = UBound(iaArray)
  7.  
  8.    For i = (n - 1) To 0 Step -1
  9.  
  10.        For j = 0 To i
  11.  
  12. If tipo = True Then
  13.            If iaArray(j) > iaArray(j + 1) Then
  14.            Swap iaArray(j), iaArray(j + 1)
  15.  
  16.            End If
  17. Else
  18. If iaArray(j) < iaArray(j + 1) Then
  19.            Swap iaArray(j), iaArray(j + 1)
  20.  
  21.            End If
  22.            End If
  23.  
  24.  
  25.        Next j
  26.  
  27.    Next i
  28.  
  29. 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



En línea

themindmaster

Desconectado Desconectado

Mensajes: 32



Ver Perfil
Re: Ayuda ordenar un list de manera ascendente o descendente
« Respuesta #15 en: 13 Octubre 2013, 21:15 pm »

me da error :( dice que  se esperaba endsub T___T
saludos!
En línea

El sabio no se sienta para lamentarse, sino que se pone alegremente a su tarea de reparar el daño hecho.
Danyfirex


Desconectado Desconectado

Mensajes: 493


My Dear Mizuho


Ver Perfil
Re: Ayuda ordenar un list de manera ascendente o descendente
« Respuesta #16 en: 13 Octubre 2013, 21:20 pm »

Muestra tu código completo  :rolleyes:
En línea

themindmaster

Desconectado Desconectado

Mensajes: 32



Ver Perfil
Re: Ayuda ordenar un list de manera ascendente o descendente
« Respuesta #17 en: 13 Octubre 2013, 21:37 pm »

jajajaja perdona se me olvido recargar la pagina :)  mira el codigo
Código
  1. Private Sub cmdañadir_Click()
  2. lstnumero.AddItem (txtnumero)
  3.  
  4. End Sub
  5.  
  6. Private Sub cmdordenar_Click()
  7. Public Sub BubbleSort(ByRef iaArray() As Long, Optional ByVal tipo As Boolean = True)
  8.  
  9. Dim n As Integer, i As Integer, j As Integer
  10.  
  11.    n = UBound(iaArray)
  12.  
  13.    For i = (n - 1) To 0 Step -1
  14.  
  15.        For j = 0 To i
  16.  
  17. If tipo = True Then
  18.            If iaArray(j) > iaArray(j + 1) Then
  19.            Swap iaArray(j), iaArray(j + 1)
  20.  
  21.            End If
  22. Else
  23. If iaArray(j) < iaArray(j + 1) Then
  24.            Swap iaArray(j), iaArray(j + 1)
  25.  
  26.            End If
  27.            End If
  28.  
  29.  
  30.        Next j
  31.  
  32.    Next i
  33.  
  34.  
  35.  
  36.  
  37.  
  38. End Sub
En línea

El sabio no se sienta para lamentarse, sino que se pone alegremente a su tarea de reparar el daño hecho.
Danyfirex


Desconectado Desconectado

Mensajes: 493


My Dear Mizuho


Ver Perfil
Re: Ayuda ordenar un list de manera ascendente o descendente
« Respuesta #18 en: 13 Octubre 2013, 21:46 pm »

Estas declarando un rutina dentro de otra :S

debería ser algo así.

Código
  1.  
  2.  
  3.  
  4. Private Sub Ordenar_Click()
  5. Dim i As Long
  6. Dim arreglo() As Long
  7. ReDim arreglo(List1.ListCount - 1)
  8. For i = 0 To List1.ListCount - 1
  9. arreglo(i) = Int(List1.List(i))
  10. Next
  11. For i = 0 To UBound(arreglo)
  12.  
  13. Next
  14. Call BubbleSort(arreglo(), True)
  15. List1.Clear
  16.  
  17. For i = 0 To UBound(arreglo)
  18. List1.AddItem arreglo(i)
  19. Next
  20.  
  21.  
  22.  
  23. End Sub
  24.  
  25.  
  26.  
  27.  
  28. 'true ascendente, false descendente
  29. Public Sub BubbleSort(ByRef iaArray() As Long, Optional ByVal tipo As Boolean = True)
  30.  
  31. Dim n As Integer, i As Integer, j As Integer
  32.  
  33.    n = UBound(iaArray)
  34.  
  35.    For i = (n - 1) To 0 Step -1
  36.  
  37.        For j = 0 To i
  38.  
  39. If tipo = True Then
  40.            If iaArray(j) > iaArray(j + 1) Then
  41.            Swap iaArray(j), iaArray(j + 1)
  42.  
  43.            End If
  44. Else
  45. If iaArray(j) < iaArray(j + 1) Then
  46.            Swap iaArray(j), iaArray(j + 1)
  47.  
  48.            End If
  49.            End If
  50.  
  51.  
  52.        Next j
  53.  
  54.    Next i
  55.  
  56. End Sub
  57.  
  58.  
  59.  
  60.  
  61.  
  62. Private Sub Swap(ByRef xArg1, ByRef xArg2)
  63.  
  64.    Dim xTmp
  65.  
  66.    xTmp = xArg2
  67.  
  68.    xArg2 = xArg1
  69.  
  70.    xArg1 = xTmp
  71.  
  72. End Sub
  73.  
  74.  
  75.  
  76.  
  77.  


PD: te recomiendo que leas mas sobre vb6( al menos lo básico ¬¬) lo estas haciendo al azar.

saludos
En línea

themindmaster

Desconectado Desconectado

Mensajes: 32



Ver Perfil
Re: Ayuda ordenar un list de manera ascendente o descendente
« Respuesta #19 en: 13 Octubre 2013, 21:57 pm »

este es el codigo que puse y me da un errorsillo:
Código
  1. Private Sub cmdañadir_Click()
  2. lstnumero.AddItem (txtnumero)
  3.  
  4. End Sub
  5.  
  6. Private Sub cmdordenar_Click()
  7. Dim i As Long
  8. Dim arreglo() As Long
  9. ReDim arreglo(List1.ListCount - 1)
  10. For i = 0 To List1.ListCount - 1
  11. arreglo(i) = Int(List1.List(i))
  12. Next
  13. For i = 0 To UBound(arreglo)
  14.  
  15. Next
  16. Call BubbleSort(arreglo(), True)
  17. List1.Clear
  18.  
  19. For i = 0 To UBound(arreglo)
  20. List1.AddItem arreglo(i)
  21. Next
  22.  
  23.  
  24.  
  25. End Sub
  26.  
  27.  
  28.  
  29.  
  30. 'true ascendente, false descendente
  31. Public Sub BubbleSort(ByRef iaArray() As Long, Optional ByVal tipo As Boolean = True)
  32.  
  33. Dim n As Integer, i As Integer, j As Integer
  34.  
  35.    n = UBound(iaArray)
  36.  
  37.    For i = (n - 1) To 0 Step -1
  38.  
  39.        For j = 0 To i
  40.  
  41. If tipo = True Then
  42.            If iaArray(j) > iaArray(j + 1) Then
  43.            Swap iaArray(j), iaArray(j + 1)
  44.  
  45.            End If
  46. Else
  47. If iaArray(j) < iaArray(j + 1) Then
  48.            Swap iaArray(j), iaArray(j + 1)
  49.  
  50.            End If
  51.            End If
  52.  
  53.  
  54.        Next j
  55.  
  56.    Next i
  57.  
  58. End Sub
  59.  
  60.  
  61.  
  62.  
  63.  
  64. Private Sub Swap(ByRef xArg1, ByRef xArg2)
  65.  
  66.    Dim xTmp
  67.  
  68.    xTmp = xArg2
  69.  
  70.    xArg2 = xArg1
  71.  
  72.    xArg1 = xTmp
  73.  
  74. End Sub
  75.  
error 424 se requiere un objeto :(
En línea

El sabio no se sienta para lamentarse, sino que se pone alegremente a su tarea de reparar el daño hecho.
Páginas: 1 [2] 3 Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
ordenar base de datos de manera ascendente
PHP
adamsst 7 2,716 Último mensaje 15 Mayo 2015, 22:40 pm
por engel lex
Ayuda please! Ordenar numero de forma ascendente
Programación C/C++
bryanrz96 1 1,973 Último mensaje 13 Noviembre 2015, 22:19 pm
por 0xFer
bubble sort ascendente y descendente en un solo codigo
Programación C/C++
Paul Young 7 4,735 Último mensaje 7 Marzo 2016, 16:15 pm
por engel lex
ordenar por apellido ascendente, y por nombre descendente
Programación C/C++
matiapache12 1 2,746 Último mensaje 26 Octubre 2016, 18:08 pm
por palacio29
Ascendente, Descendente y fecha del sistema en ANSI C
Programación C/C++
paulin.c 1 1,874 Último mensaje 4 Diciembre 2017, 16:57 pm
por do-while
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines