Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Question about : For Each XXX In XXXX

Posted on 1999-01-07
2
Medium Priority
?
265 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 150 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

718 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