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

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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


.



Relevant Pages

  • Re: How can I throw out (handle) an ENTER keypress for an AcceptButton?
    ... that Form1 was receiving a KeyUp from a key press that occurred on Form2. ... My app starts with Form1 which has a textbox on it. ... KeyUp event of the textbox for that. ... > Private Sub Button1_Click(ByVal sender As System.Object, ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Unload in Form_Load
    ... Form: Form1 ... Private Sub Form_Click ... End With ... Form: Form2 ...
    (microsoft.public.de.vb)
  • Re: beginner programmer with a problem.
    ... Private Sub cmd_OpenForm2_Click ... DoCmd.OpenForm "Form2" ... Closing Form1 without any design changes. ... > BUT, unlike the macro, it does NOT automatically come on again when your ...
    (microsoft.public.access.modulesdaovba)
  • Re: Form Reference Question (Getting Back Your Visual Basic 6.0 Goodies)
    ... the second button uses a collection to make each instance of Form2 invisible. ... for example, when the end user clicks my control on Form2 which starts a routine myModuleCode, it would be nice if, in myModuleCode, ... You'll probably have to send in a reference to form1 to form2. ... sub new ...
    (microsoft.public.dotnet.languages.vb)
  • Verknüpfung Umschalten Acc2000
    ... Tabellen ausgewählt habe, über die Option "Verknüpfte ... Mit der im Form1 ... Form1, sollte es möglich sein, manchmal im Form2 einige ... Sub VerknüpfungUmschalten_Click ...
    (microsoft.public.de.access)