none
Need some help with a Class in VB .net. RRS feed

  • Question

  • Please can some one help me to learn how to code a class.

    Ie:

    Class one()

    2 complete subs.

    Public Sub fred()

    End Sub

    Public Sub bill()

    End Sub

    .........................

    Form1

    How to call fred() or bill() as is, to use.

    Wednesday, October 24, 2018 6:43 PM

Answers

  • Here you go

    Public Class Form1
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim demo As New One
            demo.Fred()
        End Sub
    End Class
    Public Class One
        Public Sub Fred()
            MessageBox.Show("Hi Fred")
        End Sub
    End Class
    Now I placed both classes in the same file for easy of learning. What you should do is create each class in a new file by right clicking on the project, select add new item/class.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites


    Wednesday, October 24, 2018 6:49 PM
    Moderator

All replies

  • Here you go

    Public Class Form1
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim demo As New One
            demo.Fred()
        End Sub
    End Class
    Public Class One
        Public Sub Fred()
            MessageBox.Show("Hi Fred")
        End Sub
    End Class
    Now I placed both classes in the same file for easy of learning. What you should do is create each class in a new file by right clicking on the project, select add new item/class.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites


    Wednesday, October 24, 2018 6:49 PM
    Moderator
  • In addition to what that has already posted as an answer,  you should understand OO basics, becuase VB.NET is an OO language.  

    https://alfredjava.wordpress.com/2008/07/08/class-vs-object-vs-instance/

    Wednesday, October 24, 2018 8:32 PM
  • Thank you Karen, that gives me a better understanding. Got it working now.
    Wednesday, October 24, 2018 10:18 PM