Results 1 to 4 of 4

Thread: [RESOLVED] How to run a sub on another form?

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2006
    Location
    Geographic Center of the Universe
    Posts
    13

    Resolved [RESOLVED] How to run a sub on another form?

    Is there a way to run a sub on a form by calling it from another form?

  2. #2
    Hyperactive Member StreaksAthlete's Avatar
    Join Date
    Sep 2004
    Posts
    348

    Re: How to run a sub on another form?

    If you declare the Sub public, you can call it from anywhere. Ex:

    VB Code:
    1. Public Class Form1
    2.  
    3.     Public Sub HelloWorld()
    4.         MsgBox("Hello World")
    5.     End Sub
    6.  
    7. End Class
    Say we want to call it from Form2:

    VB Code:
    1. Public Class Form2
    2.  
    3.     Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    4.         Dim frm1 As New Form1
    5.         frm1.HelloWorld()
    6.     End Sub
    7.  
    8. End Class
    Unity Programs™ - Downloads To Make Your Computer Life Easier - UnityPrograms.com, check it out
    My small company, I need feedback.


    If someone's post was useful, don't forget to Rate It by clicking the Rate This Post link under the avatar.
    If this post has been resolved. Please mark it as Resolved by going through the Thread Tools above and clicking on the Mark Thread Resolved option.
    We ride together, We die together, .NET for life. - Working With Visual Studio.NET 2005

    Application Deployment, General Developer Forum, Visual Basic .NET

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How to run a sub on another form?

    Forms are objects, just like any other. Any object can call any accessible member of any other object PROVIDED that it has a reference to that object. Forms are no different. I suggest that you read the "Forms in VB.NET" tutorial in my signature.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    New Member
    Join Date
    Jul 2006
    Location
    Geographic Center of the Universe
    Posts
    13

    Re: How to run a sub on another form?

    thanks for the help both of you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width