Running The IDE (The Integrated Development Environment)
Running The IDE (The Integrated Development Environment)
Programming
Microsoft Visual Basic 6.0
Chapter 1
Getting Started MS VB 6.0
Running the IDE (The Integrated Development Environment)
You can choose from several ways to launch the Visual Basic IDE, as is true for any
Windows executable:
• You can run the Visual Basic 6 environment from the Start Menu; the exact
path to the menu command depends on whether you have installed Visual Basic as
part of the Microsoft Visual Studio suite.
• You can create a shortcut to the IDE on your desktop and run it by simply
double-clicking on it.
Choose Standard.EXE and click the Open button. Then you are in the Project1 –
Microsoft Visual Basis (design) window. See below.
Project
Explorer
Tool Box
Pointer PictureBox
Label Textbox
Frame CommandButton
CheckBox OptionButton
ComboBox ListBox
hsb vsb
Timer DriveListBox
DirList FileListBox
Shape Line
Image Data
OLE
13. Drive List Box Lets the users select a disk drive. drv
14. Directory List Lets the users select a Box directory or dir
folder.
15. File List Box Lets the users select a file. fil
You have to fix the properties for the command button Command1. Two most
important properties you should not forget are Caption and Name.
• Caption : - It is to let know a user what the button intends to operate (event).
4
Properties Setting
After you have written the coding , Save your Project like as frmGreeting
for Project Name and Form Name . Then , Click on RunButton OR
Press F5 to run the program .
5
Properties Setting
Object Property Value
Form - (Name) - frmDateTime
- Caption - Date & Time Program
1.11 InputBox :
Syntax : InputBox (Prompt,[Title], [ Default] ,[XPos], [YPos],
[ Helpfile],[Context] ) As String
10
Declaring Variables
• Format : Dim (Variable Name) As (Data Type)
• Example Dim SecondNo As Double
Note :
A variable name:
Must begin with a letter.
Must not exceed 255 characters.
Must be unique within the same scope.
Must not be a Visual Basic reserved word.
Exercises
1.1
The form should have one textbox and a command button. The user can type a string
in the textbox. Whenever the command button is clicked , the caption of the form
should be changed to the string typed in the textbox.
• Open a project.
• Add a textbox control and a command button on the form.
• Write the following code.
Private Sub cmdChange_Click()
cmdChange .Caption=Text1.Text
End Sub
• Save the project and form sub .
(FrmChanging)
• Press F5 to run the program.
1.2
• Create the following form with one CommandButton, and 4 TextBoxes to find
the saving of a deposit 200,000 Kyats after 5 years, where given that interest is 15 %
per year. Properties setting is given below.
• (Extra properties are used in this exercise, such as alignments for text
boxes all of same size; Height 400, Width 1225 and Left 1320).
Coding
Private Sub cmdCalculate_Click()
Deposit = Val(txtDeposite.Text)
IR = Val(txtInterest.Text) / 100
yr = Val(txtYear.Text)
TotalAmount = Deposit * (1 + yr * IR)
txtTotal.Text = Format(TotalAmount,
"Fixed")
End Sub
12
1.3
Create the Form shown here to calculate
• the sum of two numbers. Numbers should be Floats.
• All fonts in Times New Roman, Bold, Size 12.
Coding
Private Sub cmdSum_Click()
Dim FirstNo As Double
Dim SecondNo As Double
Dim Result As Double
FirstNo = CDbl(txtFirstNo.Text)
SecondNo = Val(txtSecondNo.Text)
Result = FirstNo + SecondNo
lblResult . Caption = Format(Result)
End Sub
The first three lines declare variables. Note carefully ‘ Dim, Double, CDbl(), Val(),
Format()..etc.
You can use Val() for the function CDbl() and also Str() for Format().