Valhalla Legends Forums Archive | Battle.net Bot Development References | [VB]Creating Whisper Windows

AuthorMessageTime
MailMan
So far I've got the simple part done. I created a whisper window form, and when I recieve a whisper, I did something along the lines of:

[code]
Dim whisper_window as new WhisperForm
With whisper_window
.caption = from_this_person
.show
End with
[/code]

My question is, is there a way to check your currently open forms to see if there's already an open window for that user. I set the caption of each form to the name of the person whispering me, so I could search for the forms or something.. but I'm not sure how.

Thanks in advance.
March 25, 2003, 10:18 PM
Camel
dim whisperwindows() as WhisperForm
...
whisperwindows(x) = new WhisperForm
March 26, 2003, 12:09 AM
St0rm.iD
Add all your whisperforms to a Collection, with their key as the username. Search the Collection for the username, if it doesn't exist, add a new one, otherwise get it from the Collection and dispatch the event.
March 26, 2003, 12:26 AM
Etheran
inefficient!!! But definatly practical and easy. :)
March 26, 2003, 1:02 AM
CupHead
Rather than waste more memory with an extra array or collection, you can use VB's predefined collection Forms and cycle through that. My whisper window code looks something like this:

[code]
Dim j As Integer
If frmWhisper.Count = 0 Then Call CreateWWindow(Username)
For j = 0 To Forms.Count - 1
If Forms(j).Tag = Username Then
'Forms(j) is the form that already exists with that user's whispers.
End If
Next j
Call CreateWWindow(Username)
j = Forms.Count - 1
[/code]
March 26, 2003, 2:09 AM
MailMan
Thanks again, CupHead.
March 26, 2003, 3:15 AM
Camel
[quote author=CupHead link=board=17;threadid=819;start=0#msg6418 date=1048644543]
[code]
If frmWhisper.Count = 0 Then Call CreateWWindow(Username)
[/code]
[/quote]

you don't really need that line; if frmWhisper.Count is 0, it will jump over the for looa and call that function _again_
March 27, 2003, 10:01 PM
CupHead
[code][/code][quote]you don't really need that line; if frmWhisper.Count is 0, it will jump over the for looa and call that function _again_ [/quote]

Actually, idiot, the Forms collection contains *all* available forms therefore no, it will cycle through the loop for each available form including those that are not whisper windows. By adding that check before the loop, I can avoid having to cycle through when the program knows that no frmWhispers exist.

Anyway, for Camel, quick VB lesson:
[code]
Dim j As Integer
If frmWhisper.Count = 0 Then Call CreateWWindow(Username) '#1
For j = 0 To Forms.Count - 1
If Forms(j).Tag = Username Then
'Forms(j) is the form that already exists with that user's whispers. #2
End If
Next j
Call CreateWWindow(Username) '#3
j = Forms.Count - 1
[/code]

Ok, we have line #1 because if no frmWhispers exist, then we absolutely have to create one for this new whisper. By creating it before the loop, we allow the loop to find it and add the whisper to it without having to cycle through all of the loaded forms. See line #2? That's where you'd jump past the second window creation (line #3) since a form was found that you want to add your text to. Line #1 provides a single use instance that prevents the program from having to look through all available forms.

Edit: Running the loop from Forms.Count - 1 to 0 Step -1 is actually going to be faster than running from 0 to Forms.Count - 1, if anyone implements this.
March 28, 2003, 4:18 PM

Search