473,399 Members | 4,254 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Form Reference Question (Getting Back Your Visual Basic 6.0 Goodies)

"Getting Back Your Visual Basic 6.0 Goodies" by Billy Hollis, 2003-5-14,
states:

"Getting a Forms Collection
Visual Basic 6.0 developers are often fond of looping through the currently
loaded forms in an application to find out something, such as if a
particular form it loaded, or how many of a particular type of form are
loaded. Windows Forms does not include a Forms collection, however, so
gaining such functionality in Visual Basic .NET means some additional work."

Hollis gives an example were we have "Form1" and "Form2".

Form1 has TWO buttons ... the first button creates a number of instances
of Form2;
the second button uses a collection to make each instance of Form2
invisible.

PROBLEM

The above is like a FORWARD reference ... from the main form, to some other
form.

I am struggling with reversing the syntax ...

from other forms and other modules I would like to control Form1 ....
for example, when the end user clicks my control [some button] on Form2
which starts a routine myModuleCode, it would be nice if, in myModuleCode,
I could do something like:

....
"Form1".Visible = False ' Hide Form1 until processing is complete
.... ' start of processing
....
....
.... ' end of processing
"Form1".Visible = True ' Unhide Form1 because processing is
complete
....

My feeble attempts to adapt Hollis' example has only succeeded in causing a
variety of crashes. Using "Me", "Me.Name", et cetera, did not help me
discover the correct syntax.

Needless to say, the online help was useless (or perhaps it is I who is
useless at locating information just beyond my fingertips).

Rather than continuing to bang my brain against the syntax wall, I hope some
reader of this newsgroup will be kind enough to share her/his expertise in
this matter.

Thank you .... regards, gerry
Nov 21 '05 #1
7 1835
gerryLowry::Ability Business Computer Services {KCAZ0H1} wrote:
"Getting Back Your Visual Basic 6.0 Goodies" by Billy Hollis, 2003-5-14,
states:

"Getting a Forms Collection
Visual Basic 6.0 developers are often fond of looping through the currently
loaded forms in an application to find out something, such as if a
particular form it loaded, or how many of a particular type of form are
loaded. Windows Forms does not include a Forms collection, however, so
gaining such functionality in Visual Basic .NET means some additional work."

Hollis gives an example were we have "Form1" and "Form2".

Form1 has TWO buttons ... the first button creates a number of instances
of Form2;
the second button uses a collection to make each instance of Form2
invisible.

PROBLEM

The above is like a FORWARD reference ... from the main form, to some other
form.

I am struggling with reversing the syntax ...

from other forms and other modules I would like to control Form1 ....
for example, when the end user clicks my control [some button] on Form2
which starts a routine myModuleCode, it would be nice if, in myModuleCode,
I could do something like:

....
"Form1".Visible = False ' Hide Form1 until processing is complete
.... ' start of processing
....
....
.... ' end of processing
"Form1".Visible = True ' Unhide Form1 because processing is
complete
....

My feeble attempts to adapt Hollis' example has only succeeded in causing a
variety of crashes. Using "Me", "Me.Name", et cetera, did not help me
discover the correct syntax.

Needless to say, the online help was useless (or perhaps it is I who is
useless at locating information just beyond my fingertips).

Rather than continuing to bang my brain against the syntax wall, I hope some
reader of this newsgroup will be kind enough to share her/his expertise in
this matter.

Thank you .... regards, gerry


As long as myModuleCode has a reference to "Form1" then you can do this.
You'll probably have to send in a reference to form1 to form2.
Something like:

public class form2
dim RefToForm1 as Form1
sub new(F1 as Form1)
mybase.new()
RefToForm1 = F1
end sub
sub myModuleCode()
RefToForm1.Visible = False
.....
RefToForm1.Visible = False
end sub
End class

note that this way of doing it causes you to create Form2 this way:

From inside Form1 somewhere...
dim F2 as new Form2(Me) 'This passes in the reference of form1 to form2

Hope it helps
Chris
Nov 21 '05 #2
| As long as myModuleCode has a reference to "Form1" then you can do this.
| You'll probably have to send in a reference to form1 to form2.
| Something like:
|
| public class form2
| dim RefToForm1 as Form1
| sub new(F1 as Form1)
| mybase.new()
| RefToForm1 = F1
| end sub
| sub myModuleCode()
| RefToForm1.Visible = False
| .....
| RefToForm1.Visible = False
| end sub
| End class
|
| note that this way of doing it causes you to create Form2 this way:
|
| From inside Form1 somewhere...
| dim F2 as new Form2(Me) 'This passes in the reference of form1 to form2
|
| Hope it helps
| Chris

Hi, Chris ... it may help ... although I sense potential problems in more complex programs ...

For example, Form1 opens Form2, Form2 calls the sub "chris" in Module1, "chris" hides Form1,
then, later, Form1 opens Form3, Form3 calls the sub "chris" in Module1, "chris" hides Form1.

This all appears to force far to much form to form to module or class communication.

Since ALL of these code units are compiled together, it would be so much
easier if one could say from ANYWHERE, in a simple syntax, something like

