Solved

keypress question

Posted on 2006-11-19
5
306 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

773 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