• Welcome to Valhalla Legends Archive.
 

list box's

Started by TeEhEiMaN, June 26, 2003, 10:48 PM

Previous topic - Next topic

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

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.

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


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.
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Eternal

#2
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.

Public Function checkSafeTag (StrAccountName) as Boolean

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:

For i = 0 to frmName.ListboxName.ListCount - 1

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.

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


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.

If frmName.CheckSafeTag(strAccountName) Then safe = true

Hope it helps...
^-----silly Brit
-----------------------------
www.brimd.com

Eternal

lol, posted the same time as iago...  ;D
^-----silly Brit
-----------------------------
www.brimd.com

Camel

Quote from: iago on June 27, 2003, 01:54 AMThe best way to do it would be to use an array of strings.
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).

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.
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


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.

Camel

#7
Quote from: iago on June 27, 2003, 04:51 AM
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.

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:
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


[edit] hrm, now that's not really pcode :)