Form Array?

masterigor
02-09-2008, 02:46 PM
I am trying to make an AIM Client to resemble the actual AIM program. Basically the problem is that I have a Messagebox form where it has the message, who your sending it to, etc, and I'm trying to make an array of it so that you can press new message and im multiple people. I have a button that generates a new messaging window:


Private Sub Command3_Click()
screennamecount = screennamecount + 1
Set messagebox2(screennamecount) = New messagebox
messagebox2(screennamecount).Show
End Sub

The problem is I can't make it receive the messages. The actual Winsock control is on the Messagebox form and I tried using the code:

Private Sub mooSock1_IncomingInstantMessage(screenname As String, Message As String)

finalmessage = Mid(Mid(Message, 46), 1, Len(Mid(Message, 46)) - 21)


If Not messagebox2(0).Text2.Text = "" Then
messagebox2(0).Text2.Text = messagebox2(0).Text2.Text & vbCrLf & screenname & ":" & finalmessage
Else
messagebox2(0).Text2.Text = messagebox2(0).Text2.Text & screenname & ":" & finalmessage
End If


End Sub

however it gives me an error on the messagebox2(0) part, and I can't figure out why. Originally it was a loop where it would see how much messageboxes were loaded and it would check if the screen-name of the sender was the screen-name in the messagebox that the person was talking to, and if it was, it send message, so it was something like:

For I = 0 to screennamecount
if messagebox2(i).text1.text= screenname then

however it also give me an erorr on the messagebox2(I)

the master
02-09-2008, 02:51 PM
The reason for your errors is 0. You are adding 1 to screennamecount *before* you use it as an index in the array so the first one will be 1 and not 0.

I think you were on the right track with your loop but you need to make it "for i=1..." and not "for i=0..."

masterigor
02-09-2008, 02:57 PM
The reason for your errors is 0. You are adding 1 to screennamecount *before* you use it as an index in the array so the first one will be 1 and not 0.

I think you were on the right track with your loop but you need to make it "for i=1..." and not "for i=0..."


I made the " Messagebox2(0) " into "Messagebox2(1)" and it still gave me an error

the master
02-09-2008, 03:05 PM
How have you defined your array and do you change the value of screennamecount anywhere other than Command3_Click?

Since this is an IM program and forms will be loaded and unloaded a lot then why not use a collection instead?


'Declarations
dim colForms as collection

'in form_load
set colforms = new collection

'In command3_click
dim frmChat as messagebox 'messagebox being the name of your form
set frmchat = new messagebox
colforms.add frmchat
set frmchat=nothing

'And the loop
dim frmChat as messagebox
for each frmchat in colforms
frmchat.text2.etc....
next

masterigor
02-09-2008, 03:44 PM
Thanks that worked!

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum