net/publication/364327123
CITATIONS READS
0 3,804
1 author:
Ahlam M. Kadhim
Mustansiriyah University
25 PUBLICATIONS 37 CITATIONS
SEE PROFILE
All content following this page was uploaded by Ahlam M. Kadhim on 14 October 2022.
قسم الفيزياء
Department of Physics
Course in
Programming
Visual Basic 6.0
Supervised and prepared by
Assistant Professor Dr. Ahlam M. Kadhim
Second year
What is Visual Basic?
Visual Basic is one of the most important and powerful programming
languages that are widely used nowadays. Visual Basic is a tool that
allows you to develop Windows (Graphic User Interface - GUI)
applications. Visual Basic is governed by an event processor. Nothing
happens until an event is detected. Once an event is detected, the code
corresponding to that event (event procedure) is executed. Program
control is then returned to the event processor. The use of this language is
due to two main reasons:
1. The ease of learning this language and the breadth of its
applications.
2. Continuous support from Microsoft in updating this language and
adding many features that address many modern topics.
Variables Types
Type Description
String Symbolic Variable
Boolean Logical variable True or False (0, 1)
Integer -32768 to 32767
Long -2x109 to 2x109
Single 1.40129x10-45 to 3.40283x1038
Double 4.94065x10-324 to 1.7976x10308
Date January 1st 100 To December 31st 9999
Variant All variables
Numerical Operators
Solution:
Dim a, b, y As Double
Private Sub Command1_Click ()
a = Val (Text1.Text)
b = Val (Text2.Text)
Pi = 3.14
y = b + (4 * pi * a ^ 3) / 3
Text3.Text = y
End Sub
3
Visual Basic also includes two additional arithmetic operators,
the division sign / gives the result of an integer and the division
sign \ (backslash) that gives the result of integers and fractions
Solution:
Function Task
X=RND Create random number value (0…1)
Y=ABS(X) |𝑥|
Y=SQR(X) √𝑥
Y=EXP(X) ex
Y=LOG(X) Len(x)
Y=LOG(X) / LOG(10) Log(x)
Y=sin(X)
Y=cos(X)
Trigonometric function
Y=tan(X)
4
Y=ATN(x) Tan-1(x)
Y=INT(X) Take rounding value of x
Y=FIX(X) Take only integer part
Conversion Functions:
Solution:
Dim X As Double
Private Sub Command1_Click( )
X = InputBox("Enter Number")
List1.AddItem y
End Sub
Private Sub Command2_Click( )
y = CLng(X)
List1.AddItem y
5
End Sub
Project 5: Write a program code that shows the use of the Rnd
function to randomly choose among ten numbers, when a certain
number appears, the image is displayed and the program plays
the sound?
Solution:
7
Project 7: Write the previous program using other tools?
Solution:
Solution:
Solution:
Private Sub Form_Load()
Dim I
For I=1 To 10
List1.AddItem Str(I)
List2.AddItem Str(I)
Next I
Combo1.AddItem “+”
Combo1.AddItem “-”
Combo1.AddItem “*”
Combo1.AddItem “/”
End Sub
Solution:
11
Project 12: Write a program to enter any list of numbers such as
(3,7, 9, 6, 10,4,20 and 40), print the numbers that are divisible
by a certain number (5, 2) display them by one V.B tools ?
Solution:
Solution:
Solution:
14
1–D Arrays
Arrays are declared in a manner identical to that used for regular
variables. For example, to declare an integer array named ‘A',
with dimension 6, at the procedure level, we use:
Dim A (6) as Integer
In the illustration below, A is the matrix name, and the number 6
in parentheses is the upper bound of matrix. The above
declaration creates empty positions in the computer's memory
for an array of 6 elements, with sequence numbers 0 to 5. The
numbers inside the parentheses are called the locations of the
19
2-Dimension (2-D) Arrays
Project 24: Find the sum of the main diameter elements and
print them on the list box or another tool such as a picture box?
Solution:
Project 25: Write a program to print a matrix and find the sum
of the elements of any row or column of the matrix?
Project 25: Write a program to print the unit matrix, i.e. all the
elements of the principal diagonal are 1 and the other elements
are zero?
Solution:
23
Project 26: Write a program to print the sum of the elements of
any matrix?
Solution:
For k = 1 To 4
v(k) =
Val(InputBox("enter v"))
sumV = sumV + v(k)
Next
sumV
MeanV =
4
For k = 1 To 4
I(k) = Val(InputBox("enter i"))
sumI = sumI + I(k)
Next
sumI
MeanI =
4
25
MeanV
R =
MeanI
Text1.Text = CStr(R)
b) Draw the graph between the current and voltages.
Scale (0, 0)-(100, 100)
PSet (10, 10)
PSet (20, 20)
PSet (30, 30)
PSet (40, 40)
Line (10, 10)-(20, 20)
Line (20, 20)-(30, 30)
Line (30, 30)-(40, 40)
End Sub
HW: Give values less than 100 and greater than 0 and specify
the dimensions of the form by instructing scal?
26
Private Sub Timer1_Timer()
Static I As Integer
FillStyle = 2
FillColor = QBColor(5)
I=I+1
'Circle (50, 50), I, vbBlue
'Line (50 - I, 50 - I)-(50 + I, 50 + I), vbRed, B
Line (I, I)-(I + 10, I + 10), RGB(50, 200, 0), B
If I = 50 Then
I=0
Form1.Cls
End If
End Sub
27
Private Sub Timer1_Timer()
Dim i As Integer
Static j As Integer
For i = 0 To 9
Image1(i).Visible = False
Next i
Image1(j).Visible = True
If Command1.Caption = "Right" Then
j=j+1
Else
j=j-1
End If
If j = 10 Then j = 0
If j = -1 Then j = 9
End Sub
28
References:
1. “Programming with Microsoft ® Visual Basic®2017”, Eighth Edition
Printed in the United States of America Print Number: 01 Print Year:
2017© 2018 Cengage Learning.
2. “Introduction visual Basic 6.0”, 1stedition, 2013 Gary Haggard, Wade
Hutchison & Christy Shibata & bookboon.com.
3. Visual Basic for Electronics Engineering Applications. Copyright
1999 – 2005 Vincent Himpe. The author recognizes the copyrights,
trademarks and registered trademarks of all products mentioned in this
book. Initial edition 5-9-1999. Second revised edition 09-03-2002 E-
mail: vincent_himpe@hotmail.com.
4. "Windows Programming Microsoft Visual Basic 6.0" Chapter One
University of Baghdad Collage of Education For Pure Science Dep.of
Computer Science Third Stage M.Sc. Lubab Ahmed
5. “Course Notes for: Learn Visual Basic 6.0” , © Lou Tylee, 1998
KIDware 15600 NE 8th, Suite B1-314 Bellevue, WA 98008 (206)
721-2556 FAX (425) 746-4655.
6. تاليف احمد صادق, ""اكواد الفجوال بيسك
7. 2008 "فجوال بيسك خطوة بخطوة" تاليف احمد جمال خليفة
8. تاليف انس ابراهيم محفوظ, "6 "تميز مع فجوال بيسك
9. " تاليف محمد عبد الناصر الخطيب6 "فجوال بيسك ستوديو
29