CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2000
    Posts
    10

    range of a listbox

    I need code for the following procedures:
    1) Make it so the user can only enter numbers into a listbox when prompted for them. They cannot enter any text besides numbers.
    2) Once they enter numbers, I find the range between them. The range is the difference between the smallest and highest number in the listbox.
    3) Make it so a user can only enter numbers in a textbox.




  2. #2
    Join Date
    Sep 1999
    Location
    Red Wing, MN USA
    Posts
    312

    Re: range of a listbox

    To make a Textbox only accept Numeric Data Try this:
    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
    private Const GWL_STYLE = -16
    private Const ES_NUMBER = &H2000

    private Sub Form_Load()
    Dim oCTRL as Control
    for Each oCTRL In Controls
    If TypeOf oCTRL is TextBox then
    If UCase(oCTRL.Tag) = "N" then
    Call SetWindowLong(oCTRL.hwnd, GWL_STYLE, _
    GetWindowLong(oCTRL.hwnd, GWL_STYLE) Or ES_NUMBER)
    End If
    End If
    next
    End Sub


    This will make any Textbox on your Form who's Tag Property has been set to N Numeric Only.

    To make a user Enter a Number into a List, use a Textbox set to Numeric Only.

    To find the Range of Numbers Entered, the easiest way would be to Format the Number the User Entered to include Preceeding Zeros, then have the List Sorted, the Lowest Value will be the First Item and the Highest would be the Last.


    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]
    Aaron Young
    Senior Programmer Analyst (Red Wing Software)
    Certified AllExperts Expert

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