Click to See Complete Forum and Search --> : range of a listbox


Dr. Inferno
February 2nd, 2000, 06:32 PM
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.

Aaron Young
February 2nd, 2000, 07:06 PM
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
ajyoung@pressenter.com
aarony@redwingsoftware.com