Limiting Access to Text Boxes, List Boxes and Combo Boxes 
Author Message
 Limiting Access to Text Boxes, List Boxes and Combo Boxes

Urgent Help Required, All viable suggestions greatly appreciated

I am tyring to limit user input on a text box and combo box to be numberic
only.

Any suggestions,

I was using the following but this doesnt seem to work on combos or my text
boxes any more

Private Const GWL_STYLE = (-16)
Private Const ES_LOWERCASE = &H10&
Private Const ES_UPPERCASE = &H8&
Private Const ES_NUMBER = &H2000&

Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA"
(ByVal hwnd As Long, ByVal nindex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA"
(ByVal hwnd As Long, ByVal nindex As Long, ByVal dwNewLong As Long) As Long

Public Sub NumOnly(txtBox As TextBox)
Dim lStyle As Long
lStyle = GetWindowLong(txtBox.hwnd, GWL_STYLE)
lStyle = lStyle Or ES_NUMBER
lStyle = SetWindowLong(txtBox.hwnd, GWL_STYLE, lStyle)
End Sub



Sun, 20 May 2001 03:00:00 GMT  
 Limiting Access to Text Boxes, List Boxes and Combo Boxes
Have you tried this:

Function CheckNumeric (strNumber as String) as Boolean
        If Not IsNumeric(strNumber) and strNumber<>"" Then
                CheckNumeric=False
        Else
                CheckNumeric=True
        End If
End Function

--
Later,
Jody


http://www.visual-statement.com/vb



Quote:
> Urgent Help Required, All viable suggestions greatly appreciated

> I am tyring to limit user input on a text box and combo box to be
numberic
> only.

> Any suggestions,

> I was using the following but this doesnt seem to work on combos or my
text
> boxes any more

> Private Const GWL_STYLE = (-16)
> Private Const ES_LOWERCASE = &H10&
> Private Const ES_UPPERCASE = &H8&
> Private Const ES_NUMBER = &H2000&

> Private Declare Function GetWindowLong Lib "user32" Alias
"GetWindowLongA"
> (ByVal hwnd As Long, ByVal nindex As Long) As Long
> Private Declare Function SetWindowLong Lib "user32" Alias
"SetWindowLongA"
> (ByVal hwnd As Long, ByVal nindex As Long, ByVal dwNewLong As Long) As
Long

> Public Sub NumOnly(txtBox As TextBox)
> Dim lStyle As Long
> lStyle = GetWindowLong(txtBox.hwnd, GWL_STYLE)
> lStyle = lStyle Or ES_NUMBER
> lStyle = SetWindowLong(txtBox.hwnd, GWL_STYLE, lStyle)
> End Sub



Sun, 20 May 2001 03:00:00 GMT  
 Limiting Access to Text Boxes, List Boxes and Combo Boxes
Try changing the routine to (tested in VB5/VB6 on Win98):

Public Sub NumOnly(ctl As Control)

   Dim style As Long
   Dim hWndEdit As Long

   If TypeOf ctl Is TextBox Then

     'textbox, so just need the handle
      hWndEdit = ctl.hwnd

   ElseIf TypeOf ctl Is ComboBox Then

     'combobox, so need to obtain the handle
     'of its child edit part
      hWndEdit = FindWindowEx(ctl.hwnd, 0&, vbNullString, vbNullString)

   End If

  'if a valid handle
   If hWndEdit Then

     'get the edit control style
      style = GetWindowLong(hWndEdit, GWL_STYLE)

     'if its not already es_number, set it
      If style And Not ES_NUMBER Then

         style = style Or ES_NUMBER
         style = SetWindowLong(hWndEdit, GWL_STYLE, style)

      End If

   End If

End Sub

--

Randy Birch, MVP Visual Basic

http://www.mvps.org/vbnet/
http://www.mvps.org/ccrp/

To assist in maintaining this thread for the benefit of
others, please post any response to this newsgroup.

Quote:

>Urgent Help Required, All viable suggestions greatly appreciated

>I am tyring to limit user input on a text box and combo box to be numberic
>only.

>Any suggestions,

>I was using the following but this doesnt seem to work on combos or my text
>boxes any more

>Private Const GWL_STYLE = (-16)
>Private Const ES_LOWERCASE = &H10&
>Private Const ES_UPPERCASE = &H8&
>Private Const ES_NUMBER = &H2000&

>Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA"
>(ByVal hwnd As Long, ByVal nindex As Long) As Long
>Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA"
>(ByVal hwnd As Long, ByVal nindex As Long, ByVal dwNewLong As Long) As Long

>Public Sub NumOnly(txtBox As TextBox)
>Dim lStyle As Long
>lStyle = GetWindowLong(txtBox.hwnd, GWL_STYLE)
>lStyle = lStyle Or ES_NUMBER
>lStyle = SetWindowLong(txtBox.hwnd, GWL_STYLE, lStyle)
>End Sub



Sun, 20 May 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Limit subform combo box by selection in parent combo box

2. dialog box with list box or combo box

3. Bold text on certain items in a combo box / list box

4. How to list macro names in a combo box or a list box

5. Updating a combo box list W/limit to list selected

6. Want Access combo box to filter rowsource of another combo box

7. Columns in List box, when inserting text from text box (VBA)

8. VB List Box Versus Access List Box

9. Combo box spawning list box

10. Examples of OwnerDrawn for Combo Box / List Box / Menu / Toolbars

11. List Box and Combo box

12. adding to a combo box or list box

 

 
Powered by phpBB® Forum Software