textbox query

Steven Low

Active member
Joined
Apr 14, 2005
Messages
42
Programming Experience
1-3
hi guys


i need some hepl with this

basiclly i have two text boxes. what i like in tx1 i have a number say 2

and in tx2 what ever the the number is in tx1 i like it to x3. how would i do this? :confused:
 
Hello.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim A As Integer = CInt(TextBox1.Text)
TextBox2.Text = CStr(A * 3)
End Sub
OK.
 
TextBox Query.

Glad to help. Try this:-
VB.NET:
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar < "0"c OrElse e.KeyChar > "9"c Then
If e.KeyChar <> Convert.ToChar(System.Windows.Forms.Keys.Back) Then
If e.KeyChar <> "."c Then
e.Handled = True
End If
End If
End If
End Sub
KeyPress
Private Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Try
If TextBox1.Text <> "" Then
Dim a As Single = CSng(TextBox1.Text)
TextBox2.Text = CStr(a * 3)
Else
MsgBox("Wrong Input!")
End If
Catch ex As Exception
MsgBox("INPUT ERROR!")
End Try
End Sub

Put 2 TextBoxes on your Form. To get those Events: go to Left drop-down menu in Code Editor select TextBox1 then go to Right drop-down menu and select KeyPress. For the other do the same by selecting TextBox1 in L drop-down and in Right drop-down Select TextChanged.
In the TextBox1_KeyPress event the lines allow number, decimal point and backSpace.
Good Programming.
 
Back
Top