• Welcome to Valhalla Legends Archive.
 

List Users Code

Started by Lair, November 14, 2004, 08:17 PM

Previous topic - Next topic

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

drivehappy


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.

The-FooL


Lair

Fixing the Loop made no difference, ..and code tags..?

Zakath

When you post code to the forum, enclose it in [ code ] and [ /code ] tags.
Quote from: iago on February 02, 2005, 03:07 PM
Yes, you can't have everybody...contributing to the main source repository.  That would be stupid and create chaos.

Opensource projects...would be dumb.

drivehappy

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?

Lair

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

drivehappy


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)

Lair

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.

drivehappy

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.