You are on page 1of 28

ICT VB.

NET
In XYZ Company, the accountant needs to find the salary of each employee using the number of
hours they worked and hourly rate.

Using VB.NET, create the following form to calculate their salaries.

1. Create a new project in Visual basic.net change the caption of the form1 to “SALARY”

2. Add necessary control to the form and design the user interface accordingly

3. In the properties window give meaningful names to each control. Change the caption of
relevant controls. Your form should be similar to the above format

4. Type the code to display the salary when you click on the calculate button

[Salary= Hours Worked x Rate]

5. Save the file as “Myform.vb” and save the project as “MyProject.sln”

125 Vocational Training Authority of Sri Lanka - Jaffna


ICT VB.NET

Using VB.Net, create the following form to calculate the answer.

1. Create a new project. Change the caption of the form1 to “OPERATOR”. [05 Marks]

2. Add necessary controls to the form and design the user interface accordingly. [07 Marks]

3. In the properties window give meaning full name to each control. Change the capacity of
relevant controls. Your form should be similar to the above format[06 Marks]

4. Type a code to display the answer when you click on the “CALCULATE” button. [15 Marks]

5. Type a code to clear all the text boxes when you click on “CLEAR” button. [07 Marks]

6. Type a code to exit from the program when you click on “EXIT” button. [05 Marks]

7. Savethe form as “Calculator.vb” and save the project as “Calculatort.sln”. [05 Marks]

126 Vocational Training Authority of Sri Lanka - Jaffna


ICT VB.NET

Using VB.Net, create the following form to calculate the answer.

1. Create new project. Change the caption of the form1 to “EMPLOYEE DETAILS” [02 Marks]

2. Add necessary controls to the form and give suitable name and design the user interface
accordingly. [08 Marks]

3. In the properties window give meaningful name to each control. Change the caption of relevant
Controls. Your form should be similar to the above form. [06 Marks]

4. Type the code to display the answer when you click on the “Net Salary” button. [05 Marks]
Net salary= Basic salary- deduction

5. Type the code to display the answer when you click on the “Bonus” button using following bonus
chart.
Net Salary Bonus
<10000 50
10000>= 125
15000>= 150
20000>= 200 [14 Marks]
6. Type a code to clear all the text boxes when you click on “CLEAR” button. [05 Marks]

7. Type a code to exit from the program when you click on “EXIT” button. [05 Marks]

8. Save the form as “Companybonus.vb” and save the project as “Companybonus.sln”. [05 Marks]

127 Vocational Training Authority of Sri Lanka - Jaffna


ICT VB.NET
Using VB.Net, create the following form to find the answer.

1. Create new project. Change the caption of the form1 to “Result Sheet” [02 Marks]

2. Add necessary controls to the form and give suitable name and design the user interface

accordingly. [08 Marks]

3. In the properties window give meaningful name to each control. Change the caption of relevant

controls. Your form should be similar to the above form. [06 Marks]

4. Type the code to display the full name when you click on the “Full Name” text box.

[05Marks]

5. Type the code to display the total when you click on the “Total” text box using following

fomula.(Total= Mark1+Mark2) [07 Marks]

6. Type the code to display the average when you click on the “average” text box using following

formula.(Average= Total/2) [07 Marks]

7. Type a code to clear all the text boxes when you click on “CLEAR” button.[05 Marks]

8. Type a code to exit from the program when you click on “Close” button. [05 Marks]

9. Save the form as “MarkSheet.vb” and save the project as “Result.sln”. [05 Marks]

128 Vocational Training Authority of Sri Lanka - Jaffna


ICT VB.NET
Using VB.Net, create the following form to find the answer.

1. Create new project. Change the caption of the form1 to “Result Sheet1”

2. Add necessary controls to the form and give suitable name and design the user interface

accordingly.

3. In the properties window give meaningful name to each control. Change the caption of relevant

controls. Your form should be similar to the above form.

4. Type the code to display the total, average, grade when you click on the “Calculate” button

using following formula.

Total= Word Mark+ Excel Mark+ PowerPoint Mark+ Access Mark

Average= Total/4

Grade: Average Grade


>=75 A
>=65 B
>=50 C
<50 F
7.Type a code to clear all the text boxes when you click on “CLEAR” button.

8.Type a code to exit from the program when you click on “Close” button.

9. Save the form as “MarkSheet.vb” and save the project as “Result.sln”.

129 Vocational Training Authority of Sri Lanka - Jaffna


ICT VB.NET

1. Design above interface by adding given controls.


2. Add following course names to the combo control and use “NCICT” as default.
combo names- NCICT,NDICT,CCNA,IT Essential
3. Get the system date and display on “Date Reg” text boxes with dd/mm/yyyy format. This can be
displayed automatically when you select from combo control (combo click).
Helpful functions- date (), day (), month (), year ()
4. Course Fee should be displayed based on the selection of course from the combo control. This
also can be displayed automatically when you select course from combo control. (combo click)
Course Fee to add
NCICT 5000.00
NDICT 7000.00
CCNA 40000.00
IT Essential 10000.00
E: When select course NCICT the “Course Fee” text box should be filled with 5000.
5. Find the balance fee and display on “Balance Fee” text box. The balance fee is calculated and
displayed when you enter value in “Amount paid” text box.(Change event)
 Balance Fee=Course fee- Amount Paid
6. Display following message box when you click “Save” button and when ok button on message
box clear controls and allow to add another record.
7. Make your project as “Register.vb” file.

130 Vocational Training Authority of Sri Lanka - Jaffna


ICT VB.NET
Using VB create a simple programme to find the “Salary” for employees based on three departments.

1. Create the above user interface and add necessary controls to the form.
Note: Give meaningful names and property values to each control.
2. Change the caption property value of the form to “ DAPARTMENT ALLOWANCE”
3. Write a code a display the “New Salary” when you click on the “calculate button.

4. Write a code to display the following message box when you click on the close button.
5. Save the form as “salfrom.vb” & the project as “salproject.sln”
6. Create an executable file. Name it as “salproject”

131 Vocational Training Authority of Sri Lanka - Jaffna


ICT VB.NET

1. Create the following forms and save it on 2008 Decnew.VB project. And assign a suitable / given
name for the objects and titles.
2. When you run the project, startup object should be MENU Form.
3. Menu Form,
Assign the following to Menu Options.
Temperature – To open temperature Conversion Form
Distance – to open Distance Conversion Form
Exit –To close the Project

4. Temperature Conversation Form


Input - User can enter temperature and select measurements
Result - Will produce output (Fahrenheit to Celsius OR Celsius to Fahrenheit)
- IF measurements unit is not selected it will give an error message.
(Hint: - Celsius= ((Fahrenheit)-32)*5/9), Fahrenheit= ((Celsius)*9/5)+32

5. Distance Conversion Form


Input - User can enter temperature and select measurements
Result - Will produce output (Miles to Kilometers Or Kilometers to Miles)
-IF measurements unit is not selected it will give an error message
(Hint:- Miles= Kilometers * 5/8, Kilometers = Miles * 8/5)

132 Vocational Training Authority of Sri Lanka - Jaffna


ICT VB.NET
Calculate Interest amount and Total amount using Visual Basic.

1. Design above user interface using necessary controls to form.


[Note: Give the meaning name and property values to each control]
2. Write the code to display the following message box. When you click on “Calculate” button.
If the Customer No is not entered.
3. Write the code to calculate the Interest amount and Total amount when you click the “Calculate”
button according to the selected interest rates( 6 Month Deposits or 12 Months Deposits)
Note: if you select 6 month Deposits= amount x 12% otherwise
If you select 12 Months Deposits= amount x 15%

