Cambiar color textbox dependiendo del dato

Quisiera adaptar un textbox1 a los siguiente parámetros, que si en este hay un valor menor que 20 se ponga el fondo en rojo y me aparezca en otro textbox2 que diga BAJO PESO, entre 21 y 40 fondo verde y textbox2 Peso normal, entre 41 y 60 fondo naranja, textbox2 Obeso,,, mayor de 60 fondo rojo textbox2 Sobrespeso.
texbotx1 <=20 fondo rojo                textbox2=Bajode peso      
textbox1 >20 y <40 fonfo verde       textbox2=Peso normal
textbox1 >40 y >60 fondo naranja   textbox2=Obeso                                        textbox1>60 fondo rojo                  textbox2=Sobrepeso                  
Agradezco la colaboración

1 respuesta

Respuesta
1
Crea un nuevo proyecto y agrega 2 textbox (nombres por defecto text1 y text2)
Private Sub Text1_Change()
If IsNumeric(Text1.Text) Then
    If Text1.Text <= 20 Then
        Text1.BackColor = vbRed
        Text2.Text = "Bajo peso"
    ElseIf Text1.Text > 20 And Text1.Text <= 40 Then
        Text1.BackColor = vbGreen
        Text2.Text = "Peso Normal"
    ElseIf Text1.Text > 40 And Text1.Text <= 60 Then
        Text1.BackColor = &H80FF&
        Text2.Text = "Obeso"
    ElseIf Text1.Text > 60 Then
        Text1.BackColor = vbRed
        Text2.Text = "Sobrepeso"
    End If
Else
    Text1.BackColor = &H80000005
End If
End Sub
O se me olvido limpiar el text2...
Después de:
...
Else
    Text1.BackColor = &H80000005
agrega esto----> text2.text=""
end if
end Sub
Ahora si..

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas