I need a basic lesson

sethindeed
10-09-2001, 06:21 AM
Hello,
I would like to have basic informations on how do we handle forms that are loaded via an array. My problem remains the same. Suppose I have Form(1), Form(2) Form(3) and Form(4) loaded in memory, if I unload Form(3), I would like to see Form(4) takes its place. I know it has something to do with redimming the array VS UBound or something...I am all lost here :(

Banjo
10-09-2001, 06:29 AM
<pre>Unload FormArray(3)
Set FormArray(3) = FormArray(4)
Set FormArray(4) = Nothing</pre>

You can then ReDim the array if you wish.

anhmytran
10-09-2001, 06:35 AM
I think you have some misconception.
There is no arrays of Forms.

There is only Collection of Forms.

The notation FormABC(Number) is an invalid syntax.

AnhMy_Tran

Banjo
10-09-2001, 06:44 AM
I don't think he's talking about the Forms collection. I think has a normal array of form references. I.e.: Dim ar() as Form

sethindeed
10-09-2001, 06:57 AM
Thanx Banjo, I'll try this :)

anhmytran
10-09-2001, 07:04 AM
If there is an array of form, it should be loaded into the
collection of forms to work.

When an element of the array is unloaded from the collection
of forms, it remains in the array, at its position.

In order to remove an element in the array, the array should
be resized. It is a different matter from unload a form from
the collection of forms.

AnhMy_Tran

Banjo
10-09-2001, 07:07 AM
That's why I said that he needed to set the unused array element to Nothing.

sethindeed
10-09-2001, 07:07 AM
I just have to resize by removing 1 to the previous total ?

sethindeed
10-09-2001, 07:14 AM
I am getting an error when I am trying to Redim Preserve my Form array a second time ( the first time, no problems ).
I am calling Redim Preserve ( 1 To TotalTemplate ) and this is generating an error the second time around :(

anhmytran
10-09-2001, 07:20 AM
Option Explicit
Dim arrForm() As Form

Private Sub Form_Load()
ReDim arrForm(1 To 3)
Set arrForm(1) = New FormB
Set arrForm(2) = New FormC
Set arrForm(3) = New FormD
End Sub

Private Sub Form_Resize()
Dim i As Integer
For i = 1 To UBound(arrForm)
Load arrForm(i)
Next i
End Sub

Private Sub cmdFeedBack_Click()

Unload arrForm(2)
Dim i As Integer, msg As String
Dim frm As Form
For Each frm In Forms
msg = msg & frm.Name & vbNewLine
Next frm
MsgBox msg, vbOKOnly, "Array of Forms"

End Sub

Private Sub cmdResize_Click()
Set arrForm(2) = arrForm(3)
ReDim Preserve arrForm(1 To UBound(arrForm) - 1)
End Sub

AnhMy_Tran

sethindeed
10-09-2001, 07:32 AM
OKay thanx, my routine works quite well now.
My only problem is when I try to Redin Preserve my routine, seems to generates an error each time the seonc time around...

Banjo
10-09-2001, 07:58 AM
It normally a good idea to use LBound to UBound instead of 1 to UBound. This will be the source of bugs in the future if for some reason you change it to a zero-based array.

sethindeed
10-09-2001, 08:49 AM
Thanx everyone. My function is now bug free :)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum