Link to home
Start Free TrialLog in
Avatar of stephenz43
stephenz43

asked on

keypress question

Good Morning Troops

I have the following in the Keypress event for a textbox: I would like for it to handle other textboxs. As written it refers to only txtRentalpmt.text which imakes the handles statement ( handles anothertextbox.kepress) dependent on txtRemtalPmt.text

 Dim IntegerOnly As Boolean
        'Dim PositiveOnly As Boolean
        Dim KeyAscii As Integer
        KeyAscii = Asc(e.KeyChar) ' NOTE: used as a flag when = 0 to mark bad values
        Select Case KeyAscii
            Case 48 To 57, 8, 13 ' Digits 0 - 9, Backspace, CR.
            Case 46 ' Period (decimal point).
                If IntegerOnly Then
                    KeyAscii = 0
                Else
                    'If we already have one period, throw it away
                    If InStr(txtRentalPmt.Text, ".") <> 0 Then         '<-----------------Cant be dependent on this textbox
                        KeyAscii = 0
                    End If
                End If
            Case Else ' Provide no handling for other keys.
                KeyAscii = 0
        End Select
        If KeyAscii = 0 Then
            e.Handled = True
        Else
            e.Handled = False
        End If
Avatar of Kinger247
Kinger247

Handle all the textboxes in the handles part like:

    Private Sub KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress, TextBox2.KeyPress, TextBox3.KeyPress

    End Sub
and change :

txtRentalPmt.Text

to

directcast(sender,textbox).text
ASKER CERTIFIED SOLUTION
Avatar of Kinger247
Kinger247

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of stephenz43

ASKER

Thank you
no problem.