Valhalla Legends Forums Archive | Battle.net Bot Development | list box's

AuthorMessageTime
TeEhEiMaN
Alright List BoX's! Arnt tehy fun! :P

I need some help, How would I be Able to do like

If username = 'A name from a like box' List2.List Then
Do this

For Like a datatbase or a shitlist or something.

Know what I mean?

If you dont undertsand reply and Ill try and be more specifec
June 27, 2003, 3:48 AM
iago
It's a really bad idea to use a listbox for something that doesn't require one, like this. The best way to do this is with a hashtable, but those are rather difficult to do in visual basic. The best way to do it would be to use an array of strings.

[code]dim Shitlist as string(0 to 1000) ' this might be wrong, I haven't used vb in awhile

private function CheckShitlist(name as string) as boolean
for i = 0 to 1000
if Shitlist(i) = name then
checkshitlist = true
exit function
end if
next
end function
[/code]

This can only hold 1000 names, but it should give you the idea. Look up redim if you want to be able to dynamically expand your list.
June 27, 2003, 6:54 AM
Eternal
If you are storing data in a listbox, you need to create a simple loop to cycle through each entry and compare it to a string you pass in (such as an account name). I am going to assume you are using Visual Basic (something tells me you are!) If you can, do a google search for Listbox's properties...familiarise yourself with what the basic ones do.

Firstly, I would set up a Public Function and declare it as a Boolean, which will return a true or false state.

[code]Public Function checkSafeTag (StrAccountName) as Boolean[/code]

The loop is very simple. Listboxes have an index of 0 (which means they count from 0 upwards, they don't start at 1) so the loop has to consider that. Ie:

[code]For i = 0 to frmName.ListboxName.ListCount - 1[/code]

Of course, you should declare your variables etc. Ok, here's a bit of code that I wrote for checking a safetag. I prefer to use 'needle' & 'haystack' variable names and declare them first, it makes looking at large bits of code easier.

[code] Public Function CheckSafeTag(ByVal StrAccountName As String) As Boolean

Dim safe As Boolean
Dim haystack, needle As String
Dim LBMax As Integer

haystack = LCase(strAccountName)
safe = False
LBMax = frmName.lstListBoxName.ListCount - 1

For i = 0 To LBMax
needle = LCase(frmName.lstListBoxName.list(i))

If needle = haystack Then
safe = True
Exit For
End If

Next i
CheckSafeTag = safe
End Function[/code]

You should then add a line of code to the 'user joins' part of your bot to check the Function and see if it is true or false.

[code] If frmName.CheckSafeTag(strAccountName) Then safe = true[/code]

Hope it helps...
June 27, 2003, 7:07 AM
Eternal
lol, posted the same time as Iago... ;D
June 27, 2003, 7:14 AM
Camel
[quote author=iago link=board=17;threadid=1710;start=0#msg13055 date=1056696854]The best way to do it would be to use an array of strings.[/quote]
be careful though, arrays take forever to resize in vb when they get real big. it's fine to use them if you're only storing 40 or 50 strings, but alternative methods (such as databases) become favorable when the list is in high demand (simply because it takes forever to resize the arrays).
June 27, 2003, 7:14 AM
iago
The best way to do it would be a hash table. I don't know if vb supports them in any internal way (like perl's %var{thingy} variables or I think java uses it for vectors), but if there is a way that is probably best. You'll have to research how to write a hashtable in vb, though.
June 27, 2003, 9:51 AM
Adron
You should probably be using a VB collection. I don't know how they are implemented, but they behave much the same as a stl map. The only annoying part is with finding a name that's not in the collection.
June 27, 2003, 2:40 PM
Camel
[quote author=iago link=board=17;threadid=1710;start=0#msg13061 date=1056707495]
The best way to do it would be a hash table. I don't know if vb supports them in any internal way (like perl's %var{thingy} variables or I think java uses it for vectors), but if there is a way that is probably best. You'll have to research how to write a hashtable in vb, though.
[/quote]

vb doesn't support hashes, but one could write a couple of functions in conjunction with a couple of arrays to emulate a hash table.

p-vb-code:
[code]Dim HashIDs() As String
Dim HashValues() As <whatever>

Function FindArrayElementMatching(DesiredValue As String, ValueList() As String) As Long
Dim X as Long
FindArrayElementMatching = -1
For X = LBound(ValueList) To UBound(ValueList)
If ValueList(X) = DesiredValue Then
FindArrayElementMatching = X
Exit Function
End If
Next
End Function

Function GetHashValue(HashID As String) As <whatever>
Dim ID as Long
ID = FindArrayElementMatching(HashID, HashIDs())
If ID = -1 Then Debug.Assert False 'this is bad
GetHashValue = HashValues(ID)
End Function

Sub SetHashValue(HashID As String, HashValue As <whatever>)
Dim ID as Long
ID = FindArrayElementMatching(HashID, HashIDs())
If ID = -1 Then Debug.Assert False 'no record exists, must redim HashValues() and HashIDs() to add another value
HashValues(ID) = HashValue
End Sub[/code]

[edit] hrm, now that's not really pcode :)
June 27, 2003, 9:29 PM

Search