Solved

Question about : For Each XXX In XXXX

Posted on 1999-01-07
2
257 Views
Last Modified: 2010-08-05
Hello,
I have a form containing two command buttons :

Option Explicit

Private Sub Command1_Click()
Dim mynew As Form1
Set mynew = New Form1
mynew.Show
End Sub

Private Sub Command2_Click()
Dim myform As Form  
~~~~~~~~~~~~~~~~~~
For Each myform In Forms
    Debug.Print TypeName(myform)
    Unload myform
Next myform

End Sub

--
What surprises me is the line above.  There is no error if
I use "Dim myform As Form" or "Dim myform As Form1".
But typename(myform) shows 'form1'.

I want to know if :
Dim myvar As X
For Each myvar In Y
....

the, should the class of X = class of element in Y ?

Thank you.

rgds.
alan
alanpong@hkstar.com
0
Comment
Question by:alanpong
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 3

Accepted Solution

by:
traygreen earned 50 total points
ID: 1454670
Should not suprise you.
Form1 is a descendant of type form, it is your set command that will determine the attributes (properties, contained controls etc) of the new form.  So the name will always be the same unless you explictly change it.

Assuming that Y is a collection of <objects> X, then YES..
each MyVAR (instance of type X)will be an element of Y
0
 
LVL 1

Author Comment

by:alanpong
ID: 1454671
after thinking it again, i have the conclusions as below :

form is a parent class of form1.  By "Set" , form1
is instanced as a object that
inherit form's properties, method.... and so on.
In addition, two button are included in form1.

They are different classes in the view
of c++ :

class form has xxxx
class form1 has xxxx + two buttons

I don't think the <object> form is the same as
<object> form1 because object is a instance of class.  
However, I think the following is correct in VB :
 If A is B's parent, then type A = type B.
,where "type" is VB-defined characteristic. (e.g.
type can be "object","form", "control", "variant".....)

If so, "Dim myform as form" has the same effect as
"Dim myform as form1". The former means myform has the form's type.
The latter means myform has the form1's type.
(form's type = form1's type)


For the line "for each myform in forms", forms
contain a collection of object references.  In order
to assign these object references to the object varible
myform.  They should have the same object type.  Otherwise,
there is "Type match" error.

rgds.
alan
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month4 days, 2 hours left to enroll

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question