"Form1".Visible = <truth value>

It would have been so much easier if VB.NET had included the VB6 Forms collection.

g.
Nov 21 '05 #3
Gerry~Lowry wrote:
| As long as myModuleCode has a reference to "Form1" then you can do this.
| You'll probably have to send in a reference to form1 to form2.
| Something like:
|
| public class form2
| dim RefToForm1 as Form1
| sub new(F1 as Form1)
| mybase.new()
| RefToForm1 = F1
| end sub
| sub myModuleCode()
| RefToForm1.Visible = False
| .....
| RefToForm1.Visible = False
| end sub
| End class
|
| note that this way of doing it causes you to create Form2 this way:
|
| From inside Form1 somewhere...
| dim F2 as new Form2(Me) 'This passes in the reference of form1 to form2
|
| Hope it helps
| Chris

Hi, Chris ... it may help ... although I sense potential problems in more complex programs ...

For example, Form1 opens Form2, Form2 calls the sub "chris" in Module1, "chris" hides Form1,
then, later, Form1 opens Form3, Form3 calls the sub "chris" in Module1, "chris" hides Form1.

This all appears to force far to much form to form to module or class communication.

Since ALL of these code units are compiled together, it would be so much
easier if one could say from ANYWHERE, in a simple syntax, something like

"Form1".Visible = <truth value>

It would have been so much easier if VB.NET had included the VB6 Forms collection.

g.


You could make Form1 a module level variable and give everyone access,
but this does not really follow the OO method of development. You could
make your own forms collection if you wanted, again same issue.

"This all appears to force far to much form to form to module or class
communication."

How is this a problem. I also don't see how it's form to form to module
communication... Form2 hides Form1, calls the module, shows Form1.
You could handle this as an event I guess. Make an event in Form2
called "StartProcess" and one called "EndProcess" Then have Form1
handle the Form2 events.

in Form2:

RaiseEvent(StartProcess)
callProcessFunction
RaiseEvent(StopProcess)

in Form1
'This could be done dynamically use addhandler/removehander instead of
using "handles" keyword
private sub StartProcess_Handler() handles form2.StartProcess
me.visible = false
end sub

Chris
Nov 21 '05 #4
(Here's a somewhat kludgey* solution ... f.y.i.:

In Module1

Public myStartUpForm As Form

Public Sub setReferenceToForm1(ByRef myStartUpFormIs As Form)
myStartUpForm = myStartUpFormIs
End Sub

Public Sub showHideMyStartUpForm()
myStartUpForm.Visible = Not myStartUpForm.Visible
End Sub

In Form1 initialization

setReferenceToForm1(Me)

The global, myStartUpForm, should allow reference back to Form1 from anywhere.

g.)

* kludgey, and potentially buggy ... for example, if a general form referenced with
this method was closed, I am not sure what might result if the global was later
used ... something likely not pretty

"Gerry~Lowry" <ge*********@abilitybusinesscomputerservices.com > wrote in message news:ea**************@tk2msftngp13.phx.gbl...
| | As long as myModuleCode has a reference to "Form1" then you can do this.
| | You'll probably have to send in a reference to form1 to form2.
| | Something like:
| |
| | public class form2
| | dim RefToForm1 as Form1
| | sub new(F1 as Form1)
| | mybase.new()
| | RefToForm1 = F1
| | end sub
| | sub myModuleCode()
| | RefToForm1.Visible = False
| | .....
| | RefToForm1.Visible = False
| | end sub
| | End class
| |
| | note that this way of doing it causes you to create Form2 this way:
| |
| | From inside Form1 somewhere...
| | dim F2 as new Form2(Me) 'This passes in the reference of form1 to form2
| |
| | Hope it helps
| | Chris
|
| Hi, Chris ... it may help ... although I sense potential problems in more complex programs ...
|
| For example, Form1 opens Form2, Form2 calls the sub "chris" in Module1, "chris" hides Form1,
| then, later, Form1 opens Form3, Form3 calls the sub "chris" in Module1, "chris" hides Form1.
|
| This all appears to force far to much form to form to module or class communication.
|
| Since ALL of these code units are compiled together, it would be so much
| easier if one could say from ANYWHERE, in a simple syntax, something like
|
| "Form1".Visible = <truth value>
|
| It would have been so much easier if VB.NET had included the VB6 Forms collection.
|
| g.
Nov 21 '05 #5
| You could make Form1 a module level variable and give everyone access,
| but this does not really follow the OO method of development. You could
| make your own forms collection if you wanted, again same issue.

I think that is basically what I have done
in the kludge that I just posted. I agree with
you ... it's ugly and very un-OO.

| "This all appears to force far to much form to form to module or class
| communication."
|
| How is this a problem. I also don't see how it's form to form to module
| communication... Form2 hides Form1, calls the module, shows Form1.

Chris, perhaps I was a bit unclear here. In some business
applications, it would be convenient to be able to safely
call any module and/or control any form from any point in code.

It seems a bit like a bucket brigade, with each form passing
references down the call hierarchy, just so that any form
that might need it would have access to it.

