Solved

keypress question

Posted on 2006-11-19
5
310 Views
Last Modified: 2010-04-23
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
0
Comment
Question by:stephenz43
  • 4
5 Comments
 
LVL 10

Expert Comment

by:Kinger247
ID: 17975764
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
0
 
LVL 10

Expert Comment

by:Kinger247
ID: 17975768
and change :

txtRentalPmt.Text

to

directcast(sender,textbox).text
0
 
LVL 10

Accepted Solution

by:
Kinger247 earned 500 total points
ID: 17975778
Sorry to quick on the enter key , anyway ...

so the statement will look like ..

If InStr(directcast(sender,textbox).text, ".") <> 0 Then      
  KeyAscii = 0
End If

or change it to:

If DirectCast(sender, TextBox).Text.Contains(".") Then
  KeyAscii = 0
End If
0
 

Author Comment

by:stephenz43
ID: 17975820
Thank you
0
 
LVL 10

Expert Comment

by:Kinger247
ID: 17975824
no problem.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question