Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why isnt this working? Textbox values..

Status
Not open for further replies.

RocAFella2007

Technical User
Mar 21, 2007
45
GB
Hi, basically I have two textboxes. Text is entered into textbox1, whenever a numeric value is entered in textbox1 I want that value shown in textbox2, I want this done straight away, also I want the default value of textbox2 to be '0'.

I have the following coding:

Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
TextBox2.Clear()
For Each c As Char In TextBox1.Text
If Char.IsDigit(c) Then
TextBox2.AppendText(c)
End If
Next
End Sub

It is working but could somebody help me on the default value part? Thanks
 
Set the Text value for the control = 0 in the designer. Then change the code to this:

Code:
        TextBox2.Clear()
        Dim bNumericFound As Boolean = False
        For Each c As Char In TextBox1.Text
            If Char.IsDigit(c) Then
                TextBox2.AppendText(c)
                bNumericFound = True
            End If
        Next
        If Not bNumericFound Then
            TextBox2.Text = 0
        End If

Senior Software Developer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top