Thread

Seprating words in a ListBox (Sdk)

Seprating words in a ListBox // Sdk

1  |  

trekkerx

Apr 9, 2001, 6:56pm
Dose anyone know how to get words from a List box, and then have the bot
search for ppl saying words in it then haveing the bot eject them for
saying it? The list box is a list of eject words, and i cant get the bot
to pick out certan words then find them in the listbox, If anyone can
please tell me.

~ TrekkerX

m a k a v e l i

Apr 9, 2001, 8:01pm
Brant is the only one I have seen pull that off, in his Paintball Bot. It
is a very complicating scheme to do.

m a k a v e l i

Apr 9, 2001, 8:25pm
Add a Timer to the form and label it "timCheck" then:

Private Sub sdk_EventChat()

timCheck.Interval = 1000

timCheck.Enabled = True

End Sub

Private Sub timCheck_Timer()

Message = LCase(sdk.AwChatMessage)

If lstWord.ListCount = 0 Or lstWord.ListIndex = lstWord.ListCount - 1
Then
timCheck.Enabled = False
Exit Sub
End If

If X = "" Then
X = 0
lstWord.ListIndex = X
Else
X = (X + 1)
lstWord.ListIndex = X
End If

Word = lstWord.Text

If InStr(Message, Word) <> 0 Then

sdk.AwEjectDuration = (5 * 60)

sdk.AwEjectSession = sdk.AwChatSession

If sdk.AwWorldEject Then
MsgBox "Unable to ejection session " & sdk.AwChatSession
Else
MsgBox "Session " & sdk.AwChatSession & " ejected"
End If

End If
End Sub

Add a Module named anything and add this to the Module:

Global X as Integer
Global Message

j b e l l

Apr 9, 2001, 9:23pm
i did when i knew vb.. lol.. haven't used it for over four years.. *sigh*

--
--
J B E L L
http://platinum.awjbell.com
G O I N G P L A T I N U M


[View Quote]

mrgrimm

Apr 9, 2001, 9:54pm
This method wont work. It allows for other events to be processed while
checking the words in the ListBox.

Instead, try something like this:

lstWords = ListBox containing words/phrases to check for

Public Function ContainsWord(ByRef lstBox As ListBox, ByVal strMessage As
String) As String

Dim i As Integer

' Loop thru the list items
For i = 0 To lstBox.ListCount
' Check if the message contains the value in the list item
If InStr(1, strMessage, LCase(lstBox.List(i)), vbTextCompare) > 0
Then
' Return the found value
ContainsWord = lstBox.List(i)
Exit Function
End If
Next i

ContainsWord = ""

End Function

Private Sub AwSdkOcx_EventChat()

' Check the message
If ContainsWord(lstWords, AwSdkOcx.AwChatMessage) <> "" Then
' The message contained one of the words

' Eject the session
AwSdkOcx.AwEjectDuration = 5 * 60
If AwSdkOcx.AwWorldEject Then
MsgBox "Unable to ejection session " & AwSdkOcx.AwChatSession
Else
MsgBox "Session " & AwSdkOcx.AwChatSession & " ejected"
End If

End If

End Sub

[View Quote]

grimble

Apr 9, 2001, 10:08pm
makaveli,

There are a number of key problems with this code. The two major ones are
listed below:

Firstly, its bizarre! What's with the timer?? Ever heard of a loop? That
timer is running asynchronously along side the retrieval of the AW events,
so its going to be totally arbitrary which messages are going to be checked.
The code is basically going to check for the next word in the list (after
the current one), in the last chat message received, every second. Chat
messages will often be missed completely and ONLY be scanned for all the
words if no-one says anything else while it goes through the loop.

Secondly, (apart from the fact that it's not an answer to what TrekkerX
wants because of the previous point), ListIndex is only used to position the
selection. Its a UI thing and not something for setting the current record
so that you can use the Text property.

This isn't a difficult task ... The code you really want goes something like
this ... which isn't how I would actually do it - see point later in post -
but its comparative to your example (again, in VB with your control names
for continuity):

Private Sub sdk_EventChat()

Dim messageChat As String
Dim indexEjectWord As Long

messageChat = LCase(sdk.AwChatMessage)

For indexEjectWord = 0 To lstWord.ListCount - 1
If InStr(messageChat, LCase(lstWord.List(indexEjectWord))) Then

'<do eject handling code here>

End If
Next indexEjectWord

End Sub

This is still going to fall foul of words within words (there's a place in
the UK called Scunthorpe!!) so additional logic needs to go in there to
check for whole words including handling the start/end of the chat message
and punctuation - so you can't just check for " " &
lstWord.List(indexBadWord) & " " either.

Personally, I am a believer in user interface components being JUST for user
interface purposes ... displaying/entering information and interactivity. My
view is that the prime copy of the data belongs in the guts of the
application, not in a visual control. So actually, I would have a ReDim'd
array of Strings or a Collection holding the words, and that store is then
used to populate the listbox on startup. Just my upbringing I guess ...
different people do things in different ways.

BTW, a small piece of advice. See the Dim statements? Use them ... Variants
suck! You should never find code like this ANYWHERE in an application ...
large or small ... it just doesn't make any sense.

If X = "" Then X = 0

If you MUST use variants (which is extremely lazy and unnecessarily adds to
the underlying processing), use the IsEmpty(varName) to do this check.

Grims.



[View Quote]

grimble

Apr 9, 2001, 10:12pm
Ack!!!

'<do eject handling code here>

should read

'<do eject handling code here>
Exit For

Sorry ....

Grims


[View Quote]

grimble

Apr 9, 2001, 10:16pm
GRRRR .... it took me so long to type my post that you beat me to it !!

Just for the reader ... (accidental omissions I'm sure - MrGrimm is better
that this)

For i = 0 To lstBox.ListCount -1

and

If ContainsWord(lstWords, LCase(AwSdkOcx.AwChatMessage)) <> "" Then

Grims :o)



[View Quote]

m a k a v e l i

Apr 9, 2001, 11:17pm
Well, was thinking it wasn't the easiest or best way to do it. It was a on
the spot thing, I am not as experienced as you two so I used the way I know
of doing it.

1  |  
Awportals.com is a privately held community resource website dedicated to Active Worlds.
Copyright (c) Mark Randall 2006 - 2024. All Rights Reserved.
Awportals.com   ·   ProLibraries Live   ·   Twitter   ·   LinkedIn