Valhalla Legends Archive

Programming => Battle.net Bot Development => Topic started by: Lair on November 14, 2004, 08:17 PM

Title: List Users Code
Post by: Lair on November 14, 2004, 08:17 PM
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
Title: Re: List Users Code
Post by: drivehappy on November 14, 2004, 08:57 PM

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.
Title: Re: List Users Code
Post by: The-FooL on November 14, 2004, 08:59 PM
Use code tags.
Title: Re: List Users Code
Post by: Lair on November 14, 2004, 09:21 PM
Fixing the Loop made no difference, ..and code tags..?
Title: Re: List Users Code
Post by: Zakath on November 14, 2004, 10:07 PM
When you post code to the forum, enclose it in [ code ] and [ /code ] tags.
Title: Re: List Users Code
Post by: drivehappy on November 14, 2004, 11:08 PM
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?
Title: Re: List Users Code
Post by: Lair on November 15, 2004, 04:38 PM
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
Title: Re: List Users Code
Post by: drivehappy on November 15, 2004, 04:43 PM

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)
Title: Re: List Users Code
Post by: Lair on November 15, 2004, 04:49 PM
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.
Title: Re: List Users Code
Post by: drivehappy on November 15, 2004, 06:16 PM
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.