Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

keypress question

Posted on 2006-11-19
5
Medium Priority
?
336 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses
Course of the Month9 days, 4 hours left to enroll

877 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