This code seemingly should work, but doesn't.
My users are stored in a Listbox, each user on a new line. After this is a comment on their access, and who added them Ex)
Lair ABG Default
This code is ment to take all the users and display them.
(every first word on the line)
Thanks in advance if you can offer any assistance.
Public Sub ListUsers()
Dim Users As String, SplitUsers As String, IntHld As Integer
IntHld = frmMain.Safelist.ListCount
For pro3 = 0 To IntHld
SplitUsers = Split(frmMain.Safelist.List(pro3), " ")(0) & ", "
Users = Users & SplitUsers
Next pro3
modqueue.add Users
End Sub
Public Sub ListUsers()
Dim Users As String, SplitUsers As String, IntHld As Integer
IntHld = frmMain.Safelist.ListCount
For pro3 = 0 To IntHld-1
SplitUsers = Split(frmMain.Safelist.List(pro3), " ")(0) & ", "
Users = Users & SplitUsers
Next pro3
modqueue.add Users
End Sub
Your For loop range is incorrect for the listbox. The ListCount property will return the number of items, starting at 1.
Use code tags.
Fixing the Loop made no difference, ..and code tags..?
When you post code to the forum, enclose it in [ code ] and [ /code ] tags.
Quote from: Lair on November 14, 2004, 09:21 PM
Fixing the Loop made no difference, ..and code tags..?
What exactly is happening that shouldn't?
After it is finished going through the For loop, it doesn't go onto whatever is after that, it just stops.
Public Sub ListUsers()
Dim Users As String, SplitUsers As String, IntHld As Integer
IntHld = frmMain.Safelist.ListCount
For pro3 = 1 To IntHld
SplitUsers = Split(frmMain.Safelist.List(pro3), " ")(0) & ", "
Users = Users & SplitUsers
Next pro3 <-- stops here after it is done going through the listbox
modQueue.Add Users <-- It never does this or anything else i put after
End Sub
Public Sub ListUsers()
Dim Users As String, SplitUsers As String, IntHld As Integer
IntHld = frmMain.Safelist.ListCount
For pro3 = 1 To IntHld
SplitUsers = Split(frmMain.Safelist.List(pro3-1), " ")(0) & ", "
Users = Users & SplitUsers
Next pro3 <-- stops here after it is done going through the listbox
modQueue.Add Users <-- It never does this or anything else i put after
End Sub
Since you didn't use For pro3 = 0 to IntHld-1, when this method is called:
frmMain.Safelist.List(pro3) it expects a 0 based index. So try this:
frmMain.Safelist.List(pro3-1)
Quote from: drivehappy on November 14, 2004, 08:57 PM
Your For loop range is incorrect for the listbox. The ListCount property will return the number of items, starting at 1.
I originally had it at 0 and it wasen't working.
That change helped, Yay! Thanks for the help.
Yes, 0 would not work unless you made the correction I indicated earlier:
For pro3 = 0 To IntHld-1
(Sorry if it was hard see)
For better efficiency I would do this:
...
IntHld = frmMain.Safelist.ListCount - 1
For pro3 = 0 To IntHld
SplitUsers = Split(frmMain.Safelist.List(pro3), " ")(0) & ", "
...
Since it doesn't need to calculate the index each loop. However, it wouldn't make much of a dent in speed.