-
April 15th, 2013, 06:49 AM
#1
how to generalize a command in Module to be called in different forms
Hi,
I am new to Visual basic and trying to write a program where I am writing a public subroutine in module and calling it in MDI and other MDI child forms. But the problem is, how should I make it general so that same subroutine can be used in different forms. For example the command: Form1.Picture1.cls
For the other form this command would be Form2.Picture1.cls. Please tell me how to generalize such commands.
Thanks in advance.
-
April 15th, 2013, 09:57 AM
#2
Re: how to generalize a command in Module to be called in different forms
You would pass the object or form as a parameter
In your module
Code:
Public Sub ClearPicture(PictureBox as Picture)
PictureBox.Cls
End Sub
or
Code:
Public Sub ClearPicture(TheForm as Form)
TheForm.Picture1.Cls
End Sub
In your form code you would use
Code:
ClearPicture Picture1
or
Of course neither of these would make any sense in the example you gave as you could simply use
in your form code rather than calling a separate sub for such a simple method.
In general however you should never make a specific reference to a form from a module or other form and instead you should pass the form or control to be used as a parameter so that the module can work with any form rather than being locked into a form by a specific name.
Always use [code][/code] tags when posting code.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|