0% found this document useful (0 votes)
33 views

Programming With Visual Basic

The document discusses programming with Visual Basic. It covers 1) an introduction to Visual Basic, 2) forms and control tools, and 3) project explorer, properties, and events. It then discusses 4) building and saving projects and applications, 5) files, projects, and exercises, and 6) dialogue boxes and message boxes. The remaining sections cover various Visual Basic statements, elements, and programming concepts.

Uploaded by

Mohammed Abdo
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Programming With Visual Basic

The document discusses programming with Visual Basic. It covers 1) an introduction to Visual Basic, 2) forms and control tools, and 3) project explorer, properties, and events. It then discusses 4) building and saving projects and applications, 5) files, projects, and exercises, and 6) dialogue boxes and message boxes. The remaining sections cover various Visual Basic statements, elements, and programming concepts.

Uploaded by

Mohammed Abdo
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

Programming with visual Basic:

1-Introdution to Visual Basics


2-Forms and Control tools.

3-Project explorer, properties and events.


)( 4-make project, save it and its applications.
5- Files projects and exercises.
6- Dialogue boxes message boxes.

7-Basic elements for visual basic statements, Variables, assignment statements.

.
8-General view on assignment statement, constants and operations.
.

9-Adding astringe of variable. .


10-Control statements and Ifthen statements.
.

11-If-hen-els statement.
12-Select statement.
13-For-next statement.
14-Condition loop .

15-Nested-loop.
16-Seguences.

Microsoft Visual
Basic
6.0

Visual Basic

.
Basic
Beginning All purpose Symbolic Instruction Code "
" ) (VB ) (Windows

Dos
... .

VB graphical

user interface
.
VB
Objects Properties

Actions Events

:
Start>Programs>Microsoft Visual Studio 6.0>Microsoft Visual Basic 6.0

. ) (

VB .

Visual Basic

a
b
f

d
e

(a :Menu bar
.

(b :Toolbar .
(c :Toolbox Controls

.. :
( )(Pointer

: .

( )(Picture box
( )(Label

: .

( )(Text Box
( )(Frame

: .

.: .

( )(Command Button
( )(Check Box

: .
:

( )(Option Button
.

/
( )(Combo Box

Visual Basic

: Drop-

.Down list
: .

( )(List Box

( )(Horizontal Scrollbar
( )(Vertical Scrollbar
( )(Timer

: .

: .

: .

( )(Drive List Box


.

( )(Dir List Box


.

( )(File List Box

:
:
:

.
( )(Shape
( )(Line

( )(Image

:
: .

).(Stretch
( )(Data

( )(OLE

: .
: .

(d :Form Window
.
:Properties Window object

.

(e :Project Explorer Window



(f :Form Layout Window
.

(g :Code Window
. Code Private sub

Visual Basic


End sub .


.
) ( VB
.

:
( ) :(design objects
toolbox

Visual Basic

) (
)Project1-Microsoft Visual Basic (design
( ) :(Code object

)Project1-Form1 (Code
) :(Run Form
Start

Run

. End

Run

.
:

Save Project File Save File as


save Save
Project as .save

. VB

. )( Label
: :

Visual Basic


""=Labelno.caption


caption

)(Labelno.backcolor =QBcolor

backcolor

)(Labelno.forecolor =QBcolor

forecolor

)(= Labelno.fontsize
= or Labelno.fontsize

Fontsize

: " " .
:

: label
label .
caption " "Label1 " ".

Font size

: .

Visual Basic

. Text box control


:


) (


""=textno.text


Text

)(textno.backcolor =QBcolor

backcolor

)(textno.forecolor =QBcolor

forecolor

Multiline True

Multiline

Multiline False

Enabled
textno.Enabled=true

textno.Enabled=false
text
text

delete .

: " "welcome to visual basic world


.

:
.
Te
:

textbox form text text1


.welcome to visual basic world

multiline text1 false .true

. Command Button
:

Visual Basic


""=commandno.caption


caption

1-Graphical
0-Standard

Style

)(commandno.backcolor =QBcolor

backcolor

style
1-Graphical

: form label ) name (


.label
Label

Comma

label form caption label1


.

command button form caption

command1 .name
command1 :

)(Private Sub Command1_Click


"Label1.Caption = "Ahmad
End Sub

)(

/ form .

/ Calculator ) (
.
/ :

Visual Basic

. Form
VB form

: object
.form


name

)(0-15
)(0-15

" "=formno.caption

caption

) (

)(formno.backcolor=QBcolor

backcolor

)(formno.forecolor=QBcolor

forecolor

. Shape
:

0-rectangle
1-square
2-oval
3-circle
0-trancsparence
1-opaque


shape

backstyle
backcolor
bordercolor

: .
) : (

shape1 shape

) ( shape shape1
) 3- circle (.

Visual Basic

) label1 ( caption
label1 .circle

Sha
Lab
. . List box
- :design stage

list Listno )

( .

: VB form label show


hide form
show hide

display .
:
: .form2
Form1
" "=Label1: caption
"Command1: caption="show

Visual Basic
"Command2: caption="hide

Label1

Command2

Command1

form2 :

. Option Button
:

Caption, Font, Enabled, BackColor and visible

Command Button .click


: form red, blue, green
.
:
: :
option1:caption
green
option2: caption
blue
option3: caption
red
caption option1 option2 green
:

Visual Basic

qbcolor vb
.
Private Sub Option1_Click()
Form1.BackColor = vbGreen
End Sub
Private Sub Option2_Click()
Form1.BackColor = vbBlue
End Sub
Private Sub Option3_Click()
Form1.BackColor = vbRed
End Sub
Check Box
Caption, Font, Enabled, BackColor, Forecolor, value and :
visible
.Text Box :
: text . : :
Text1

Text
Text1
Check1
caption Bold
Check2
Check1
caption Italic
Check2
Check3
caption underline
Check3
Private Sub Check1_Click()
Text1.FontBold = Check1.Value
End Sub
Private Sub Check2_Click()
Text1.FontItalic = Check2.Value
End Sub
Private Sub Check3_Click()
Text1.FontUnderline = Check3.Value
End Sub

Visual Basic

. Timer
:


Interval

) (

)(true/false

enabled

timer interval
: .
: : timer interval timer1
1000 label caption
label1 .

Label

Timer
:
)(Private Sub Timer1_Timer
Label1.Caption = Time
End Sub
: time . label1

. Input-Output Boxes
Input Box .Message Box

.
Message box

.Msgbox
Msgbox:
"Msgbox "Message", Symbol, "title

Visual Basic

vbcritical

16

32

vbquestion

vbexclamation

48

vbinformation

64

: )( Commands

Vbokonly
Vbokcancel
vbAbortRetryIgnor
vbYesNoCancel
vbYesNo
vbRetryCancel

0
1
2
3
4
5

Commands
Ok
Ok, Cancel
Abort, Retry, Ignore
Yes, No, Cancel
Yes, No
Retry, Cancel
:

MsgBox "please close your program", 16, "Error"


or
MsgBox "please close your program", vbcritical, "Error"

Visual Basic

Input Box
Message Box
ok . :
)"X = Inputbox ("prompt","title
:
:Prompt .
:Title ) (caption .


X .
: x .inputbox
: form
.
)(Private Sub Form_Load
)"X=Inputbox("enter value of x", "calculation
End Sub
calculation enter value of x
x .

Visual Basic

.
.
.
. ):(Variables

As Dim
:
:Integer .
:Long ) (.
:Single ) (.

:Double ) (.
:String .
:Boolean ).(true or false
:Date

:Time .
. Constant


:
= Const
=. : :
Const = .

.
:
.
.

.
.

Visual Basic

):(assignment statement
:
Variable name = expression

:
.
)(Operation Code
^

) (Operation

*/
Mod

+-

) (

&
>< = < <= > >=
AND , OR

) (


)3*(x+4*y

)3(x+4y

X^2 + 4 / 2

X2 + 4 2

16^ (1 / 4) + 3^3 + 10 (5 * 4) / 3^ 2 2^3

16 + 33 + 10 5 4 3 2 2 3

(5*y)/(x^2-4)+x-1

5y
+ x 1
x 4
2

:
:
) ( : Val .
) ( :Cstr .
) ( :CInt .

Visual Basic

.
( :Input
:
textbox .
inputbox .
( :output :
textbox .
label .
message box .
. print

: form )(

.
: :
form

caption

Command1
caption
+
Command2
Caption
Label1
Caption

Label2
Caption

text1, text2 text


Dim x, y, z as integer
)( Private sub command1_click
)X=val(text1.text
)Y=val(text2.text
Z=x + y
)="&z "(Msgbox
End sub
)( Private sub command2_click
)X=val(text1.text
)Y=val(text2.text
Z=x - y
)="&z "(Msgbox
End sub

Visual Basic

.)(string
,"2007" ,"100$" ,"name" :
" " )" "(
:

As String Dim

: ) ( Len Length
.
: .
.:
Form1
Caption
String length
Command1
caption
Click here
Label1
Caption
=Length
Text1
Text
.
Dim s As String
)(Private Sub Command1_Click
)"s = InputBox("inter string
)L = Len(s
)Text1.Text = CStr(L
End Sub
End sub


.

)abs(x

)sqr(x

) sin,cos,tan x(

)sin(x), cos(x) tan(x

Visual Basic

:
.print
.:
text1, text2, text3 command1
caption .run print
.

.:
Dim a, b, c, av As single
)( Private sub command1_click
)a=val (text1.text
)b=val(text2.text
)c =val(text3.text
av=(a+b+c) / 3
Print "av=";av
End sub

)(
/ .
/ input box
.label1, label2
/ .
/ : run :

Visual Basic

. ):(conditional statements

- )(if statement

- )(select case

- ):(if statement
if <, >, <=, >=, < >, =, and, or
if.
( If ..Then
:
If condition then statement
: pass
:
:

:
Dim x as integer
)(Private sub command1_click
)X= cint(text1.text
"If x>= 50 then text2.text= "pass
End sub
( If block
:
If condition then
Statements
End if

Visual Basic

pass :

:
Dim x as integer
Private sub command1_click()
X= cint(text1.text)
If x>= 50 then
text2.text= "pass"
text2.fontsize=18
end if
End sub
If.. Then.. Else (
:
If condition then
Statements
Else
Statements
End if
:
.
:
Dim x As Integer
Private Sub command1_click()
x = CInt(Text1.Text)
If x >= 50 Then
Text2.Text = "pass"
Else
Text2.Text = "fail"
End If
End Sub
If.. then.. Elseif ..Else (
:
If condition then
Statements
Elseif condition then

Visual Basic

Statements
Else
Statements
End if
:
.
:
Dim x As String
Private Sub command1_click()
x = text1.Text
If x = "Muhammad" Then
MsgBox "hello, Muhammad"
ElseIf x = "hasan" Then
MsgBox "hello,hasan"
Else
MsgBox "hello, guest"
End If
End Sub

(nested if) If If condition then


If condition then
Statements
Else
Statements
Elseif
Else
Statements
End if
(option button) :
.( illegal division operation)
:
Dim a, b, c As Single
Private Sub command1_click()
a = Val(Text1(0).Text)
b = Val(Text2.Text)
If Option1.Value Then
c=a*b
Text3.Text = CStr(c)
Else

Visual Basic

If b <> 0 Then
Text3.Text = CStr(c)
Else
Text3.Text = "illegal division operation"
End If
End If
End Sub

Select Statement -

:

Select case variables


Case value1
Statements
Case value2
Statements
.
.
.
Case else
Statements
End select
form :
:
Dim x As Integer
Private Sub Command1_Click()
x = CInt(Text1.Text)
Select Case x
Case 1
MsgBox ("Sunday")
Case 2
MsgBox ("Monday")
Case 3
MsgBox ("Tuesday")

Visual Basic
Case 4
)"MsgBox ("Thursday
Case 5
)"MsgBox ("Wednesday
Case 6
)"MsgBox ("Friday
Case 7
)"MsgBox ("Saturday
End Select
End Sub

. loop statement

visual basic

- : -
- counter loop
:fornext
:

For variable = start value to end value step step value


Statements
Next variable
: hello
Dim i as integer
)( Private Sub Command1_Click
For i = 1 To 5
"Print "hello
Next i
End Sub
- Conditional Loop

.Do while
:Do
Do until - Do while - :Do
:Do while Loop - Do while

.

Visual Basic

:
Do while condition
Statements
Loop
: hello do while
Dim i as integer
)( Private Sub Command1_Click
i=1
Do while i <= 5
Print "hello"; i
i=i+1
Loop
End Sub
:Do until Loop - Do until
:
:

: hello

Do until condition
Statements
Loop

Dim i as integer
)( Private Sub Command1_Click
i=1
Do
Print "hello"; i
i=i+1
Loop until i > 5
End Sub
:
Exit:
:For next - .Exit for

:Do while - .Exit Do

Visual Basic

.
.
: x s=1+x+x2+x3++xn
:
Dim I, n, sum as integer
Dim x,s as Double
)( Private Sub command1_click
sum = 1
)n=cint(text1.text
)x=val(text2.text
For i = 1 To n
Sum = sum +x^i
Next i
)Text3.text=cstr(sum
End Sub

:nested for
.

For i = 1 To n
For j = 1 To m
Statements
Next j
Next i
:
Dim I, j As Integer
)(Private Sub command1_click
For I = 1 To 10
For j = 1 To 10
p=I*j
Print I; "*"; j; "="; p,
Next j
Print
Next I
End Sub

Visual Basic

/ x y

Y=x x

y=-x x
/ label

/ check box
option button .

/
) (
/
9-10
A
7-8
B
5-6
C
0-4
D

You might also like