La Web del Programador: Comunidad de Programadores
https://www.lawebdelprogramador.com/foros/Visual-Basic.NET/609097-ordenar-numeros.html

ordenar numeros

ordenar numeros

Publicado por juan delgado (1 intervención) el 13/03/2006 23:11:24
quisiera que me ayuden con un problema que tengo, quiero ordenar tres numeros de mayor a menor. los numeros los proporciono a traves de tres TextBox y mostrar el resultado en un Label. agradeco sus respuestas

RE:ordenar numeros

Publicado por Eliseo Mondragon (3 intervenciones) el 14/03/2006 01:50:09
Ya que tienes en tu Form los Tres TextBox y el label solo ocupas esto:
programa esto

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
Public Class Form1
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim intMayor, intMedio, intMenor As Integer
        If (CInt(TextBox1.Text) > CInt(TextBox2.Text)) Then
            If (CInt(TextBox1.Text) > CInt(TextBox3.Text)) Then
                intMayor = CInt(TextBox1.Text)
                If (CInt(TextBox2.Text) > CInt(TextBox3.Text)) Then
                    intMedio = CInt(TextBox2.Text)
                    intMenor = CInt(TextBox3.Text)
                Else
                    intMedio = CInt(TextBox3.Text)
                    intMenor = CInt(TextBox2.Text)
                End If
            Else
                intMayor = CInt(TextBox3.Text)
                intMedio = CInt(TextBox1.Text)
                intMenor = CInt(TextBox2.Text)
            End If
        Else
            If (CInt(TextBox2.Text) > CInt(TextBox3.Text)) Then
                intMayor = CInt(TextBox2.Text)
                If (CInt(TextBox1.Text) > CInt(TextBox3.Text)) Then
                    intMedio = CInt(TextBox1.Text)
                    intMenor = CInt(TextBox3.Text)
                Else
                    intMedio = CInt(TextBox3.Text)
                    intMenor = CInt(TextBox1.Text)
                End If
            Else
                intMayor = CInt(TextBox3.Text)
                intMedio = CInt(TextBox2.Text)
                intMenor = CInt(TextBox1.Text)
            End If
        End If
        Label1.Text = Str(intMayor) & " > " & Str(intMedio) & " > " & Str(intMenor)
    End Sub
End Class

Esta un poco largo pero es usando puro if para que fuera mas sencillo de entender aunque hay mas formas

RE:ordenar numeros

Publicado por Beatriz (1 intervención) el 28/11/2006 01:44:35
¡hola!
que tal como estas
ocupare es programa para poder realizar otro.

de casualidad sabras como ordenar de forma accendente y descendente

5 numeros introducidos por el usuario.

debe tener la opcion si los ordena accendente o descendente

MUCHA GRACIAS
sin imagen de perfil

RE:ordenar numeros

Publicado por Estefania (1 intervención) el 26/05/2016 21:54:16
Muchas gracias!,me ha servido bastante,siga así!! :)

RE:ordenar numeros

Publicado por Harold (411 intervenciones) el 14/03/2006 03:22:23
Espero esto te ayude............

1
2
3
4
5
6
7
8
9
10
Dim num(3), i As Integer 'arreglo de 3 valores
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        num.SetValue(CInt(TextBox1.Text), 1)
        num.SetValue(CInt(TextBox2.Text), 2)
        num.SetValue(CInt(TextBox3.Text), 3)
        Array.Sort(num) 'Ordena 1,2,3
        For i = 3 To 1 Step -1 ' Obtenemos el mayor al menor poniendo en reversa
            Label1.Text = Label1.Text & "  " & num.GetValue(i)
        Next
    End Sub

RE:ordenar numeros

Publicado por Yovani Lastarria (1 intervención) el 01/08/2007 17:48:16
Esta forma de hacerlo es mas sencilla solo se trabaja con if de 3 numeros pero si deseas mas numeros se realiza con Array........

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Private Sub btOrdenar_Click()
Dim I As Integer
Dim a, b, c As Integer
a = Val(Txtnum1.Text)
b = Val(Txtnum2.Text)
c = Val(Txtnum3.Text)
For I = 1 To 2
If a > b Then
   ax = a
   a = b
   b = ax
End If
If b > c Then
   ax = b
   b = c
   c = ax
End If
Next I
Me.lblordenador.Caption = Str(a) + " " + Str(b) + " " + Str(c)
End Sub

RE:ordenar numeros

Publicado por Harold (411 intervenciones) el 14/03/2006 04:08:28
Mejorado un poquito..... : )

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
'Esto te servira si por ejm tienes 100 o mas textbox que sumar
    'no lo agregaras uno por uno verdad........
 
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Dim num(3), i As Integer 'arreglo de 3 valores
    Dim ctlTbx As Control
    Dim vtext As Char
 
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
 
        'Esto busca todos los  textbox en tu formulario y si coincide si su texto es un
        'numero lo agrega a la coleccion, sino no toma el texto.
 
        For Each ctlTbx In Me.Controls
            If ctlTbx.GetType Is GetType(System.Windows.Forms.TextBox) Then
                vtext = Convert.ToChar(ctlTbx.Text.Chars(0)) 'toma el primer v del textbox
                If Char.IsNumber(vtext) Then
                    i += 1
                    num.SetValue(CInt(ctlTbx.Text), i)
                End If
            End If
        Next

        Array.Sort(num) 'Ordena 1,2,3
        For i = 3 To 1 Step -1 'i = es la cantidad de textbox con digitos
            Label1.Text = Label1.Text & "  " & num.GetValue(i)
        Next

    End Sub

RE:ordenar numeros

Publicado por daniel (1 intervención) el 07/05/2008 06:17:14
quiero ordenar 4 numeros de mayor a menor los numeros lo podre en un textbox y luego al oprimir el Commandbutton los ordenara en el mismo textbox si podrian decir me seria util. mesera util cual quier respuesta y gracias

RE:ordenar numeros

Publicado por FREDY ARRIETA (1 intervención) el 17/03/2009 18:53:05
NESECITO UN PROGRAMA EN VISUAL QUE ME ORGANIZE TRES NUMEROS DE MAYOR A MENOR ,DESPUES DE SER INTRODUCIDOS DESDE EL TECLADO YO LO HICE PERO CUANDO LE REPITO ALGUNOS DE LOS TRES VALORES ME GENERA UN HERROR MUCHAS GRACIAS POR SU ATENCION Y AGRADESCO SU AYUDA

RE:ordenar numeros

Publicado por JUAN PABLO  (1 intervención) el 05/10/2009 04:40:21
NESECITO UN PROGRAMA EN VISUAL QUE ME ORGANIZE TRES NUMEROS DE MAYOR A MENOR ,DESPUES DE SER INTRODUCIDOS DESDE EL TECLADO YO LO HICE PERO CUANDO LE REPITO ALGUNOS DE LOS TRES VALORES ME GENERA UN HERROR MUCHAS GRACIAS POR SU ATENCION Y AGRADESCO SU AYUDA

RE:ordenar numeros

Publicado por lidio (1 intervención) el 30/11/2009 21:52:21
ordenar numeros de 1 al 10 consecutivos.ejemplo:
12345678910
123456789
12345678
1234567
123456
12345
1234
123
12
1
de tal forma que quede asi

RE:ordenar numeros

Publicado por henry (1 intervención) el 13/12/2009 22:59:20
holas q tal ps queria que me`pueda orientarn como puedo ordenar numeros dentro de un texbox y que me lo muestre en ascendente o descendente si fuera posible que funcion aplicar a mi pequeña aplicacion.