0% found this document useful (0 votes)
3 views1 page

How to Declare Structures in VB.NET

To declare a structure in Visual Basic, you must specify the access level using keywords like Public or Private, add elements like variables, procedures, and events to the structure body, and can define additional items like constants, functions, and a default property. Elements inside the structure can have different access levels, for example making a variable Private but a procedure Public.

Uploaded by

Marcus
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

How to Declare Structures in VB.NET

To declare a structure in Visual Basic, you must specify the access level using keywords like Public or Private, add elements like variables, procedures, and events to the structure body, and can define additional items like constants, functions, and a default property. Elements inside the structure can have different access levels, for example making a variable Private but a procedure Public.

Uploaded by

Marcus
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

To declare a structure

1. Create the beginning and ending statements for the structure.

You can specify the access level of a structure using the Public, Protected, Friend, or Private
keyword, or you can let it default to Public.

 Private Structure employee


End Structure

 Add elements to the body of the structure.

A structure must have at least one element. You must declare every element and specify an access
level for it. If you use the Dim Statement without any keywords, the accessibility defaults to
Public.

Private Structure employee


Public givenName As String
Public familyName As String
Public phoneExtension As Long
Private salary As Decimal
Public Sub giveRaise(raise As Double)
salary *= raise
End Sub
Public Event salaryReviewTime()
End Structure

The salary field in the preceding example is Private, which means it is inaccessible outside the
structure, even from the containing class. However, the giveRaise procedure is Public, so it can
be called from outside the structure. Similarly, you can raise the salaryReviewTime event from
outside the structure.

In addition to variables, Sub procedures, and events, you can also define constants, Function
procedures, and properties in a structure. You can designate at most one property as the default
property, provided it takes at least one argument. You can handle an event with a SharedSub
procedure. For more information, see How to: Declare and Call a Default Property in Visual Basic.

You might also like