4.
2 Suffixes for Literals
Literals are values that you assign to a data. In some cases, we need to
add a suffix behind a literal so that VB can handle the calculation more
accurately. For example, we can use num=1.3089# for a Double type
data. Some of the suffixes are displayed in the Table below.
4.3 Constants:
Constant also store values, but as the name implies, those values remains
constant throughout the execution of an application. Using constants can
make your code more readable by providing meaningful names instead of
numbers. There are a number of built –in constants in Visual Basic. There
are two sources for constants:
System-defined constants are provided by applications and controls.
Visual Basic constants are listed in the Visual Basic (VB).
User-defined constants are declared using the Const statement. It is
a space in memory filled with fixed value that will not be changed.
For example:
Visual Basic page 1
4.2 Suffixes for Literals
ﻻﺣﻘﺎﺕ ﻟﻠﺤﺮﻑ4.2
Literals are values that you assign to a data. In some cases, we need to
ﻧﺤﺘﺎﺝ ﺇﻟﻰ ﺫﻟﻚ، ﻓﻲ ﺑﻌﺾ ﺍﻟﺤﺎﻻﺕ.ﺍﻟﻘﻴﻢ ﺍﻟﺤﺮﻓﻴﺔ ﻫﻲ ﺍﻟﻘﻴﻢ ﺍﻟﺘﻲ ﺗﻘﻮﻡ ﺑﺘﻌﻴﻴﻨﻬﺎ ﻟﺒﻴﺎﻧﺎﺕ
add a suffix behind a literal so that VB can handle the calculation more
ﺍﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﻟﺤﺴﺎﺏ ﺃﻛﺜﺮVB ﺇﺿﺎﻓﺔ ﻻﺣﻘﺔ ﺧﻠﻒ ﺣﺮﻓﻲ ﺑﺤﻴﺚ ﻳﻤﻜﻦ ﻟـ
accurately. For example, we can use num=1.3089# for a Double type
ﻟﻨﻮﻉ ﻣﺰﺩﻭﺝ# num = 1.3089 ﻳﻤﻜﻨﻨﺎ ﺍﺳﺘﺨﺪﺍﻡ، ﻋﻠﻰ ﺳﺒﻴﻞ ﺍﻟﻤﺜﺎﻝ.ﺑﺪﻗﺔ
data. Some of the suffixes are displayed in the Table below.
. ﻳﺘﻢ ﻋﺮﺽ ﺑﻌﺾ ﺍﻟﻠﻮﺍﺣﻖ ﻓﻲ ﺍﻟﺠﺪﻭﻝ ﺃﺩﻧﺎﻩ.ﺑﻴﺎﻧﺎﺕ
4.3 Constants:
: ﺍﻟﺜﻮﺍﺑﺖ4.3
Constant also store values, but as the name implies, those values remains
ﺗﻈﻞ ﻫﺬﻩ ﺍﻟﻘﻴﻢ، ﻭﻟﻜﻦ ﻛﻤﺎ ﻳﻮﺣﻲ ﺍﻻﺳﻢ، ﺗﻘﻮﻡ ﺃﻳﻀﺎ ﺑﺘﺨﺰﻳﻦ ﺍﻟﻘﻴﻢ ﺍﻟﺜﺎﺑﺘﺔ
constant throughout the execution of an application. Using constants can
ﻳﻤﻜﻦ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﻟﺜﻮﺍﺑﺖ.ﺛﺎﺑﺖ ﻃﻮﺍﻝ ﺗﻨﻔﻴﺬ ﺍﻟﻄﻠﺐ
make your code more readable by providing meaningful names instead of
ﺍﺟﻌﻞ ﺷﻔﺮﺗﻚ ﺃﻛﺜﺮ ﻗﺎﺑﻠﻴﺔ ﻟﻠﻘﺮﺍﺀﺓ ﻣﻦ ﺧﻼﻝ ﺗﻮﻓﻴﺮ ﺃﺳﻤﺎﺀ ﺫﺍﺕ ﻣﻌﻨﻰ ﺑﺪﻻ ﻣﻦ
numbers. There are a number of built –in constants in Visual Basic. There
ﻫﻨﺎﻙ.Visual Basic ﻳﻮﺟﺪ ﻋﺪﺩ ﻣﻦ ﺍﻟﺜﻮﺍﺑﺖ ﺍﻟﻤﻀﻤﻨﺔ ﻓﻲ.ﺃﻋﺪﺍﺩ
are two sources for constants:
:ﻣﺼﺪﺭﺍﻥ ﻟﻠﺜﻮﺍﺑﺖ
System-defined constants are provided by applications and controls.
ﻳﺘﻢ ﺗﻮﻓﻴﺮ ﺍﻟﺜﻮﺍﺑﺖ ﺍﻟﺘﻲ ﻳﺤﺪﺩﻫﺎ ﺍﻟﻨﻈﺎﻡ ﺑﻮﺍﺳﻄﺔ ﺍﻟﺘﻄﺒﻴﻘﺎﺕ ﻭﺍﻟﻀﻮﺍﺑﻂ.
Visual Basic constants are listed in the Visual Basic (VB).
.(Visual Basic (VB ﻓﻲVisual Basic ﻳﺘﻢ ﺳﺮﺩ ﺛﻮﺍﺑﺖ
User-defined constants are declared using the Const statement. It is
ﻳﺘﻢ ﺍﻟﺘﺼﺮﻳﺢ ﻋﻦ ﺍﻟﺜﻮﺍﺑﺖ ﺍﻟﻤﻌﺮﻓﺔ ﻣﻦ ﻗﺒﻞ ﺍﻟﻤﺴﺘﺨﺪﻡ ﺑﺎﺳﺘﺨﺪﺍﻡ ﻋﺒﺎﺭﺓConst. ﺃﻧﻪ
a space in memory filled with fixed value that will not be changed.
.ﻣﺴﺎﺣﺔ ﻓﻲ ﺍﻟﺬﺍﻛﺮﺓ ﻣﻠﻴﺌﺔ ﺑﻘﻴﻤﺔ ﺛﺎﺑﺘﺔ ﻟﻦ ﺗﺘﻐﻴﺮ
For example:
:ﻋﻠﻰ ﺳﺒﻴﻞ ﺍﻟﻤﺜﺎﻝ
Visual Basic page 1
Visual Basic 1 ﺻﻔﺤﺔ
Const X=3.14156 Constant for procedure
Private Const X=3.14156 Constant for form and all procedure
Public Const X=3.14156 Constant for all forms
4.4 Outputting Variable:
The Print method is used to display data on the screen. The statement
Print expression (example: Print X) displays the value of the expression at
the current position of the cursor in the form Object. The statement
Picture.Print expression displays the value of the expression at the
current position of the cursor in the PictureBox object. Several expressions
may be placed in the same Print method if separated by semicolons (to
display them adjacent to one another) or by commas (to display them in
successive zones).
Examples :
Print x , y or Picture1.Print x , y
Print “ x & y =” ; x ; y or Picture1. Print “ x & y =” ; x ; y
Examples (by use Visual Basic Operators):
Private Sub Command1_ click ( )
Picture1.Print 7\3
Picture1.Print 7 Mod 3
Picture1.Print "My"&" Name"
Picture1.Print 10/3*15/3*3/2-9/3/2*4*3
Picture1.Print 4E3-3E2/5/3E1
Picture1.Print 4E-8/2*5E8/6E16*4E14*3
Picture1.Print 4/3^3/4^2*3^4*2^4
Visual Basic page 2
Const X=3.14156 Constant for procedure
Const X = 3.14156 ﺛﺎﺑﺖ ﻟﻺﺟﺮﺍﺀ
Private Const X=3.14156 Constant for form and all procedure
ﺛﺎﺑﺖ ﻟﻠﺸﻜﻞ ﻭﺟﻤﻴﻊ ﺍﻹﺟﺮﺍﺀﺍﺕX = 3.14156 ﺛﺎﺑﺖ ﺍﻟﺨﺎﺹ
Public Const X=3.14156 Constant for all forms
ﺛﺎﺑﺖ ﻟﺠﻤﻴﻊ ﺍﻷﺷﻜﺎﻝX = 3.14156 ﺛﺎﺑﺖ ﻋﺎﻡ
4.4 Outputting Variable:
: ﻣﺘﻐﻴﺮ ﺍﻹﺧﺮﺍﺝ4.4
The Print method is used to display data on the screen. The statement
ﺍﻟﺒﻴﺎﻥ.ﺗﺴﺘﺨﺪﻡ ﻃﺮﻳﻘﺔ ﺍﻟﻄﺒﺎﻋﺔ ﻟﻌﺮﺽ ﺍﻟﺒﻴﺎﻧﺎﺕ ﻋﻠﻰ ﺍﻟﺸﺎﺷﺔ
Print expression (example: Print X) displays the value of the expression at
( ﻗﻴﻤﺔ ﺍﻟﺘﻌﺒﻴﺮ ﻋﻨﺪPrint X :ﻳﻌﺮﺽ ﺗﻌﺒﻴﺮ ﺍﻟﻄﺒﺎﻋﺔ )ﻣﺜﺎﻝ
the current position of the cursor in the form Object. The statement
ﺍﻟﺒﻴﺎﻥ.ﺍﻟﻤﻮﺿﻊ ﺍﻟﺤﺎﻟﻲ ﻟﻠﻤﺆﺷﺮ ﻓﻲ ﺷﻜﻞ ﻛﺎﺋﻦ
Picture.Print expression displays the value of the expression at the
ﻗﻴﻤﺔ ﺍﻟﺘﻌﺒﻴﺮ ﻓﻲ ﻣﻠﻒPicture.Print ﻳﻌﺮﺽ ﺗﻌﺒﻴﺮ
current position of the cursor in the PictureBox object. Several expressions
ﻋﺪﺓ ﺗﻌﺒﻴﺮﺍﺕ.PictureBox ﺍﻟﻤﻮﺿﻊ ﺍﻟﺤﺎﻟﻲ ﻟﻠﻤﺆﺷﺮ ﻓﻲ ﻛﺎﺋﻦ
may be placed in the same Print method if separated by semicolons (to
ﻳﻤﻜﻦ ﻭﺿﻌﻬﺎ ﻓﻲ ﻧﻔﺲ ﻃﺮﻳﻘﺔ ﺍﻟﻄﺒﺎﻋﺔ ﺇﺫﺍ ﺗﻢ ﺍﻟﻔﺼﻞ ﺑﻴﻨﻬﺎ ﺑﻔﻮﺍﺻﻞ ﻣﻨﻘﻮﻃﺔ )ﺇﻟﻰ
display them adjacent to one another) or by commas (to display them in
ﻋﺮﺿﻬﺎ ﺑﺠﻮﺍﺭ ﺑﻌﻀﻬﺎ ﺍﻟﺒﻌﺾ( ﺃﻭ ﺑﺎﻟﻔﻮﺍﺻﻞ )ﻟﻌﺮﺿﻬﺎ ﺑﺘﻨﺴﻴﻖ
successive zones).
.(ﻣﻨﺎﻃﻖ ﻣﺘﺘﺎﻟﻴﺔ
Examples :
: ﺃﻣﺜﻠﺔ
Print x , y or Picture1.Print x , y
Picture1.Print x، y ﺃﻭy ﺃﻭx ﻃﺒﺎﻋﺔ
Print “ x & y =” ; x ; y or Picture1. Print “ x & y =” ; x ; y
=" ؛ ﺍﻟﻌﺎﺷﺮ ؛ ﺫx & y" ﻃﺒﺎﻋﺔ.Picture1 ﺃﻭy =" ؛ ﺍﻟﻌﺎﺷﺮ ؛x & y" ﻃﺒﺎﻋﺔ
Examples (by use Visual Basic Operators):
:(Visual Basic ﺃﻣﺜﻠﺔ )ﺑﺎﺳﺘﺨﺪﺍﻡ ﻋﻮﺍﻣﻞ ﺗﺸﻐﻴﻞ
Private Sub Command1_ click ( )
() _ ﺍﻧﻘﺮ1 ﺍﻷﻣﺮ ﺍﻟﻔﺮﻋﻲ ﺍﻟﺨﺎﺹ
Picture1.Print 7\3
3 \ 7 ﻃﺒﺎﻋﺔ-1 ﺍﻟﺼﻮﺭﺓ
Picture1.Print 7 Mod 3
Picture1.Print 7 Mod 3
Picture1.Print "My"&" Name"
Picture1.Print "My" & "Name"
Picture1.Print 10/3*15/3*3/2-9/3/2*4*3
3 * 4 * 3/2 / 9-2 / 3 * 15/3 * 10/3 ﻃﺒﺎﻋﺔ-1 ﺻﻮﺭﺓ
Picture1.Print 4E3-3E2/5/3E1
4E3-3E2 / 5 / 3E1 ﺍﻃﺒﻊ-1
Picture1.Print 4E-8/2*5E8/6E16*4E14*3
Print 4E-8/2 * 5E8 / 6E16 * 4E14 * 3.1 ﺻﻮﺭﺓ
Picture1.Print 4/3^3/4^2*3^4*2^4
4 ^ 2 * 4 ^ 3 * 2 ^ 3/4 ^ 4/3 ﺍﻃﺒﻊ-1 ﺻﻮﺭﺓ
Visual Basic page 2
Visual Basic 2 ﺻﻔﺤﺔ
Picture1.Print 27^1/3-2E2^3*4E-4/4^3
Picture1.Print (3-3^3)/((3^2+3^3)/3^5)/3^4
Picture1.Print (14+2^5/2^4)^(1/4)+((15-5*4)/(3^2-2^3/2))
Picture1.Print (((3^(3^3)/3^3)^(1/3)+3^4)^(1/3)* 5^2)^(1/2)
4.5 Visual Basic Functions:
Visual Basic offers a rich assortment of built-in functions. The numeric and
string variables are the most common used variables in programming.
Therefore Visual Basic provides the user with many functions to be used
with a variable to perform certain operations or type conversion. Detailed
description of the function in general will be discussed in the following
functions section. The most common functions for (numeric or string)
variable X are stated in the following table.
Visual Basic page 3
Picture1.Print 27^1/3-2E2^3*4E-4/4^3
2E2 ^ 3 * 4E-4/4 ^ 3-3 / 1 ^ 27 ﺍﻃﺒﻊ.1 ﺻﻮﺭﺓ
Picture1.Print (3-3^3)/((3^2+3^3)/3^5)/3^4
Picture1.Print (3-3 ^ 3) / ((3 ^ 2 + 3 ^ 3) / 3 ^ 5) / 3 ^ 4
Picture1.Print (14+2^5/2^4)^(1/4)+((15-5*4)/(3^2-2^3/2))
Picture1.Print (14 + 2 ^ 5/2 ^ 4) ^ (1/4) + ((15-5 * 4) / (3 ^ 2-2 ^ 3/2))
Picture1.Print (((3^(3^3)/3^3)^(1/3)+3^4)^(1/3)* 5^2)^(1/2)
Picture1.Print (((3 ^ (3 ^ 3) / 3 ^ 3) ^ (1/3) + 3 ^ 4) ^ (1/3) * 5 ^ 2) ^ (1/2)
4.5 Visual Basic Functions:
:Visual Basic ﻭﻇﺎﺋﻒ4.5
Visual Basic offers a rich assortment of built-in functions. The numeric and
ﺍﻟﻌﺪﺩﻳﺔ ﻭ. ﻣﺠﻤﻮﻋﺔ ﻣﺘﻨﻮﻋﺔ ﻏﻨﻴﺔ ﻣﻦ ﺍﻟﻮﻇﺎﺋﻒ ﺍﻟﻤﻀﻤﻨﺔVisual Basic ﻳﻘﺪﻡ
string variables are the most common used variables in programming.
.ﻣﺘﻐﻴﺮﺍﺕ ﺍﻟﺴﻠﺴﻠﺔ ﻫﻲ ﺍﻟﻤﺘﻐﻴﺮﺍﺕ ﺍﻷﻛﺜﺮ ﺍﺳﺘﺨﺪﺍﻣﺎ ﻓﻲ ﺍﻟﺒﺮﻣﺠﺔ
Therefore Visual Basic provides the user with many functions to be used
ﻟﻠﻤﺴﺘﺨﺪﻡ ﺍﻟﻌﺪﻳﺪ ﻣﻦ ﺍﻟﻮﻇﺎﺋﻒ ﻻﺳﺘﺨﺪﺍﻣﻬﺎVisual Basic ﻟﺬﻟﻚ ﻳﻮﻓﺮ
with a variable to perform certain operations or type conversion. Detailed
ﻣﻔﺼﻠﺔ.ﻣﻊ ﻣﺘﻐﻴﺮ ﻹﺟﺮﺍﺀ ﻋﻤﻠﻴﺎﺕ ﻣﻌﻴﻨﺔ ﺃﻭ ﻧﻮﻉ ﺍﻟﺘﺤﻮﻳﻞ
description of the function in general will be discussed in the following
ﺳﻴﺘﻢ ﻣﻨﺎﻗﺸﺔ ﻭﺻﻒ ﺍﻟﻮﻇﻴﻔﺔ ﺑﺸﻜﻞ ﻋﺎﻡ ﻓﻲ ﻣﺎ ﻳﻠﻲ
functions section. The most common functions for (numeric or string)
( ﺍﻟﻮﻇﺎﺋﻒ ﺍﻷﻛﺜﺮ ﺷﻴﻮﻋﺎ ﻟـ )ﺭﻗﻤﻲ ﺃﻭ ﺳﻠﺴﻠﺔ.ﻗﺴﻢ ﺍﻟﻮﻇﺎﺋﻒ
variable X are stated in the following table.
. ﻣﺬﻛﻮﺭ ﻓﻲ ﺍﻟﺠﺪﻭﻝ ﺍﻟﺘﺎﻟﻲX ﻣﺘﻐﻴﺮ
Visual Basic page 3
Visual Basic 3 ﺻﻔﺤﺔ
4.6 Converting Data Types:
Visual Basic provides several conversion functions can used to convert
values into a specific data type. The following table describes the convert
function.
Visual Basic page 4
4.6 Converting Data Types:
: ﺗﺤﻮﻳﻞ ﺃﻧﻮﺍﻉ ﺍﻟﺒﻴﺎﻧﺎﺕ4.6
Visual Basic provides several conversion functions can used to convert
ﺍﻟﻌﺪﻳﺪ ﻣﻦ ﻭﻇﺎﺋﻒ ﺍﻟﺘﺤﻮﻳﻞ ﺍﻟﺘﻲ ﻳﻤﻜﻦ ﺍﺳﺘﺨﺪﺍﻣﻬﺎ ﻟﻠﺘﺤﻮﻳﻞVisual Basic ﻳﻮﻓﺮ
values into a specific data type. The following table describes the convert
ﻳﺼﻒ ﺍﻟﺠﺪﻭﻝ ﺍﻟﺘﺎﻟﻲ ﺍﻟﺘﺤﻮﻳﻞ.ﺍﻟﻘﻴﻢ ﻓﻲ ﻧﻮﻉ ﺑﻴﺎﻧﺎﺕ ﻣﺤﺪﺩ
function.
.ﻭﻇﻴﻔﺔ
Visual Basic page 4
Visual Basic 4 ﺻﻔﺤﺔ
Examples (1):
A=Lcase ("My Name Is") → A= my name is
A=Ucase ("My Name Is") → A=MY NAME IS
A=" My Name Is": B=Left (A,7) → B=My Name
C=Right(A,7) : → C=Name Is
D= Mid (A,3,5) → D=Name
E=Mid(A,3) → E=Name Is
Examples (2):
Print INT(4.1)
Print INT(-4.1)
Print INT(-4.8)
Print INT(2.34567*100+0.5)/100
A=3.14159/180: Print SIN (45*A)/COS(60*A)^2/COS(45*A)/SIN(30*A)^3
Print INT (-4E-6/2)*INT(5E8/6E15*1.2E10) Print SGN
(INT(4/3^8/4^3*3^5*2^5)) Print EXP (LOG(27^1/3+2E2^3*4E-4/4^2))
Print FIX (4.1)
Print FIX(-4.8)
Print FIX (2.34567*100+0.5) / 100
Visual Basic page 5
Examples (1):
:(1) ﺃﻣﺜﻠﺔ
A=Lcase ("My Name Is") → A= my name is
A = Lcase ("My Name Is") → A = ﺍﺳﻤﻲ
A=Ucase ("My Name Is") → A=MY NAME IS
A = Ucase ("My Name Is") → A = MY NAME IS
A=" My Name Is": B=Left (A,7) → B=My Name
( ← ﺏ = ﺍﺳﻤﻲ7 ، ﺏ = ﻳﺴﺎﺭ )ﺃ:"ﺃ = "ﺍﺳﻤﻲ ﻫﻮ
C=Right(A,7) : → C=Name Is
C = 7 ، )ﻳﻤﻴﻦ )ﺃ: → C = ﺍﻻﺳﻢ ﻫﻮ
D= Mid (A,3,5) → D=Name
D = ( → ﺩ = ﺍﻻﺳﻢ3،5 ، ﻣﻨﺘﺼﻒ )ﺃ
E=Mid(A,3) → E=Name Is
E = ( → ﻩ = ﺍﻻﺳﻢ ﻫﻮ3 ، ﻣﻨﺘﺼﻒ )ﺃ
Examples (2):
:(2) ﺃﻣﺜﻠﺔ
Print INT(4.1)
(4.1) ﺑﺮﻳﻨﺖ ﺇﻧﺖ
Print INT(-4.1)
(INT (-4.1 ﻃﺒﺎﻋﺔ
Print INT(-4.8)
(INT (-4.8 ﻃﺒﺎﻋﺔ
Print INT(2.34567*100+0.5)/100
INT (2.34567 * 100 + 0.5) / 100 ﻃﺒﺎﻋﺔ
A=3.14159/180: Print SIN (45*A)/COS(60*A)^2/COS(45*A)/SIN(30*A)^3
A = 3.14159 / 180: ﻃﺒﺎﻋﺔSIN (45 * A) / COS (60 * A) ^ 2 / COS (45 * A) / SIN (30 * A) ^ 3
Print INT (-4E-6/2)*INT(5E8/6E15*1.2E10) Print SGN
Print INT (-4E-6/2) * INT (5E8 / 6E15 * 1.2E10) ﻃﺒﺎﻋﺔSGN
(INT(4/3^8/4^3*3^5*2^5)) Print EXP (LOG(27^1/3+2E2^3*4E-4/4^2))
((EXP (LOG (27 ^ 1/3 + 2E2 ^ 3 * 4E-4/4 ^ 2 (( ﻃﺒﺎﻋﺔ5 ^ 2 * 5 ^ 3 * 3 ^ 8/4 ^ 4/3) )ﺩﺍﺧﻠﻲ
Print FIX (4.1)
(4.1) ﻃﺒﺎﻋﺔ ﻓﻴﻜﺲ
Print FIX(-4.8)
(FIX (-4.8 ﻃﺒﺎﻋﺔ
Print FIX (2.34567*100+0.5) / 100
FIX (2.34567 * 100 + 0.5) / 100 ﻃﺒﺎﻋﺔ
Visual Basic page 5
Visual Basic 5 ﺻﻔﺤﺔ
Example (3): Convert the following arithmetic formula to visual Basic
language.
Example (4):
Create a Visual Basic project to solve for the roots of the quadratic
√
equation 𝒂𝑿𝟐+ 𝒃X +c = , using quadratic formula as:𝑋1 ,2 =−𝒃± .
Design the program so that the values of a, b, and c are entered into
separate (labeled) text boxes and display 𝑋1 𝑎nd 𝑋2 in separate (labeled)
text boxes?
Visual Basic page 6
Example (3): Convert the following arithmetic formula to visual Basic
Visual Basic ﻗﻢ ﺑﺘﺤﻮﻳﻞ ﺍﻟﺼﻴﻐﺔ ﺍﻟﺤﺴﺎﺑﻴﺔ ﺍﻟﺘﺎﻟﻴﺔ ﺇﻟﻰ:(3) ﻣﺜﺎﻝ
language.
.ﻟﻐﺔ
Example (4):
:(4) ﻣﺜﺎﻝ
Create a Visual Basic project to solve for the roots of the quadratic
ﻟﺤﻞ ﺟﺬﻭﺭ ﺍﻟﺘﺮﺑﻴﻌﻴﺔVisual Basic ﻗﻢ ﺑﺈﻧﺸﺎﺀ ﻣﺸﺮﻭﻉ
√
√
equation ᵈᵇᵽ+ ᵈX +c = , using quadratic formula as:ᵄ , =−ᵈ± .
.± ᵄ ، = −ᵈ : ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﻟﺼﻴﻐﺔ ﺍﻟﺘﺮﺑﻴﻌﻴﺔ ﻋﻠﻰ ﺍﻟﻨﺤﻮ ﺍﻟﺘﺎﻟﻲ، = ᵈᵇᵽ + ᵈX + c ﺍﻟﻤﻌﺎﺩﻟﺔ
12
ﺃ١
Design the program so that the values of a, b, and c are entered into
c ﻭb ﻭa ﺻﻤﻢ ﺍﻟﺒﺮﻧﺎﻣﺞ ﺑﺤﻴﺚ ﻳﺘﻢ ﺇﺩﺧﺎﻝ ﻗﻴﻢ
separate (labeled) text boxes and display ᵄ ᵄnd ᵄ in separate (labeled)
( ﻓﻲ ﻣﻨﻔﺼﻠﺔ )ﻣﻌﻨﻮﻧﺔᵄ ﻭ ﻭᵄ ﻣﺮﺑﻌﺎﺕ ﻧﺺ ﻣﻨﻔﺼﻠﺔ )ﻣﺴﻤﺎﺓ( ﻭﻋﺮﺽ
12
ﺃ١
text boxes?
ﻣﺮﺑﻌﺎﺕ ﺍﻟﻨﺺ؟
Visual Basic page 6
Visual Basic 6 ﺻﻔﺤﺔ
Solution:
1- Place six labels, five text boxes, and one command button on the form.
The form should
appear similar to this.
2- Set the form and object properties:
Visual Basic page 7
Solution:
:ﺍﻟﻤﺤﻠﻮﻝ
1- Place six labels, five text boxes, and one command button on the form.
. ﺿﻊ ﺳﺘﺔ ﻣﻠﺼﻘﺎﺕ ﻭﺧﻤﺴﺔ ﻣﺮﺑﻌﺎﺕ ﻧﺼﻴﺔ ﻭﺯﺭ ﺃﻣﺮ ﻭﺍﺣﺪ ﻋﻠﻰ ﺍﻟﻨﻤﻮﺫﺝ-1
The form should
ﻳﺠﺐ ﺃﻥ ﻳﻜﻮﻥ ﺍﻟﻨﻤﻮﺫﺝ
appear similar to this.
.ﺗﺒﺪﻭ ﻣﺸﺎﺑﻬﺔ ﻟﻬﺬﺍ
2- Set the form and object properties:
: ﻗﻢ ﺑﺘﻌﻴﻴﻦ ﺧﺼﺎﺋﺺ ﺍﻟﺸﻜﻞ ﻭﺍﻟﻌﻨﺼﺮ-2
Visual Basic page 7
Visual Basic 7 ﺻﻔﺤﺔ
3- Attach this code to the command1 button (Answer)
Private Sub Cmd1_ click ( )
Dim a , b , c , X1 , X2
a= Val (Txt1.text)
b= Val (Txt2.text)
c= Val (Txt3.text)
X1=Cdbl (- b + Sqr (b ^ 2 – 4 * a * c) ) / (2 * a)
X2= Cdbl (- b – Sqr (b ^ 2 – 4 * a * c) ) / ( 2 * a)
Txt4.text = CStr (X1)
Txt5.text = CStr (X2)
End Sub
4- Running the Application: press F5 or icon
4.7 InputBox Function:
InputBox function is used to input a value or character for one variable
from keyboard at running stage.
Variable-Name=InputBox (“Message”,”Title”)
For Example
X=InputBox(“Enter Value of X”,”Example 3”)
Note: The type value for InputBox function is string value
Box title
Visual Basic page 8
3- Attach this code to the command1 button (Answer)
( )ﺇﺟﺎﺑﺔcommand1 ﺇﺭﻓﺎﻕ ﻫﺬﺍ ﺍﻟﻜﻮﺩ ﺑﺰﺭ-3
Private Sub Cmd1_ click ( )
Sub Cmd1_ click ()
Dim a , b , c , X1 , X2
X1 ، X2 ، ﺝ، ﺏ، ﺧﺎﻓﺖ ﺃ
a= Val (Txt1.text)
(Txt1.text) ﺃ = ﻓﺎﻝ
b= Val (Txt2.text)
(Txt2.text) ﺏ = ﻓﺎﻝ
c= Val (Txt3.text)
(Txt3.text) ﺝ = ﻓﺎﻝ
X1=Cdbl (- b + Sqr (b ^ 2 – 4 * a * c) ) / (2 * a)
X1 = Cdbl (- b + Sqr (b ^ 2-4 * a * c)) / (2 * a)
X2= Cdbl (- b – Sqr (b ^ 2 – 4 * a * c) ) / ( 2 * a)
X2 = Cdbl (- b - Sqr (b ^ 2-4 * a * c)) / (2 * a)
Txt4.text = CStr (X1)
Txt4.text = CStr (X1)
Txt5.text = CStr (X2)
Txt5.text = CStr (X2)
End Sub
End Sub
4- Running the Application: press F5 or icon
ﺃﻭ ﺃﻳﻘﻮﻧﺔF5 ﺍﺿﻐﻂ: ﺗﺸﻐﻴﻞ ﺍﻟﺘﻄﺒﻴﻖ-4
4.7 InputBox Function:
:InputBox ﻭﻇﻴﻔﺔ4.7
InputBox function is used to input a value or character for one variable
ﻹﺩﺧﺎﻝ ﻗﻴﻤﺔ ﺃﻭ ﺣﺮﻑ ﻟﻤﺘﻐﻴﺮ ﻭﺍﺣﺪInputBox ﺗﺴﺘﺨﺪﻡ ﻭﻇﻴﻔﺔ
from keyboard at running stage.
.ﻣﻦ ﻟﻮﺣﺔ ﺍﻟﻤﻔﺎﺗﻴﺢ ﻓﻲ ﻣﺮﺣﻠﺔ ﺍﻟﺠﺮﻱ
Variable-Name=InputBox (“Message”,”Title”)
(" "ﺍﻟﻌﻨﻮﺍﻥ، " )"ﺍﻟﺮﺳﺎﻟﺔInputBox = ﺍﺳﻢ ﺍﻟﻤﺘﻐﻴﺮ
For Example
ﻋﻠﻰ ﺳﺒﻴﻞ ﺍﻟﻤﺜﺎﻝ
X=InputBox(“Enter Value of X”,”Example 3”)
X = InputBox (" ﺃﺩﺧﻞ ﻗﻴﻤﺔX" ، "3 )"ﻣﺜﺎﻝ
Note: The type value for InputBox function is string value
ﻫﻲ ﻗﻴﻤﺔ ﺳﻠﺴﻠﺔInputBox ﻗﻴﻤﺔ ﺍﻟﻨﻮﻉ ﻟﻮﻇﻴﻔﺔ:ﻣﻼﺣﻈﺔ
Box title
ﻋﻨﻮﺍﻥ ﺍﻟﺼﻨﺪﻭﻕ
Visual Basic page 8
Visual Basic 8 ﺻﻔﺤﺔ
Example(5): Repeat Example(4). Using Input Box function to input value
of a, b, and c.
Exercise (1):
Create a Visual Basic project to find the Perimeter and area of any
triangular using the equation formula as shown below. Design the program
so that the values of a, b, and c are entered into separate (labeled) text
boxes and display perimeter and area in separate (labeled) text boxes?
NOT:
Perimeter=a +b +c S= (a +b +c)/2
Area=√ ( 𝒂) ( 𝒃) ( 𝒄)
Exercise (2):
To design a simply calculator, design a form with three text boxes and four
command buttons. The integer value of the first and second number is
entered into separate (labeled) text boxes. Write codes to perform add,
subtract, multiply, and divide where pressing on buttons. Display the result
operation in separate TextBox by using the following formula. 11+15=26
Visual Basic page 9
Example(5): Repeat Example(4). Using Input Box function to input value
ﻹﺩﺧﺎﻝ ﺍﻟﻘﻴﻤﺔInput Box ﺍﺳﺘﺨﺪﺍﻡ ﻭﻇﻴﻔﺔ.(4) ﺗﻜﺮﺍﺭ ﻣﺜﺎﻝ:(5) ﻣﺜﺎﻝ
of a, b, and c.
.c ﻭb ﻭa ﻣﻦ
Exercise (1):
:(1 ﺍﻟﺘﻤﺮﻳﻦ
Create a Visual Basic project to find the Perimeter and area of any
ﻟﻠﻌﺜﻮﺭ ﻋﻠﻰ ﻣﺤﻴﻂ ﻭﻣﺴﺎﺣﺔ ﺃﻱVisual Basic ﻗﻢ ﺑﺈﻧﺸﺎﺀ ﻣﺸﺮﻭﻉ
triangular using the equation formula as shown below. Design the program
ﺗﺼﻤﻴﻢ ﺍﻟﺒﺮﻧﺎﻣﺞ.ﻣﺜﻠﺚ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺻﻴﻐﺔ ﺍﻟﻤﻌﺎﺩﻟﺔ ﻛﻤﺎ ﻫﻮ ﻣﻮﺿﺢ ﺃﺩﻧﺎﻩ
so that the values of a, b, and c are entered into separate (labeled) text
( ﻓﻲ ﻧﺺ ﻣﻨﻔﺼﻞ )ﻣﺴﻤﻰc ﻭb ﻭa ﺑﺤﻴﺚ ﻳﺘﻢ ﺇﺩﺧﺎﻝ ﻗﻴﻢ
boxes and display perimeter and area in separate (labeled) text boxes?
ﻣﺮﺑﻌﺎﺕ ﻭﻋﺮﺽ ﻣﺤﻴﻂ ﻭﻣﺴﺎﺣﺔ ﻓﻲ ﻣﺮﺑﻌﺎﺕ ﻧﺺ ﻣﻨﻔﺼﻠﺔ )ﻣﻌﻨﻮﻧﺔ(؟
NOT:
:ﻟﻴﺲ
Perimeter=a +b +c S= (a +b +c)/2
2 / ( ﺝ+ ﺏ+ = )ﺃS ﺝ+ ﺏ+ ﺍﻟﻤﺤﻴﻂ = ﺃ
Area=√ ( ᵈ) ( ᵈ) ( ᵈ)
(ᵈ) (ᵈ) (ᵈ) √ = ﺍﻟﻤﻨﻄﻘﺔ
Exercise (2):
:(2 ﺗﻤﺮﻳﻦ
To design a simply calculator, design a form with three text boxes and four
ﻗﻢ ﺑﺘﺼﻤﻴﻢ ﻧﻤﻮﺫﺝ ﺑﺜﻼﺛﺔ ﻣﺮﺑﻌﺎﺕ ﻧﺼﻴﺔ ﻭﺃﺭﺑﻌﺔ، ﻟﺘﺼﻤﻴﻢ ﺁﻟﺔ ﺣﺎﺳﺒﺔ ﺑﺴﻴﻄﺔ
command buttons. The integer value of the first and second number is
ﻗﻴﻤﺔ ﺍﻟﻌﺪﺩ ﺍﻟﺼﺤﻴﺢ ﻟﻠﺮﻗﻢ ﺍﻷﻭﻝ ﻭﺍﻟﺜﺎﻧﻲ ﻫﻲ.ﺃﺯﺭﺍﺭ ﺍﻷﻭﺍﻣﺮ
entered into separate (labeled) text boxes. Write codes to perform add,
، ﺃﻛﺘﺐ ﺃﻛﻮﺍﺩ ﻷﺩﺍﺀ ﺍﻹﺿﺎﻓﺔ.(ﺗﻢ ﺇﺩﺧﺎﻟﻬﺎ ﻓﻲ ﻣﺮﺑﻌﺎﺕ ﻧﺼﻴﺔ ﻣﻨﻔﺼﻠﺔ )ﻣﺴﻤﺎﺓ
subtract, multiply, and divide where pressing on buttons. Display the result
ﺍﻋﺮﺽ ﺍﻟﻨﺘﻴﺠﺔ.ﻃﺮﺡ ﻭﺿﺮﺏ ﻭﻗﺴﻢ ﺣﻴﺚ ﻳﺘﻢ ﺍﻟﻀﻐﻂ ﻋﻠﻰ ﺍﻷﺯﺭﺍﺭ
operation in separate TextBox by using the following formula. 11+15=26
26 = 15 + 11 .ﻓﻲ ﻣﺮﺑﻊ ﻧﺺ ﻣﻨﻔﺼﻞ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﻟﺼﻴﻐﺔ ﺍﻟﺘﺎﻟﻴﺔ
Visual Basic page 9
Visual Basic 9 ﺻﻔﺤﺔ
Exercise (3):
Create a Visual Basic project to find the average value of three positive
and integer variables (X1, X2, and X3). Find the deviation {(average-X1),
(average-X2), and (average-X3)}. Print the value of average and deviation
in PictureBox.
Exercise (4):
Create a Visual Basic project to enter an angle value (Degree, Minutes, and
Seconds) into separate text boxes Design the program to find the value of
angle (in degree only) as the following equation. Display Angle in separate
text box.
Angle= Degree + (Minutes/60) + (Seconds/3600)
Exercise (5):
Create a Visual Basic project to enter an angle value (used InputBox
statement). Design the program to find the value of angle (in Degrees,
Minutes, and Seconds). Display Degree ,Minutes and Second in PictureBox.
Pointer the control objects are used on the form window.
Visual Basic page 10
Exercise (3):
:(3) ﺗﻤﺮﻳﻦ
Create a Visual Basic project to find the average value of three positive
ﻟﻠﻌﺜﻮﺭ ﻋﻠﻰ ﻣﺘﻮﺳﻂ ﻗﻴﻤﺔ ﺛﻼﺛﺔ ﻣﻮﺟﺒﺔVisual Basic ﻗﻢ ﺑﺈﻧﺸﺎﺀ ﻣﺸﺮﻭﻉ
and integer variables (X1, X2, and X3). Find the deviation {(average-X1),
،(average-X1)} ﺃﻭﺟﺪ ﺍﻻﻧﺤﺮﺍﻑ.(X3 ﻭX2 ﻭX1) ﻭﺍﻟﻤﺘﻐﻴﺮﺍﺕ ﺍﻟﺼﺤﻴﺤﺔ
(average-X2), and (average-X3)}. Print the value of average and deviation
ﺍﻃﺒﻊ ﻗﻴﻤﺔ ﺍﻟﻤﺘﻮﺳﻂ ﻭﺍﻻﻧﺤﺮﺍﻑ.{(X3 ( ﻭ )ﻣﺘﻮﺳﻂX2 )ﻣﺘﻮﺳﻂ
in PictureBox.
.PictureBox ﻓﻲ
Exercise (4):
:(4) ﺗﻤﺮﻳﻦ
Create a Visual Basic project to enter an angle value (Degree, Minutes, and
ﻹﺩﺧﺎﻝ ﻗﻴﻤﺔ ﺯﺍﻭﻳﺔ )ﺍﻟﺪﺭﺟﺔ ﻭﺍﻟﺪﻗﺎﺋﻖ ﻭVisual Basic ﻗﻢ ﺑﺈﻧﺸﺎﺀ ﻣﺸﺮﻭﻉ
Seconds) into separate text boxes Design the program to find the value of
ﺛﻮﺍﻧﻲ( ﻓﻲ ﻣﺮﺑﻌﺎﺕ ﻧﺼﻴﺔ ﻣﻨﻔﺼﻠﺔ ﺻﻤﻢ ﺍﻟﺒﺮﻧﺎﻣﺞ ﻟﻠﻌﺜﻮﺭ ﻋﻠﻰ ﻗﻴﻤﺔ
angle (in degree only) as the following equation. Display Angle in separate
ﺯﺍﻭﻳﺔ ﺍﻟﻌﺮﺽ ﻣﻨﻔﺼﻠﺔ.ﺍﻟﺰﺍﻭﻳﺔ )ﺑﺎﻟﺪﺭﺟﺔ ﻓﻘﻂ( ﻋﻠﻰ ﺃﻧﻬﺎ ﺍﻟﻤﻌﺎﺩﻟﺔ ﺍﻟﺘﺎﻟﻴﺔ
text box.
.ﻣﺮﺑﻊ ﺍﻟﻜﺘﺎﺑﺔ
Angle= Degree + (Minutes/60) + (Seconds/3600)
(3600 / )ﺛﺎﻧﻴﺔ+ (60 / )ﺩﻗﻴﻘﺔ+ ﺍﻟﺰﺍﻭﻳﺔ = ﺍﻟﺪﺭﺟﺔ
Exercise (5):
:(5) ﺗﻤﺮﻳﻦ
Create a Visual Basic project to enter an angle value (used InputBox
InputBox ﻹﺩﺧﺎﻝ ﻗﻴﻤﺔ ﺯﺍﻭﻳﺔ )ﺗﺴﺘﺨﺪﻡVisual Basic ﻗﻢ ﺑﺈﻧﺸﺎﺀ ﻣﺸﺮﻭﻉ
statement). Design the program to find the value of angle (in Degrees,
، ﺻﻤﻢ ﺍﻟﺒﺮﻧﺎﻣﺞ ﻹﻳﺠﺎﺩ ﻗﻴﻤﺔ ﺍﻟﺰﺍﻭﻳﺔ )ﺑﺎﻟﺪﺭﺟﺎﺕ.(ﺑﻴﺎﻥ
Minutes, and Seconds). Display Degree ,Minutes and Second in PictureBox.
.PictureBox ﻋﺮﺽ ﺍﻟﺪﺭﺟﺔ ﻭﺍﻟﺪﻗﺎﺋﻖ ﻭﺍﻟﺜﺎﻧﻴﺔ ﻓﻲ.(ﺩﻗﺎﺋﻖ ﻭﺛﻮﺍﻧﻲ
Pointer the control objects are used on the form window.
.ﺍﺳﺘﺨﺪﻡ ﻣﺆﺷﺮ ﻛﺎﺋﻨﺎﺕ ﺍﻟﺘﺤﻜﻢ ﻓﻲ ﻧﺎﻓﺬﺓ ﺍﻟﻨﻤﻮﺫﺝ
Visual Basic page 10
10 ﻓﻴﺠﻮﺍﻝ ﺑﻴﺴﻚ ﺻﻔﺤﺔ