Foros del Web » Programación para mayores de 30 ;) » .NET »

NO sale como deberia

Estas en el tema de NO sale como deberia en el foro de .NET en Foros del Web. Tengo el siguiente programita sencillo y no sale como deberia El problema es: Ingrese 3 numeros, visualice los numeros ordenados en forma descendente Public Class ...
  #1 (permalink)  
Antiguo 23/10/2010, 17:09
Avatar de xArchangellx  
Fecha de Ingreso: octubre-2008
Ubicación: Peru
Mensajes: 208
Antigüedad: 15 años, 6 meses
Puntos: 5
Pregunta NO sale como deberia

Tengo el siguiente programita sencillo y no sale como deberia

El problema es: Ingrese 3 numeros, visualice los numeros ordenados en forma descendente

Public Class Form1
Dim m As String
Dim n1, n2, n3 As Integer


Private Sub BtnCalcular_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnCalcular.Click
n1 = TxtNumero1.Text
n2 = TxtNumero2.Text
n3 = TxtNumero3.Text

If n1 <= n2 & n2 <= n3 Then
m = n1 & " " & n2 & " " & n3
TxtResultado.Text = m

If n1 <= n3 & n3 <= n2 Then
m = n1 & " " & n3 & " " & n2
TxtResultado.Text = m

If n2 <= n1 & n1 <= n3 Then
m = n2 & " " & n1 & " " & n3
TxtResultado.Text = m

If n2 <= n3 & n3 <= n1 Then
m = n2 & " " & n3 & " " & n1
TxtResultado.Text = m

If n3 <= n1 & n1 <= n2 Then
m = n3 & " " & n1 & " " & n2
TxtResultado.Text = m

If n3 <= n2 & n2 < n1 Then
m = n3 & " " & n2 & " " & n1
TxtResultado.Text = m
End If
End If
End If
End If
End If
End If
End Sub

Private Sub BtnLimpiar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnLimpiar.Click
TxtNumero1.Clear()
TxtNumero2.Clear()
TxtNumero3.Clear()
TxtResultado.Clear()
TxtNumero1.Focus()
End Sub
End Class



Ayuda por favor
soy novato
  #2 (permalink)  
Antiguo 24/10/2010, 09:49
Avatar de gedarufi  
Fecha de Ingreso: diciembre-2008
Ubicación: Colombia
Mensajes: 540
Antigüedad: 15 años, 4 meses
Puntos: 22
Respuesta: NO sale como deberia

Cambia la asignacion de n1, n2 y n3 a esto

Código C#:
Ver original
  1. n1 = Convert.ToInt32(TxtNumero1.Text)
  2. n2 = Convert.ToInt32(TxtNumero2.Text)
  3. n3 = Convert.ToInt32(TxtNumero3.Text)

Última edición por gedarufi; 24/10/2010 a las 09:50 Razón: Error en el código
  #3 (permalink)  
Antiguo 25/10/2010, 04:04
 
Fecha de Ingreso: abril-2009
Mensajes: 121
Antigüedad: 15 años
Puntos: 4
Respuesta: NO sale como deberia

Hola:

Voy a describirte varios fallos:

1.- Si es Visual basic (que creo que sí) el "AND" es "AND" no &. El caracter ampersand "&" se usa para concatenar. Luego el IF sería:

If n1 <= n2 And n2 <= n3 Then

2.- Has concatenado varios IF pero lo has hecho mal. Reduciendo a tres IF:

If n1 <= n2 And n2 <= n3 Then
...
If n1 <= n3 And n3 <= n2 Then
...
If n2 <= n1 And n1 <= n3 Then
...
End If
End If
End If

Si en el primero no entra, no entra en ningún otro. Debería ser:

If n1 <= n2 And n2 <= n3 Then
...
ElseIf n1 <= n3 And n3 <= n2 Then
...
ElseIf n2 <= n1 And n1 <= n3 Then
...
End If

En definitiva, este sería el código de los IF:

If n1 <= n2 And n2 <= n3 Then
m = n1 & " " & n2 & " " & n3
txtResultado.Text = m
ElseIf n1 <= n3 And n3 <= n2 Then
m = n1 & " " & n3 & " " & n2
txtResultado.Text = m
ElseIf n2 <= n1 And n1 <= n3 Then
m = n2 & " " & n1 & " " & n3
txtResultado.Text = m
ElseIf n2 <= n3 And n3 <= n1 Then
m = n2 & " " & n3 & " " & n1
txtResultado.Text = m
ElseIf n3 <= n1 And n1 <= n2 Then
m = n3 & " " & n1 & " " & n2
txtResultado.Text = m
ElseIf n3 <= n2 And n2 < n1 Then
m = n3 & " " & n2 & " " & n1
txtResultado.Text = m
End If

Etiquetas: sale
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 20:47.