How to call a form routine from a module by the form handle 
Author Message
 How to call a form routine from a module by the form handle

Hi!

I have two form files, each contains a procedure called "MyProc". I
also have a module, from where I want to call MyProc either in Form1
or Form 2, depending on a var where I store the destination form's
handle. It looks like this:

If lngHandle = Form1.hwnd Then
  Call Form1.MyProc
Else If lngHandle = Form2.hwnd Then
  Call Form2.MyProc
End If

The problem is, that I have to test for each form handle in the module
and that I cannot write a general module to use in more projects
because it has to be changed for each project.

The best idea would be to do something like "Call lngHandle.MyProc",
but that does not work.

Do you have any ideas?

Thanks, Christian



Tue, 27 Nov 2001 03:00:00 GMT  
 How to call a form routine from a module by the form handle

Quote:

>Hi!

>I have two form files, each contains a procedure called "MyProc". I
>also have a module, from where I want to call MyProc either in Form1
>or Form 2, depending on a var where I store the destination form's
>handle. It looks like this:

>If lngHandle = Form1.hwnd Then
>  Call Form1.MyProc
>Else If lngHandle = Form2.hwnd Then
>  Call Form2.MyProc
>End If

>The problem is, that I have to test for each form handle in the module
>and that I cannot write a general module to use in more projects
>because it has to be changed for each project.

>The best idea would be to do something like "Call lngHandle.MyProc",
>but that does not work.

>Do you have any ideas?

>Thanks, Christian

Shortly after I have written the above message, I found the following
solution:

  Dim CurrentForm As Form

  For Each CurrentForm In Forms
    If CurrentForm.hWnd = lngHandle Then
      Call CurrentForm.MyProc
    End If
  Next CurrentForm

It might not be the best way, but it works ...;-)

Christian



Tue, 27 Nov 2001 03:00:00 GMT  
 How to call a form routine from a module by the form handle
Hi!
I think you can solve this using implements statement
Each form is class itself and it can implement the same interface
This is just the case for what Implements is designed

Quote:

> Hi!

> I have two form files, each contains a procedure called "MyProc". I
> also have a module, from where I want to call MyProc either in Form1
> or Form 2, depending on a var where I store the destination form's
> handle. It looks like this:

> If lngHandle = Form1.hwnd Then
>   Call Form1.MyProc
> Else If lngHandle = Form2.hwnd Then
>   Call Form2.MyProc
> End If

> The problem is, that I have to test for each form handle in the module
> and that I cannot write a general module to use in more projects
> because it has to be changed for each project.

> The best idea would be to do something like "Call lngHandle.MyProc",
> but that does not work.

> Do you have any ideas?

> Thanks, Christian

--



Tue, 27 Nov 2001 03:00:00 GMT  
 How to call a form routine from a module by the form handle

Quote:
>I have two form files, each contains a procedure called "MyProc". I
>also have a module, from where I want to call MyProc either in Form1
>or Form 2, depending on a var where I store the destination form's
>handle. It looks like this:
>If lngHandle = Form1.hwnd Then
>  Call Form1.MyProc
>Else If lngHandle = Form2.hwnd Then
>  Call Form2.MyProc
>End If
>The problem is, that I have to test for each form handle in the module
>and that I cannot write a general module to use in more projects
>because it has to be changed for each project.
>The best idea would be to do something like "Call lngHandle.MyProc",
>but that does not work.

One approach would be to put a hidden button on each form, pass the button to
the module, and later invoke its Click event by setting its Value.  For
example:

 Private cmdCallback as CommandButton

 Public Sub SetCallback(cmd as CommandButton)
 Set cmdCallback=cmd
 End Sub

 Public Sub DoCallback
 cmdCallback=True
 End Sub

J. Bodie



Tue, 27 Nov 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Can VB modules call form routines?

2. How to call a routine in another form?

3. Having trouble calling routines from another form

4. Calling a Class Module;CFileDialog - from OnClick of Button on form

5. Calling a Function in an MS Access Class/Form/Module from an outside application

6. Form call function in module of another database

7. Referencing the Form from Which a Module Function Is Called

8. module sub called from within form

9. Module called by two forms

10. Calling a Sub in Another Form vs a Module

11. Pass variable form module to a form

12. How do you pass from obj from one form to a module/forms

 

 
Powered by phpBB® Forum Software