Form As array
i used to know this one, need a refresher, what was it that allowed me to dim a form as an array...
dim newform as new form 2() ??
[140 byte] By [
vchatlive] at [2007-11-11 10:09:44]

# 1 Re: Form As array
dim foms(7) as new form1
now u have 8 forms , from form(0) to form (7) .
Amahdy at 2007-11-11 17:23:11 >

# 2 Re: Form As array
gotcha, ok now how about this...
if a UserB sends UserA a message. if should open a new IM window IF its the first message, but if its a new message for an existing message session, then how can i find the correct form(index) of the message based on the username. that way there can be multiple messages between users... im thinking something along the lines of...
if IncomingData username is in the array list then send the message there,
else open a new window start a new session.
how could i go about doing that?
any ideas on a way to get started with that?
# 3 Re: Form As array
how about on the main form have a label array that stores username with a # in front of it ( which would be the array number of the form2 loading process) but have them not visible? would that possible work and have it check against that, loop through the label array to find it, if exists use it if not open a new one and add another label to the array
# 4 Re: Form As array
that will work, but you will have another array to maintein.
I will eliminate all arrays in toto, this is how:
add a public variable in your user form (that I calledd UserForm)
Public UserName as string
when you receive a message from user U:
dim f as Form
dim fx as UserForm
dim bFound as Boolean
for each f in forms
if typeof f is UserForm then
set fx = UserForm
if fx.UserName = U then
bFound = True
exit for
endif
endif
next
if not bFound then
set fx = new UserForm '' create a new one
fx.UserName = U '' and initialize it
endif
'' do whatever you have to do with 'fx'
'''---- end code NOT TESTED
Notice that in this way you don't even have to use an array of UserForm...
it is my standard way to handle mutliple instances of the same form. A local array is always dangerous, because every time that you load/unload the form you have to remember to update the array. Bad practice.
Marco
mstraf at 2007-11-11 17:26:11 >

# 5 Re: Form As array
make it user(i) send user(j) .. and i must be the same as the form(i) .. this could help .
every time form(i).show will open if it's not allready opened and will make nothink otherwise .
but to make new form just see if the incoming i > last new form(i) loaded ... yes mean you must load this i and no mean it's allready loded and running [remember maybe user close it in any time so u need to relod it ]
hope this helps .
Amahdy at 2007-11-11 17:27:09 >

# 6 Re: Form As array
what about this as a concept...
have a non visible list view. when a new IM comes in fill the listview columns with the info, like users IP address ( to send data back to), the index, the users name
when a new IM comes in check the listview for the users name. if its there get the index and put the data on that form, other wise open a new form. if i close the window it takes the listing out of the listview and recycles the index that way it always has it available for incoming....
how would that be for an idea?
# 7 Re: Form As array
yea it's good .. the feauture of the listbox is it can automatically fit container and remove empty value ".removeitem" .. instead of overloading this in an array ... of course the array is better and take less memory and fast interaction but list is easier .. anyway , u may better use the control without putting it in your form whence you don't want it all time and u will keep it invisible :
dim mylist as listbox 'mylist is a listbox that I can use and it doesn't exist in the design time .
Amahdy at 2007-11-11 17:29:14 >

# 8 Re: Form As array
how can i find the index of a new form that has been opened. if its in an array? Thank You
# 9 Re: Form As array
what do u need exactly ? the name of the form(i) has the index i .
Amahdy at 2007-11-11 17:31:11 >

# 10 Re: Form As array
how can i ... for example,
main form has button cmdLoadNewWindow
when button is pressed it loads the new form "New Window"
when its pressed again it loads "New Window" now i have 2 identical "new window" 's loaded, how do i know which is which. there is no "form2.index" that i can see anywhere how do i find the ID/index or whatever of the "new window" that is in use
even if i can have a label on the new window that has a caption with the index/id number that would help me out alot here.
# 11 Re: Form As array
Yea the way to write into the form itself is good , also if you want to performe action in the form itself u can use the "Me" ..
for example Me.caption="I make the action here !" ... Me.Hide ..
I think me can solve all problems with advanced methods like :
"If Me Is Form(2) then 'performe form indexed 2 action"
or
Select Case Me.hWnd
Case form(2).hWnd
MsgBox "I'm form indexed 2 !"
End Select
Amahdy at 2007-11-11 17:33:20 >

# 12 Re: Form As array
ok i got the forms to work on, they load the way they are supposed to but the textboxes and send button no longer work, do they need to be arrays as well? and then send the information to the textbox(0).text index? Thanks
# 13 Re: Form As array
the easiest way is to make the declaration of forms as global:
"Global a(5) As Form1"
and use the object a(i) any way u want ;
a(i).textbox = "I'm here"
a(i).hide
if me is a(i) then ... and so on.
Amahdy at 2007-11-11 17:35:16 >