4. Write the code to clear the data in all text box objects when you click the “Clear” button.
5. Write the code to close the programme when click “Exit” button.
6. Save the Form as “Deposits_Form.vb” and projects as “Deposit_Project.sln”.

133 Vocational Training Authority of Sri Lanka - Jaffna


ICT VB.NET
1. Create an new project called “Myage”
2. Design the following form and name it as Age.

3. When TODAY button is clicked Today-DAY, Today-MONTH, Today-YEAR text boxes should
display Today-DAY, Today-MONTH, and Today-YEAR from computer System Date.
Hint: If necessary use Now, Day, Month, Today-YEAR form computer System Date.
Now- will return the System date
Day (date) - will return the day number from date
Month (date) - will return the month from date
Year (date) - will return the year from date
4. Date of Birth can be selected by the user from combo box(Birth-DAY, Birth-MONTH, Birth-
YEAR)
Birth-DAY -List range 1-31
Birth- MONTH-List range 1-12
Birth-YEAR- List range 1970-1990

5. Write click event for the Calculate Age button to display Age (days in Age-DAYS months in
Age-MONTHS and years in Age-YEARS from Date of Birth and TODAY).
(Assume that the 30 days per month)
Eg: days Months Years
TODAY 15 07 2008
Date of Birth 28 09 1980
Age 17 09 27
6. Create Myage.vb file

134 Vocational Training Authority of Sri Lanka - Jaffna


ICT VB.NET

1. Design above interface by adding given controls.


2. Add Mr, Miss, Ms data to the title combo control and make “Mr.” as default
3. Get the system data and display on top right corner of the form when the application started(run)
4. Calculate the “Account Status” and display at the bottom of the form by using following criteria.
If the Customer status is “pending” display “No Interest paid”
If the Customer Status is “Inactive” display “1% amount debited” and display the 0.1% amount
from the Amount Deposited.
If the customer status is Active display the “3% Interest paid” and 2% interest value from the
Amount Deposited.
5. Write codes to disable the other two check boxes, “Receive Mails” and “Contact by Phone”,
When you select “Do not Contact” check box from the preferences.
6. Write codes to clear text boxes and make Mr. as Title and Customer status as pending when you
click Clear Button.
7. Write code to close the application when you click Exit button.
8. Make your projects as “DataEntry.EXE” file.

135 Vocational Training Authority of Sri Lanka - Jaffna


ICT VB.NET

1. Design the above interface by adding relevant controls.


2. All the button are deactive until enter a vehicle no and click “Enter” button
3. Fill the “Type” Type combo control with following data items. Make first item as default.
Data items: - Bus, Lorry, Van, Car, Motorcycle
4. Fill Year combo control to select Year from 1970 to 2010 as default item.
(Use With. command and For.. loop to fill combo control)
5. Fill the List control to select “Make” form the following. Data item when you select items from
the list it should appear in the text box above the list control.
(Data item: - Mitsubishi, Toyata, Zuzuki, Honda, TVS, Bajaj)
6. Calculate the “Registration Fee” based on the following criteria.
When the fuel type is not the Diesel
Vehicle Type Fee
Bus 2500
Lorry 2500
Van 1500
Car 1750
Motor Cycle 400
When the fuel type is Diesel annual tax 5000 should be add to the registration fee.
(You can use If... and Select Case…structure to find the vehicle type and make correct
calculation)
7. Save your project with “vregister” name and Make “Vehicle.vb” file.

136 Vocational Training Authority of Sri Lanka - Jaffna


ICT VB.NET

Find out the result of the following Console Applications.


Exercise 1:

Module Example1
SubMain()
Dim message AsString' declaration (1)
message = "Hello World !"' initial assignment (2)
'
' or :
' Dim message As String = "Hello World !" ' initialization (3)
'
Console.WriteLine(message)
'
Console.ReadLine()
EndSub
EndModule

Exercise 2:

