Author | Message | Time |
---|---|---|
Lair | 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 | November 15, 2004, 2:17 AM |
drivehappy | [code] 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 [/code] Your For loop range is incorrect for the listbox. The ListCount property will return the number of items, starting at 1. | November 15, 2004, 2:57 AM |
The-FooL | Use code tags. | November 15, 2004, 2:59 AM |
Lair | Fixing the Loop made no difference, ..and code tags..? | November 15, 2004, 3:21 AM |
Zakath | When you post code to the forum, enclose it in [ code ] and [ /code ] tags. | November 15, 2004, 4:07 AM |
drivehappy | [quote author=Lair link=topic=9552.msg88900#msg88900 date=1100488886] Fixing the Loop made no difference, ..and code tags..? [/quote] What exactly is happening that shouldn't? | November 15, 2004, 5:08 AM |
Lair | After it is finished going through the For loop, it doesn't go onto whatever is after that, it just stops. [code] 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 [/code] | November 15, 2004, 10:38 PM |
drivehappy | [code] 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 [/code] 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) | November 15, 2004, 10:43 PM |
Lair | [quote author=drivehappy link=topic=9552.msg88895#msg88895 date=1100487421] Your For loop range is incorrect for the listbox. The ListCount property will return the number of items, starting at 1. [/quote] I originally had it at 0 and it wasen't working. That change helped, Yay! Thanks for the help. | November 15, 2004, 10:49 PM |
drivehappy | Yes, 0 would not work unless you made the correction I indicated earlier: [code]For pro3 = 0 To IntHld-1[/code] (Sorry if it was hard see) For better efficiency I would do this: [code] ... IntHld = frmMain.Safelist.ListCount - 1 For pro3 = 0 To IntHld SplitUsers = Split(frmMain.Safelist.List(pro3), " ")(0) & ", " ... [/code] Since it doesn't need to calculate the index each loop. However, it wouldn't make much of a dent in speed. | November 16, 2004, 12:16 AM |