how to generalize a command in Module to be called in different forms
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: how to generalize a command in Module to be called in different forms

  1. #1
    Join Date
    Apr 2013
    Posts
    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.

  2. #2
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,781

    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
    Code:
    ClearPicture Me
    Of course neither of these would make any sense in the example you gave as you could simply use
    Code:
    Picture1.cls
    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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center