Module Example2
SubMain()
Dim value1 AsInteger
Dim value2 AsInteger
Dim sum AsInteger
value1 = 1
value2 = 2
sum = value1 + value2
Console.WriteLine(value1 &" + "& value2 & _" = "& sum)
Console.ReadLine()
EndSub
EndModule

Exercise 3:

Module Example3
SubMain()
Dim name AsString
Dim age AsInteger
'
Console.WriteLine("Name ?")
name = Console.ReadLine()
'
Console.WriteLine("Age ?")
age = Console.ReadLine()
'
Console.WriteLine("Your name is "& name &".")
Console.WriteLine("Your age is "& age &".")
'
Console.ReadLine()
EndSub
EndModule
137 Vocational Training Authority of Sri Lanka - Jaffna
ICT VB.NET

Exercise 4:

Module Exercise4
SubMain()
Dim number, square AsInteger
'
Console.WriteLine("Number ?")
number = Console.ReadLine()
'
square = number ^ 2
'
Console.WriteLine("Square of "& number &" is "& square &".")
'
Console.ReadLine()
EndSub
EndModule

Exercise 5:

Module Example5
SubMain()
Console.WriteLine(1)
Console.WriteLine(2)
Console.WriteLine(3)
'
Console.ReadLine()
EndSub
EndModule

Exercise 6:

Module Example6
SubMain()
Dim value AsInteger
'
value = value + 1
Console.WriteLine(value)
'
value = value + 1
Console.WriteLine(value)
'
value = value + 1
Console.WriteLine(value)
'
Console.ReadLine()
EndSub
EndModule

138 Vocational Training Authority of Sri Lanka - Jaffna


ICT VB.NET
Exercise 7:

Module Example7
SubMain()
Dim value AsInteger
'
DoWhile value < 3
value = value + 1
Console.WriteLine(value)
Loop
'
Console.ReadLine()
EndSub
EndModule

Exercise 8:

Module Example8
SubMain()
DimstartValueAsInteger = 10
DimendValueAsInteger = 15
'
Dim value AsInteger = startValue - 1
DoWhile value <endValue
value = value + 1
Console.WriteLine(value)
Loop
'
Console.ReadLine()
EndSub
EndModule

Exercise 9:

Make a program that brings all numbers from 20 to 10 on the console.

Output :
20
19
18
17
16
15
14
13
12
11
10

139 Vocational Training Authority of Sri Lanka - Jaffna


ICT VB.NET
Exercise 10:

Make a program that brings all powers of 2 smaller (starting with exponent 1) than 1000 on the
console.

Output :
base : 2, exponent : 1, result : 2
base : 2, exponent : 2, result : 4
base : 2, exponent : 3, result : 8
base : 2, exponent : 4, result : 16
base : 2, exponent : 5, result : 32
base : 2, exponent : 6, result : 64
base : 2, exponent : 7, result : 128
base : 2, exponent : 8, result : 256
base : 2, exponent : 9, result : 512

Exercise 11:

Module Example11
SubMain()
Console.WriteLine("Value ?")
Dim value AsInteger = Console.ReadLine()
'
If value Mod 2 = 0 Then
Console.WriteLine("Half of "& value &" is "& value / 2 &".")
Else
Console.WriteLine("Double of "& value &" is "& value * 2 &".")
EndIf
'
Console.ReadLine()
EndSub
EndModule

Exercise 12:

Make a program based on the following output (input is in italic).

Output :
Value?
0
Zero.

Output :
Value?
123
Value 123 is not equal to zero.

140 Vocational Training Authority of Sri Lanka - Jaffna


ICT VB.NET

