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
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
and change :
txtRentalPmt.Text
to
directcast(sender,textbox) .text
txtRentalPmt.Text
to
directcast(sender,textbox)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you
no problem.
Private Sub KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPr
End Sub