| You could handle this as an event I guess. Make an event in Form2
| called "StartProcess" and one called "EndProcess" Then have Form1
| handle the Form2 events.
|
| in Form2:
|
| RaiseEvent(StartProcess)
| callProcessFunction
| RaiseEvent(StopProcess)
|
| in Form1
| 'This could be done dynamically use addhandler/removehander instead of
| using "handles" keyword
| private sub StartProcess_Handler() handles form2.StartProcess
| me.visible = false
| end sub
|
| Chris

Chris, your event idea has a good degree of elegance.
It may be the best possible and the most consistent
solution.

Thank you ............ gerry
Nov 21 '05 #6
"Gerry~Lowry" <ge*********@abilitybusinesscomputerservices.com > schrieb
Hi, Chris ... it may help ... although I sense potential problems in
more complex programs ...

For example, Form1 opens Form2, Form2 calls the sub "chris" in
Module1, "chris" hides Form1, then, later, Form1 opens Form3,
Form3 calls the sub "chris" in Module1, "chris" hides Form1.

This all appears to force far to much form to form to module or
class communication.

Maybe you should rethink the design. Just curious: Why do you have to pass
Forms around so often? Even without a global "Form1" variable I don't have
to do it often, also not in more complex apps.

A basic rule is: If you want to access an object, you need a reference. If
you don't have one, you have to pass it. I've never needed an exception for
Forms.

In addition, you can always write "public shared f1 as form1" in a class to
make it available everywhere. But be careful: The object can be modified
from the whole project and finding errors can get complicated.
Since ALL of these code units are compiled together, it would be so
much
easier if one could say from ANYWHERE, in a simple syntax, something
like

"Form1".Visible = <truth value>

It would have been so much easier if VB.NET had included the VB6
Forms collection.

Armin

Nov 21 '05 #7
Armin ... it's not my design ... the particular designer has a familiar style
derived from the xBase DOS world ... the designer's theory is that the staff
are familiar with applications acting a certain way ... by acting upon
forms somewhat dynamically, the designer is simulating the legacy DOS system's
application behaviour. In Access and in VB6, the designer's goals
are somewhat more easily met.

"Armin Zingler" <az*******@freenet.de> wrote in message news:u6**************@TK2MSFTNGP10.phx.gbl...
| "Gerry~Lowry" <ge*********@abilitybusinesscomputerservices.com > schrieb
| > Hi, Chris ... it may help ... although I sense potential problems in
| > more complex programs ...
| >
| > For example, Form1 opens Form2, Form2 calls the sub "chris" in
| > Module1, "chris" hides Form1, then, later, Form1 opens Form3,
| > Form3 calls the sub "chris" in Module1, "chris" hides Form1.
| >
| > This all appears to force far to much form to form to module or
| > class communication.
|
|
| Maybe you should rethink the design. Just curious: Why do you have to pass
| Forms around so often? Even without a global "Form1" variable I don't have
| to do it often, also not in more complex apps.
|
| A basic rule is: If you want to access an object, you need a reference. If
| you don't have one, you have to pass it. I've never needed an exception for
| Forms.
|
| In addition, you can always write "public shared f1 as form1" in a class to
| make it available everywhere. But be careful: The object can be modified
| from the whole project and finding errors can get complicated.

Agreed. I would not want to risk this unless I were desperate.

thank you / gerry
Nov 21 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Steven O. | last post by:
I am basically a hobbyist programmer, at the moment doing a little work experimenting with some AI stuff. I learned C++, and then tried to teach myself MFC using MS Visual C++ 6.0. I swore off of...
15
by: simonmarkjones | last post by:
I want to validate my form using a BeforeUpdate event. However now that i call my code with a beforeupdate it wont let me go to next or previous records. What code should i put in o allow me...
2
by: DaWoE | last post by:
Hi all, I'm fairly new to ASP.NET. What i want to do is creat a online registration form. On the first step is getting the users details and the number of people he wants to register. Based on...
4
by: Ahsan | last post by:
How can i stop one VB.Net form to execute again when its running already ? in other words I don't allow the user to open one form twice in my application Suggestions please. Thank you, Ahsan
4
by: Haris Bogdanovic | last post by:
how do I refer to other form from main form so I can call its Show method ? Thanks Haris
15
by: http://www.visual-basic-data-mining.net/forum | last post by:
Does anyone have any idea how to transferring data from TextBox1 in form1 to textBox2 in form2..... That means after i fill in any data in textBox1 and click Next button... It will bring me to...
13
by: Lee Newson | last post by:
Hi, I have just written my first application using VB.NET. The app works fine when i am running it within .NET for debugging purposes, however when i try to run the app from the .exe file that...
14
by: 97T | last post by:
Well this is still bugging me. I know there are other ways around this, but for a number of reasons I would like to be able to do this one simple thing. I have a form with a number of controls...
12
by: Rob | last post by:
Let's say you open Form1 that contains TabControl1 There are several tabs on TabControl1 Now you open a new Form2 that contains a User Control How can you determine the Selected tab in Form1...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.