Example
In this example, we create three text boxes and use the Click event of a button to display the entered
text using a message box. Take the following steps:
1. Drag and drop three Label controls and three TextBox controls on the form.
2. Change the texts on the labels to: Name, Organization and Comments, respectively.
3. Change the names of the text boxes to txtName, txtOrg and txtComment, respectively.
4. Drag and drop a button control on the form. Set its name to btnMessage and its text property to
'Send Message'.
5. Click the button to add the Click event in the code window and add the following code.
PublicClass Form1
PrivateSub Form1_Load(sender AsObject, e AsEventArgs) _
HandlesMyBase.Load
' Set the caption bar text of the form.
Me.Text="tutorialspont.com"
EndSub

PrivateSubbtnMessage_Click(sender AsObject, e AsEventArgs) _


HandlesbtnMessage.Click
MessageBox.Show("Thank you "+txtName.Text+" from "+txtOrg.Text)
EndSub
EndClass

When the above code is executed and run using Start button available at the Microsoft Visual
Studio tool bar, it will show the following window:

Clicking the Send Message button would show the following message box:

141 Vocational Training Authority of Sri Lanka - Jaffna


ICT VB.NET

Example
In the following example, we create three buttons. In this example, let us:
 Set captions for the buttons
 Set some image for the button
 Handle the click events of each buttons
Take following steps:
1. Drag and drop a Label control on the form.
2. Set the Text property to provide the caption "Tutorials Point".
3. Drag and drop three buttons on the form.
4. Using the properties window, change the Name properties of the buttons to btnMoto, btnLogo and
btnExit respectively.
5. Using the properties window, change the Text properties of the buttons to Show Moto, Show Logo
and Exit respectively.
6. Drag and Drop another button, using the properties window, set its Image property and name it
btnImage.
At this stage, the form looks like:

Click the form and add following code in the code editor:
PublicClass Form1

142 Vocational Training Authority of Sri Lanka - Jaffna


ICT VB.NET
PrivateSub Form1_Load(sender AsObject, e AsEventArgs)HandlesMyBase.Load
' Set the caption bar text of the form.
Me.Text="tutorialspont.com"
btnImage.Visible=False
EndSub
PrivateSubbtnMoto_Click(sender AsObject, e AsEventArgs)HandlesbtnMoto.Click
btnImage.Visible=False
Label1.Text ="Simple Easy Learning"
EndSub
PrivateSubbtnExit_Click(sender AsObject, e AsEventArgs)HandlesbtnExit.Click
Application.Exit()
EndSub
PrivateSubbtnLogo_Click(sender AsObject, e AsEventArgs)HandlesbtnLogo.Click
Label1.Visible =False
btnImage.Visible=True
EndSub
EndClass

Clicking the first button, displays:

Clicking the second button displays:


Clicking the third button, exits the application.

143 Vocational Training Authority of Sri Lanka - Jaffna


ICT VB.NET
Example 1
In the following example, let us add a list box at design time and add items on it at runtime.
Take the following steps:
1. Drag and drop two labels, a button and a ListBox control on the form.
2. Set the Text property of the first label to provide the caption "Choose your favourite destination for
higher studies".
3. Set the Text property of the second label to provide the caption "Destination". The text on this label
will change at runtime when the user selects an item on the list.
4. Click the listbox and the button controls to add the following codes in the code editor.
PublicClass Form1
PrivateSub Form1_Load(sender AsObject, e AsEventArgs)HandlesMyBase.Load
' Set the caption bar text of the form.
Me.Text="tutorialspont.com"
ListBox1.Items.Add("Canada")
ListBox1.Items.Add("USA")
ListBox1.Items.Add("UK")
ListBox1.Items.Add("Japan")
ListBox1.Items.Add("Russia")
ListBox1.Items.Add("China")
ListBox1.Items.Add("India")
EndSub

PrivateSub Button1_Click(sender AsObject, e AsEventArgs)Handles Button1.Click


MsgBox("You have selected "+ ListBox1.SelectedItem.ToString())
EndSub
PrivateSub ListBox1_SelectedIndexChanged(sender AsObject, e AsEventArgs)
Handles ListBox1.SelectedIndexChanged
Label2.Text =ListBox1.SelectedItem.ToString()
EndSub
EndClass

When the above code is executed and run using Start button available at the Microsoft Visual
Studio tool bar, it will show the following window:

144 Vocational Training Authority of Sri Lanka - Jaffna


ICT VB.NET

When the user chooses a destination, the text in the second label changes:

Clicking the Select button displays a message box with the user's choice:

145 Vocational Training Authority of Sri Lanka - Jaffna


ICT VB.NET
Example
In the following example, let us create two groups of radio buttons and use their CheckedChanged
events for changing the BackColor and ForeColor property of the form.

Let's double click on the radio buttons and put the follow code in the opened window.
PublicClass Form1
PrivateSub Form1_Load(sender AsObject, e AsEventArgs)HandlesMyBase.Load
' Set the caption bar text of the form.
Me.Text="tutorialspont.com"
EndSub

PrivateSub RadioButton1_CheckedChanged(sender AsObject, _


eAsEventArgs)Handles RadioButton1.CheckedChanged
Me.BackColor=Color.Red
EndSub
PrivateSub RadioButton2_CheckedChanged(sender AsObject, _
eAsEventArgs)Handles RadioButton2.CheckedChanged
Me.BackColor=Color.Green
EndSub
PrivateSub RadioButton3_CheckedChanged(sender AsObject, _
eAsEventArgs)Handles RadioButton3.CheckedChanged
Me.BackColor=Color.Blue
EndSub

PrivateSub RadioButton4_CheckedChanged(sender AsObject, _


eAsEventArgs)Handles RadioButton4.CheckedChanged
Me.ForeColor=Color.Black
EndSub
PrivateSub RadioButton5_CheckedChanged(sender AsObject, _
eAsEventArgs)Handles RadioButton5.CheckedChanged
Me.ForeColor=Color.White
EndSub

146 Vocational Training Authority of Sri Lanka - Jaffna


ICT VB.NET
PrivateSub RadioButton6_CheckedChanged(sender AsObject, _
eAsEventArgs)Handles RadioButton6.CheckedChanged
Me.ForeColor=Color.Red
EndSub
EndClass

When the above code is executed and run using Start button available at the Microsoft Visual
Studio tool bar, it will show the following window:

147 Vocational Training Authority of Sri Lanka - Jaffna


ICT VB.NET
Example
In this example, let us add four check boxes in a group box. The check boxes will allow the users to
choose the source from which they came to know about the organization. If the user chooses the
check box with text "others", then the user is asked to specify and a text box is provided to give
input. When the user clicks the Submit button, he/she gets an appropriate message.
The form in design view:

Let's put the following code in the code editor window:


PublicClass Form1
PrivateSub Form1_Load(sender AsObject, e AsEventArgs) _
HandlesMyBase.Load
' Set the caption bar text of the form.
Me.Text="tutorialspoint.com"
Label1.Visible =False
TextBox1.Visible =False
TextBox1.Multiline =True
EndSub
PrivateSub Button1_Click(sender AsObject, e AsEventArgs) _
Handles Button1.Click
DimstrAsString
str=" "
If CheckBox1.Checked =TrueThen
str&= CheckBox1.Text
str&=" "
EndIf
If CheckBox2.Checked =TrueThen
str&= CheckBox2.Text
str&=" "
EndIf
If CheckBox3.Checked =TrueThen
str&= CheckBox3.Text
str&=" "
148 Vocational Training Authority of Sri Lanka - Jaffna
ICT VB.NET
EndIf
If CheckBox4.Checked =TrueThen
str&= TextBox1.Text
str&=" "
EndIf
Ifstr<>NothingThen
MsgBox(str+vbLf+"Thank you")
EndIf
EndSub
PrivateSub CheckBox4_CheckedChanged(sender AsObject, _
eAsEventArgs)Handles CheckBox4.CheckedChanged
Label1.Visible =True
TextBox1.Visible =True
EndSub
EndClass

When the above code is executed and run using Start button available at the Microsoft Visual
Studio tool bar, it will show the following window:

Checking all the boxes:

Clicking the Submit button:

149 Vocational Training Authority of Sri Lanka - Jaffna


ICT VB.NET
Example
In this example, let us create a list view at runtime. Let's double click on the Form and put the
follow code in the opened window.
PublicClass Form1
PrivateSub Form1_Load(sender AsObject, e AsEventArgs)HandlesMyBase.Load
'create a new ListView
Dim ListView1 AsListView
ListView1 =NewListView()
ListView1.Location =NewPoint(10,10)
ListView1.Size =NewSize(150,150)
Me.Controls.Add(ListView1)
'Creating the list items
Dim ListItem1 AsListViewItem
ListItem1 =ListView1.Items.Add("Item 1")
Dim ListItem2 AsListViewItem
ListItem2 =ListView1.Items.Add("Item 2")
Dim ListItem3 AsListViewItem
ListItem3 =ListView1.Items.Add("Item 3")
Dim ListItem4 AsListViewItem
ListItem4 =ListView1.Items.Add("Item 4")
'set the view property
ListView1.View =View.SmallIcon
' Set the caption bar text of the form.
Me.Text="tutorialspoint.com"
EndSub
EndClass

When the above code is executed and run using Start button available at the Microsoft Visual
Studio tool bar, it will show the following window:

150 Vocational Training Authority of Sri Lanka - Jaffna


ICT VB.NET
Adding Menus and Sub Menus in an Application
Traditionally, the Menu, MainMenu, ContextMenu, and MenuItem classes were used for adding
menus, sub-menus and context menus in a Windows application.
Now,the MenuStrip,the ToolStripMenuItem, ToolStripDropDown and ToolStripDropDownM
enucontrols replace and add functionality to the Menu related controls of previous versions.
However, the old control classes are retained for both backward compatibility and future use.
Let us create a typical windows main menu bar and sub menus using the old versions controls first.
Since these controls are still much used in old applications.
Following is an example which shows how we create a menu bar with menu items: File, Edit, View
and Project. The File menu has the sub menus New, Open and Save.
Let's double click on the Form and put the follow code in the opened window.
PublicClass Form1
PrivateSub Form1_Load(sender AsObject, e AsEventArgs)HandlesMyBase.Load
'defining the main menu bar
DimmnuBarAsNewMainMenu()
'defining the menu items for the main menu bar
DimmyMenuItemFileAsNewMenuItem("&File")
DimmyMenuItemEditAsNewMenuItem("&Edit")
DimmyMenuItemViewAsNewMenuItem("&View")
DimmyMenuItemProjectAsNewMenuItem("&Project")

'adding the menu items to the main menu bar


mnuBar.MenuItems.Add(myMenuItemFile)
mnuBar.MenuItems.Add(myMenuItemEdit)
mnuBar.MenuItems.Add(myMenuItemView)
mnuBar.MenuItems.Add(myMenuItemProject)

' defining some sub menus


DimmyMenuItemNewAsNewMenuItem("&New")
DimmyMenuItemOpenAsNewMenuItem("&Open")
DimmyMenuItemSaveAsNewMenuItem("&Save")

'add sub menus to the File menu


myMenuItemFile.MenuItems.Add(myMenuItemNew)
myMenuItemFile.MenuItems.Add(myMenuItemOpen)
myMenuItemFile.MenuItems.Add(myMenuItemSave)

'add the main menu to the form


Me.Menu=mnuBar
' Set the caption bar text of the form.
Me.Text="tutorialspoint.com"
EndSub
EndClass

151 Vocational Training Authority of Sri Lanka - Jaffna


ICT VB.NET
When the above code is executed and run using Start button available at the Microsoft Visual
Studio tool bar, it will show the following window:

152 Vocational Training Authority of Sri Lanka - Jaffna

You might also like