Visual Basic - Funciones Visual Basic

Life is soft - evento anual de software empresarial
 
Vista:

Funciones Visual Basic

Publicado por Álvaro (2 intervenciones) el 09/10/2009 01:32:07
Necesito crear una función que me muestre los digitos de un numero entero
y otra que me indique el máximo y el mínimo digito de un número entero. . .
espero respuestas, gracias
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:Funciones Visual Basic

Publicado por juan carlos (518 intervenciones) el 09/10/2009 05:29:05
hola Alvaro esto es lo que entendi
para sacar los digitos, mostrar el digito mas grande, y el mas chico:
para el ejemplo necesite
9 textbox y cuatro botones
escribe el numero en el text1
solo da click en el command1 hasta que el text1 se vacie
el command2 es para limpiar las cajas
el command3 es para sacar el digito mas grande
el command4 es para sacar el digito mas chico
codigo fuente:
el codigo es facil de entender
si deseas el codigo de ejemplo mi mail para mandartelo es:
[email protected]
==========================================
Private Sub Command1_Click()
c = Mid(Text1, 1, 2)
If Len(Text1) = 1 Then Text1.Text = "": Exit Sub
If Text2 = "" Then Text2.SelText = c: GoTo borrar
If (Text2 <> "") And (Text3 = "") Then Text3.SelText = c: GoTo borrar
If (Text3 <> "") And (Text4 = "") Then Text4.SelText = c: GoTo borrar
If (Text4 <> "") And (Text5 = "") Then Text5.SelText = c: GoTo borrar
If (Text5 <> "") And (Text6 = "") Then Text6.SelText = c: GoTo borrar
If (Text6 <> "") And (Text7 = "") Then Text7.SelText = c: GoTo borrar
If (Text7 <> "") And (Text8 = "") Then Text8.SelText = c: GoTo borrar
Exit Sub
borrar:
Text1.SetFocus
SendKeys "{home}"
SendKeys "{del}"
SendKeys "{del}"
End Sub

Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Text8.Text = ""
Text9.Text = ""
End Sub

Rem sacar el digito mas grande
Private Sub Command3_Click()
a = Len(Text9)
If a = 2 Then Text9.Text = "": Exit Sub
If Text2 > Text3 Then
Text9.SelText = Text2
ElseIf Text3 > Text2 Then
Text9.SelText = Text3
End If
If Text4 = "" Then Exit Sub
If Text4 > Text9 Then
Text9.Text = Text4
ElseIf Text4 < Text9 Then
Exit Sub
End If
If Text5 = "" Then Exit Sub
If Text5 > Text9 Then
Text9.Text = Text5
ElseIf Text5 < Text9 Then
Exit Sub
End If
If Text6 = "" Then Exit Sub
If Text6 > Text9 Then
Text9.Text = Text6
ElseIf Text6 < Text9 Then
Exit Sub
End If
If Text7 = "" Then Exit Sub
If Text7 > Text9 Then
Text9.Text = Text7
ElseIf Text7 < Text9 Then
Exit Sub
End If
If Text8 = "" Then Exit Sub
If Text8 > Text9 Then
Text9.Text = Text8
ElseIf Text8 < Text9 Then
Exit Sub
End If
End Sub

Rem sacar el digito mas chico
Private Sub Command4_Click()
a = Len(Text9)
If a = 2 Then Text9.Text = "": Exit Sub
If Text2 < Text3 Then
Text9.SelText = Text2
ElseIf Text3 > Text2 Then
Text9.SelText = Text3
End If
If Text4 = "" Then Exit Sub
If Text4 < Text9 Then
Text9.Text = Text4
ElseIf Text4 < Text9 Then
Exit Sub
End If
If Text5 = "" Then Exit Sub
If Text5 < Text9 Then
Text9.Text = Text5
ElseIf Text5 < Text9 Then
Exit Sub
End If
If Text6 = "" Then Exit Sub
If Text6 < Text9 Then
Text9.Text = Text6
ElseIf Text6 < Text9 Then
Exit Sub
End If
If Text7 = "" Then Exit Sub
If Text7 < Text9 Then
Text9.Text = Text7
ElseIf Text7 < Text9 Then
Exit Sub
End If
If Text8 = "" Then Exit Sub
If Text8 < Text9 Then
Text9.Text = Text8
ElseIf Text8 < Text9 Then
Exit Sub
End If
End Sub
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Funciones Visual Basic

Publicado por Anonimous (1 intervención) el 09/10/2009 17:02:35
Hola que tal.
A ver si esto tambien sirve.
Necesitas 2 variables para el max y el min. En numero esta en la variable "Numero"
Min=9
Max=0
For i=1 to Len (Cstr(Numero))
'muestras en un msgbox el caracter
msgbox (mid(Cstr(Numero),i,1)
'Puedes mostrarlo en algun objeto
'compruebas que el digito es mayor que el maximo
if val(mid(Cstr(Numero),i,1)>Max then
'en caso afirmativo lo guardas
Max=mid(Cstr(Numero),i,1)
end if
'compruebas si el digito es menor que el minimo
val(mid(Cstr(Numero),i,1)<Min then
'en caso afirmativo lo guardas
Min=Mid(Cstr(Numero),i,1)
end if
next i
al finalizar el bucle tendrás en la variables los dijitos maximos y minimos
espero que te sirva.
salu2
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar