Solved

Question about : For Each XXX In XXXX

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

751 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