|
-
Apr 19th, 2002, 09:10 AM
#1
Thread Starter
Addicted Member
Problems with listBox???
'Lo...
having trouble rigging a listbox to handle a variable request...
my code below is 'hardwired' to handle a list of up to 3 items..
Code:
Private Sub listClients_Click()
If listClients.Selected(0) Then
txtSelected.Text = listClients.Text
End If
If listClients.Selected(1) Then
txtSelected.Text = listClients.Text
End If
If listClients.Selected(2) Then
txtSelected.Text = listClients.Text
End If
End Sub
But what if I don't know the length of the listbox?
Here's what I've tried that doesn't work...
Code:
Private Sub listClients_Click()
DIM r, k
k = listClients.listcount
For r = 0 to k
If listClients.Selected(r) Then
txtSelected.Text = listClients.Text
End If
Next r
End Sub
Which gives me a complie error that says that there's an invalid property array index...and it then points to the "If listClients.Selected(r) then" line...
Can someone fine tune this or point me in the right direction?
Thanks...
Jim
Jim Rudnick
MCSD
KKT INTERACTIVE
www.kkti.com
-
Apr 19th, 2002, 09:13 AM
#2
Addicted Member
make
k=listclients.listcount-1
because the listbox starts at zero, not one.
-George
-
Apr 19th, 2002, 09:18 AM
#3
Make sure txtSelected is set to MultiLine.
VB Code:
Private Sub listClients_Click()
Dim i As Long
For i = listClients.ListCount - 1 To 0 Step -1
If listClients.Selected(i) = True Then
txtSelected.Text = listClients.List(lstClients.ListIndex)
End If
Next
End Sub
-
Apr 19th, 2002, 09:18 AM
#4
Thread Starter
Addicted Member
Thanks!
Hmm....
Thanks...remembered to start my hardwired one with (0) but never thought of that fix!
Tip-O-the-Hat!
Jim
Jim Rudnick
MCSD
KKT INTERACTIVE
www.kkti.com
-
Apr 19th, 2002, 09:18 AM
#5
Fanatic Member
Why are you checking for its list index?????
all you need is:
txtSelected.Text = listClients.Text
This will work with any number of entries... I dont see why you have the if statements?
Leather Face is comin...
MCSD
-
Apr 19th, 2002, 10:08 AM
#6
Thread Starter
Addicted Member
<grin> Never mind...
Nevermind -- got it myownself!
;-)
Jim
Jim Rudnick
MCSD
KKT INTERACTIVE
www.kkti.com
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
|