Public Class Form1
Dim suma As Integer
'EN CARREGAR EL FORMULARI
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'DESACTIVEM TEXTBOX2
TextBox2.Enabled = False
End Sub

'EN PREMER UNA TECLA
Private Sub TextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox1.KeyPress
'SI NO ES NUMERO NI TAB NI INTRO NI BKSPC NI DEL
If ((Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57) And (Asc(e.KeyChar) <> 13 And Asc(e.KeyChar) <> 9 And Asc(e.KeyChar) <> 8 And Asc(e.KeyChar) <> 10)) Then
'ANUL.LO ENTRADA
e.Handled = True
Else
'SI ES INTRO O TAB
If (Asc(e.KeyChar) = 13 Or Asc(e.KeyChar) = 9) Then
'ACTIVEM TEXTBOX2
TextBox2.Enabled = True
'SALTO A TEXTBOX2
TextBox2.Focus()
'DESACTIVEM TEXTBOX1
TextBox1.Enabled = False
End If
End If
End Sub

Private Sub TextBox2_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox2.KeyPress
'SI NO ES NUMERO NI TAB NI INTRO NI BKSPC NI DEL
If ((Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57) And (Asc(e.KeyChar) <> 13 And Asc(e.KeyChar) <> 9 And Asc(e.KeyChar) <> 8 And Asc(e.KeyChar) <> 10)) Then
'ANUL.LO ENTRADA
e.Handled = True
Else
'SI ES INTRO O TAB
If (Asc(e.KeyChar) = 13 Or Asc(e.KeyChar) = 9) Then
'DESACTIVEM TEXTBOX2
TextBox2.Enabled = False
'CALCULO SUMA
suma = Val(TextBox1.Text) + Val(TextBox2.Text)
'MOSTREM RESULTAT
Label1.Text = Str(suma)
End If
End If
End Sub

'EN AGAFAR FOCUS ATENCIO
Private Sub TextBox2_GotFocus(sender As Object, e As EventArgs) Handles TextBox2.GotFocus
'POSEM FONS GROC
TextBox2.BackColor = Color.Yellow
End Sub
End Class

Darrera modificació: dimecres, 3 de maig 2023, 08:41