|
-
Feb 13th, 2008, 06:04 PM
#1
Re: Arrrrgh...List Box Irritation
I think this issue is resolved, though...What I didn't understand is that when the form is first executed, the list index is -1, no matter what value is displayed to the user.
When form is first executed there is no value displayed to the user. The user sees everything in the listbox that is within the height of the listbox and no item is selected by default.
You cannot do this
intSpcSize = CInt(List1.Text)
if you have not selected which item in the listbox you want. List1.Text is null if you do not select an item and you will get the type mismatch.
All you have to do is to accept this as is.
-
Feb 13th, 2008, 06:41 PM
#2
Thread Starter
Addicted Member
Re: Arrrrgh...List Box Irritation
Ah, I see...My box is tiny, so only the one value shows..
You are saying if it was long I'd see that no value is selected...
BTW, the reason I'm using this box is I am scared to allow users to just put in any value they want, I've kinda learned not to trust them...
Is there some other better way to present a user with a choice of 20+ numerical values ?
-
Feb 13th, 2008, 10:01 PM
#3
Re: Arrrrgh...List Box Irritation
 Originally Posted by prginocx
Ah, I see...My box is tiny, so only the one value shows..
You are saying if it was long I'd see that no value is selected...
BTW, the reason I'm using this box is I am scared to allow users to just put in any value they want, I've kinda learned not to trust them...
Is there some other better way to present a user with a choice of 20+ numerical values ?
Try using a combobox instead of a listbox rather than forcing listbox to perform what it wasn't designed for (square peg, round hole analogy).
Code:
Option Explicit
Private Sub cmdTest_Click()
If cboNums.ListIndex <= 0 Then 'if non-numeric text selected or no selection
MsgBox "Please select a value!"
Else
MsgBox CInt(cboNums.Text)
End If
End Sub
Private Sub Form_Load()
cboNums.AddItem "Select a value" 'test later that this isn't selected. Can be zero length string rather than message
cboNums.AddItem "1"
cboNums.AddItem "2"
cboNums.AddItem "3"
cboNums.AddItem "4"
cboNums.AddItem "5"
cboNums.ListIndex = 0
End Sub
Last edited by leinad31; Feb 13th, 2008 at 10:08 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|