April 15th, 2013, 06:49 AM
how to generalize a command in Module to be called in different forms
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
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
Public Sub ClearPicture(PictureBox as Picture)
In your form code you would use
Public Sub ClearPicture(TheForm as Form)
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.
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.