Understanding object in VB.net

Jonathan Brotto 1,076 Reputation points
2022-03-22T13:18:49.827+00:00

To create an object in VB this works?

    '// Creating an object
    Dim oAddingMenuItems As AddingMenuItems

    oAddingMenuItems = New AddingMenuItems
Developer technologies | VB
0 comments No comments
{count} votes

1 additional answer

Sort by: Most helpful
  1. LesHay 7,141 Reputation points
    2022-03-22T13:29:37.153+00:00
    Option Strict On
    Option Explicit On
    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
            Dim oAddingMenuItems As AddingMenuItems
    
            oAddingMenuItems = New AddingMenuItems
            ' at this point,  AddingMenuItems  contains
            ' count = 123
            ' name = "New Object Name"
    
            oAddingMenuItems = New AddingMenuItems("My Own Name")
            ' at this point,  AddingMenuItems  contains
            ' count = 321
            ' name = "My Own Name"
    
    
            oAddingMenuItems = New AddingMenuItems(888, "My Own Second Name")
            ' at this point,  AddingMenuItems  contains
            ' count = 888
            ' name = "My Own Second Name"
    
    
        End Sub
        Class AddingMenuItems
            Property count As Integer
            Property name As String
    
            Sub New()
                count = 123
                name = "New Object Name"
            End Sub
            Sub New(n As String)
                name = n
                count = 321
            End Sub
            Sub New(c As Integer, n As String)
                name = n
                count = c
            End Sub
        End Class
    End Class
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.