Solved

Question about : For Each XXX In XXXX

Posted on 1999-01-07
2
234 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
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now