CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 1999
    Location
    Scotland
    Posts
    7

    Filter Input to Textbox Within an ActiveX Control

    I have a Textbox control within an ActiveX Control. I wish any input to the textbox to be numeric only. A decimal point is permitted but only once. The following code is included in my Textbox keypress event:

    Private Sub txtValue_KeyPress(KeyAscii As Integer)

    'Allow the backspace key to pass through but only allow the
    'decimal point key to pass through if it isn't in the string already...
    If KeyAscii = 46 And InStr(txtValue.Text, ".") = 0 Or KeyAscii = 8 Then
    Exit Sub
    'Only update if the Enter Key is Pressed...
    Else
    'Only let number keys through...
    If KeyAscii < 48 Or KeyAscii > 57 Then
    'MsgBox "Numeric Input Only...!", vbOKOnly, "Numeric Input Error"
    KeyAscii = 0
    End If
    End If

    End Sub

    This code appears to work fine in a textbox on its own. Problem is it gives bizarre results and does not accept a decimal point when included in my control!!!

    Any pointers would be much appreciated...


  2. #2
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: Filter Input to Textbox Within an ActiveX Control

    I've just tried your code on a simple usercontrol (ie. one text box called txtValue) and put it into a simple project.

    It all worked fine ! - Maybe something else is wrong in your UserControl / Sample Project

    Chris Eastwood

    CodeGuru - the website for developers
    http://codeguru.developer.com/vb

  3. #3
    Join Date
    Jun 1999
    Location
    Scotland
    Posts
    7

    Re: Filter Input to Textbox Within an ActiveX Control

    Oops, My mistake... you were correct Chris

    I replied to you through a private message describing my problem.

    Thanks for taking the time to look at my problem!!


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured