Visual BASIC


Exercise 2.1
Write a program using a FOR...NEXT loop to display all the even numbers from 2 to 10. Then shows the arithmetic operations using two integers.

Private Sub Form_Activate()
'Rem This program prints numbers using a loop
'Rem and performs arithmetic operations.
Dim n As Integer

For n = 2 To 10 Step 2 'FOR...NEXT Loop
Print n
Next n

Print "Welcome to VB"
Print 5 + 2
Print 5 - 2
Print 5 * 2
Print 5 / 2
Print 5 ^ 2
End Sub


Exercise 2.2
Insert one Image and Picture on a form.
Private Sub Form_Load()
Picture1.Picture = LoadPicture("C:\Program Files\Java\j2re1.4.2_01\javaws\JavaCup.ICO")
End Sub


Exercise 2.3
Insert one ComboBox and one ListBox on a form.
Double click the form and insert the following code:

Private Sub Form_Load()

Rem A Combobox of States in Malaysia
ComboState.AddItem "Sabah"
ComboState.AddItem "Sarawak"
ComboState.AddItem "Perak"

Etc. Note: Insert all the states in Malaysia.


Rem A Listbox of 7 places of interest in Sabah List1.AddItem "Mount Kinabalu"
List1.AddItem "Orang Utan Sanctuary at Sepilok"
List1.AddItem "Sabah State Museum"
End Sub


Exercise 2.4
Checkboxes.

Write a program to bold and/or italic a sentence.
Private Sub chkBold_Click()
If chkBold.Value = 1 Then ' If checked.
  txtDisplay.FontBold = True
Else ' If not checked.
  txtDisplay.FontBold = False
End If
End Sub

Private Sub chkItalic_Click()
If chkItalic.Value = 1 Then ' If checked.
  txtDisplay.FontItalic = True
Else ' If not checked.
  txtDisplay.FontItalic = False
End If
End Sub


References

VB Tutorial - University of Calgary, Canada

VBTutor.net _Lesson 3

Devdos.com - Lesson 3

 

Hosted by www.Geocities.ws

1