vb data&programming
TRANSCRIPT
8/2/2019 VB Data&Programming
http://slidepdf.com/reader/full/vb-dataprogramming 1/25
البينت فى البسيك المرئى
8/2/2019 VB Data&Programming
http://slidepdf.com/reader/full/vb-dataprogramming 2/25
نت ي ب ل ا ع ا و ن أ د د ل ا هFor example, we need to handle data such as
names, addresses, money, date, integers, floats,
statistics and etc
Data types
Numeric Text
Floating points Integers Mony
SinglePrecision
DoublePrecision
Shortintegers
LongIntegers
VariableLengthstrings
FixedLengthstrings
Integers
8/2/2019 VB Data&Programming
http://slidepdf.com/reader/full/vb-dataprogramming 3/25
اع و ن أ وع ن ل ة م ي ق ل ا د زى خ ل ا ز ي ح ل ا الدة لبينت ا
8/2/2019 VB Data&Programming
http://slidepdf.com/reader/full/vb-dataprogramming 4/25
اوث ل زي ممل ا الت Laterals
بت ا ث ل ة ي ا ه ن ى ف ز م ر ة ف ا ضإ ي ة ب ا ة ق أ د خ س د ع ى. و م ل ذ ت ب ا ث ل ذ و ب ى ئ ل ك س ا ل خ ى ل
Suffix Data type
% Integer
& Long
! Single
# Double
@ Currency
Xvalue=344% : Yvalue=0.00567# : Zvalue=19999@
memberName="Turban, John."TelNumber="1800-900-888-777"
ب ضو ح ة ف و صم بت و ص عمى
8/2/2019 VB Data&Programming
http://slidepdf.com/reader/full/vb-dataprogramming 5/25
Variablesالمغيرات
ا ه ف ز خ ذ ل ى ف ا خ م ع ر ا ع .د ي ج م ا ن ل ذ ء ا أ ى ف غ ا ن ا ب
ي أ د ب س ذ م س ب غ ل : الة ل لشط
It must be less than 255 charactersNo spacing is allowedIt must not begin with a number
Period is not permittedReserved words like rem, val, .. is not allowed
VB is not a case sensitive language
8/2/2019 VB Data&Programming
http://slidepdf.com/reader/full/vb-dataprogramming 6/25
ا د خ س ا ب ر ي غ وع ى ئ ر م ل ا ك ي س ب ل ا ب إ د ر. ك ل ذ ج ن ر ب ل ا ى ف Dim: ى م
Dim password As String
Dim yourName As String
Dim firstnum As Integer
Dim secondnum As Integer
Dim total As Integer
Dim doDate As Date
فى غ ل و ن ع ع ي
لى ء ز ل فى ة مل ة ا General
8/2/2019 VB Data&Programming
http://slidepdf.com/reader/full/vb-dataprogramming 7/25
ات ري غ مل ا ل ا : ة ل ا ل ة ل ا ل ا غ م أ ى ف ة ق ض أ صخ ي
Variable=ExpressionThe expression could be a mathematical expression, a number,
a string, a boolean value(true or false) and etc. The following
are some examples:
firstNumber=100secondNumber=firstNumber-99
userName="John Lyan"
userpass.Text = password
Label1.Visible = True
Command1.Visible = false
Label4.Caption = textbox1.Text
ThirdNumber = Val(usernum1.Text)
total = firstNumber + secondNumber+ThirdNumber
8/2/2019 VB Data&Programming
http://slidepdf.com/reader/full/vb-dataprogramming 8/25
ئى ر م ل ا ك ي سب ل ا ى ف يت م ل ا ء ا ر إ Operations in VB
+ Addition Value=x+y
- Subtraction Value=x-yfirstName=Text1.Text
secondName=Text2.Text
yourName=firstName+secondName
number1=val(Text3.Text)
number2=val(Text4.Text)
number3=num1*(num2^3)
number4=number3 Mod 2
number5=number4\number1
Total=number1+number2+number3+number4+number5
Average=Total/5
أثة
8/2/2019 VB Data&Programming
http://slidepdf.com/reader/full/vb-dataprogramming 9/25
الميت Operation Precedenceألوة
() Parentheses
^ Exponentiation
*, / Multiplication and Division
\ Integer Division
Mod Modulo arithmetic
+, - Addition and Subtraction
=,>,<,<>,>=,<= Relational Operations
NOT Logical Negation
AND AND Operation
OR OR Operation
XOR XOR Operation
ى ر ي ب أ ى ف يم ي ل مشل ا يت م ل ا
الموضحة لوت
Print ((24-(3*5)/2-0.5)^2 16
8/2/2019 VB Data&Programming
http://slidepdf.com/reader/full/vb-dataprogramming 10/25
يقت Commentsإضفة
ار-1 ادخس Rem
Print “This following is a remark statement”
Rem This print instruction will print what is between the two quotation marks
ة م د rem. ق ي ر ب ر ط ل ا ة ن ى
اة-2 اليص ة اد خس
X=(15-2*4)/2 ‘ The result will be 3.5
ى ة ا يص ل ا ة مة د . ق ي بر لطر ا ة ن
8/2/2019 VB Data&Programming
http://slidepdf.com/reader/full/vb-dataprogramming 11/25
Function Value Returned
Abs Absolute value of a number Asc ASCII or ANSI code of a character Chr Character corresponding to a given ASCII or ANSI codeCos Cosine of an angleDate Current date as a text stringFormat Date or number converted to a text string
Left Selected left side of a text stringLen Number of characters in a text stringMid Selected portion of a text stringNow Current time and dateRight Selected right end of a text stringRnd Random number Sin Sine of an angleSqr Square root of a number Str Number converted to a text stringTime Current time as a text stringTimer Number of seconds elapsed since midnightVal Numeric value of a given text string
وح VB ر يى س ى ل ا ا د خ سا ر ي ث ل ا ا د ل ا د د ل ا ى قت ي ب ط ل ا ب
8/2/2019 VB Data&Programming
http://slidepdf.com/reader/full/vb-dataprogramming 12/25
قت( ) ح ل ا ر ش ل ا ر ا أ ج ن ر ب ل ا ر ي س ى ف ح ل ا
Condition and loop statements
… Ifار-1 ThenIf conditions Then
VB expressions
End If
حى أ ى ح ى ل إ ؤ ي ى أ
If Balance - Check < 0 ThenPrint "You are overdrawn"Print "Authorities have been notified"
End If
… Ifار-2 Then…ElseIf conditions Then
VB expressionsElse
VB expressionsEnd If
8/2/2019 VB Data&Programming
http://slidepdf.com/reader/full/vb-dataprogramming 13/25
If Balance - Check < 0 ThenPrint "You are overdrawn"
Print "Authorities have been notified"Else
Balance = Balance - CheckEnd If
If Balance - Check < 0 ThenPrint "You are overdrawn"Print "Authorities have been notified"
ElseIf Balance - Check = 0 ThenPrint "Whew! You barely made it"Balance = 0
ElseBalance = Balance - Check
End If
If Age = 5 Then
Category = "Five Year Old"ElseIf Age >= 13 and Age <= 19 Then
Category = "Teenager"ElseIf (Age >= 20 and Age <= 35) Or Age = 50 Or (Age >= 60 and Age <= 65) Then
Category = "Special Adult"ElseIf Age > 65 Then
Category = "Senior Citizen"Else
Category = "Everyone Else"End If
If you have a lot of conditional statements, using If..Then..Else
could be very messy
8/2/2019 VB Data&Programming
http://slidepdf.com/reader/full/vb-dataprogramming 14/25
Switch … caseار-3
For multiple conditionalstatements, it is better to use
Select Case
Select Case expression
Case value1Block of one or more VB statementsCase value2
Block of one or more VB StatementsCase value3
Block of one or more VB statements
Case value4..
Case Else Block of one or more VB Statements
End Select
8/2/2019 VB Data&Programming
http://slidepdf.com/reader/full/vb-dataprogramming 15/25
Select Case AgeCase 5
Category = "Five Year Old"
Case 13 To 19Category = "Teenager"Case 20 To 35, 50, 60 To 65
Category = "Special Adult"Case Is > 65
Category = "Senior Citizen"
Case ElseCategory = "Everyone Else"
End Select
) رح ل ر د ق ل ا ي ف ن نص ر و ح ة م A, B, C(، ل ق م ل ا ر د ق ل ا ى ط ي ف High distinct أPass. ها
8/2/2019 VB Data&Programming
http://slidepdf.com/reader/full/vb-dataprogramming 16/25
Dim grade As String
Private Sub Command1_Click()grade = Text1.TextSelect Case grade
Case "A", "a"Label1.Caption = "High Distinction"
Case "A-", "a-"Label1.Caption = "Distinction"
Case "B", "b"Label1.Caption = "Credit"
Case "C", "c"Label1.Caption = "Pass"
Case ElseLabel1.Caption = "Fail"
End Select
End Sub
Private Sub Form_Load()Text1.Text = ""
End Sub
8/2/2019 VB Data&Programming
http://slidepdf.com/reader/full/vb-dataprogramming 17/25
Loopsالحقت
-Do…WhileDo whileالمر1 condition
Block of one or more VB statementsLoop
Do
Block of one or more VB statements
Loop while condition
Do until condition
Block of one or more VB statements
Loop
Do
Block of one or more VB statements
Loop until condition
لشط ل ذ فى condition ؤي حى أ ى ح ى ل إ
8/2/2019 VB Data&Programming
http://slidepdf.com/reader/full/vb-dataprogramming 18/25
Counter=1
Do while counter <=10
Label1.caption=counter
Counter=counter+1
Loop
Counter=1
Do until counter =10
Label1.caption=counter
Counter=counter+1loop
Counter=1
Do
Label1.caption=counter
Counter=counter+1
Loop while counter <=10
Counter=1
Do
Label1.caption=counter
Counter=counter+1
Loop until counter =10
8/2/2019 VB Data&Programming
http://slidepdf.com/reader/full/vb-dataprogramming 19/25
-For…Nextاالمر2for variable = start value to end value step
Block of VB statements
next variableFor counter = 0 To 10
Msg Box = "This is loop number"& Str$ ( counter )
Next Counter
For counter = 9 To 0 step – 1
Msg Box = " This is loop number:" & Str$ (counter )
Next counter.
لى إ ؤ ي د ق ك ل ة ل ة ل غ م ة ب ل م ا ئ ر ذ ح لك ى ع ا ث ة ئ ا ه ل ق ى ل إ صي ل غ ل ة ئ ا ه ن ة ح
For i = 0 To 4I = 0Next i
8/2/2019 VB Data&Programming
http://slidepdf.com/reader/full/vb-dataprogramming 20/25
لحقت ا يش
For i=1 to 10
For j=1 to 10
Block of VB statements
Next j
Next i Exitار
For 1 = 1 To 20If A > B Then Exit for
Next i
Counter = 10Do while counter < 20
Counter = counter + 1If A > B Then Exit Do
Loop
8/2/2019 VB Data&Programming
http://slidepdf.com/reader/full/vb-dataprogramming 21/25
بة سحل ا ة ل ا نج ر ب ل و
بة سحل ا ة ل ا ى ح نج ر
شل ا ى ف م ة ي ق ي ق ح ل ا
Dim operation As StringDim FirstNum As StringDim SecondNum As String
Dim value As DoubleDim value1 As DoubleDim value2 As DoubleDim flag As Integer
Private Sub cmd0_Click()If flag = 0 ThenIf FirstNum = "" ThenLabel1.Caption = ""FirstNum = FirstNum + "0"ElseFirstNum = FirstNum + "0"End If Label1.Caption = FirstNum
Else
If SecondNum = "" ThenLabel1.Caption = ""SecondNum = SecondNum + "0"ElseSecondNum = SecondNum + "0"End If Label1.Caption = SecondNum
End If
End Sub
8/2/2019 VB Data&Programming
http://slidepdf.com/reader/full/vb-dataprogramming 22/25
Private Sub cmd1_Click()If flag = 0 ThenIf FirstNum = "" ThenLabel1.Caption = ""FirstNum = FirstNum + "1"ElseFirstNum = FirstNum + "1"End If Label1.Caption = FirstNum
ElseIf SecondNum = "" ThenLabel1.Caption = ""SecondNum = SecondNum + "1"
ElseSecondNum = SecondNum + "1"End If Label1.Caption = SecondNum
End If End Sub
Private Sub cmd2_Click()If flag = 0 ThenIf FirstNum = "" ThenLabel1.Caption = ""FirstNum = FirstNum + "2"ElseFirstNum = FirstNum + "2"End If Label1.Caption = FirstNum
ElseIf SecondNum = "" ThenLabel1.Caption = ""SecondNum = SecondNum + "2"
ElseSecondNum = SecondNum + "2"End If Label1.Caption = SecondNum
End If End Sub
Private Sub cmd3_Click()If flag = 0 ThenIf FirstNum = "" ThenLabel1.Caption = ""FirstNum = FirstNum + "3"
ElseFirstNum = FirstNum + "3"End If Label1.Caption = FirstNum
ElseIf SecondNum = "" ThenLabel1.Caption = ""SecondNum = SecondNum + "3"
ElseSecondNum = SecondNum + "3"
End If Label1.Caption = SecondNum
End If End Sub
8/2/2019 VB Data&Programming
http://slidepdf.com/reader/full/vb-dataprogramming 23/25
Private Sub cmd4_Click()If flag = 0 ThenIf FirstNum = "" ThenLabel1.Caption = ""FirstNum = FirstNum + "4"Else
FirstNum = FirstNum + "4"End If Label1.Caption = FirstNum
ElseIf SecondNum = "" ThenLabel1.Caption = ""SecondNum = SecondNum + "4"
ElseSecondNum = SecondNum + "4"End If Label1.Caption = SecondNum
End If End Sub
Private Sub cmd5_Click()If flag = 0 ThenIf FirstNum = "" ThenLabel1.Caption = ""FirstNum = FirstNum + "5"
Else
FirstNum = FirstNum + "5"End If Label1.Caption = FirstNum
ElseIf SecondNum = "" ThenLabel1.Caption = ""SecondNum = SecondNum + "5"
ElseSecondNum = SecondNum + "5"
End If Label1.Caption = SecondNum
End If End Sub
Private Sub cmd6_Click()If flag = 0 Then
If FirstNum = "" ThenLabel1.Caption = ""FirstNum = FirstNum + "6"Else
FirstNum = FirstNum + "6"End If Label1.Caption = FirstNum
ElseIf SecondNum = "" ThenLabel1.Caption = ""SecondNum = SecondNum + "6"
ElseSecondNum = SecondNum + "6"End If Label1.Caption = SecondNum
End If End Sub
8/2/2019 VB Data&Programming
http://slidepdf.com/reader/full/vb-dataprogramming 24/25
Private Sub cmd7_Click()If flag = 0 ThenIf FirstNum = "" ThenLabel1.Caption = ""FirstNum = FirstNum + "7"
ElseFirstNum = FirstNum + "7"End If Label1.Caption = FirstNum
ElseIf SecondNum = "" ThenLabel1.Caption = ""SecondNum = SecondNum + "7"ElseSecondNum = SecondNum + "7"End If Label1.Caption = SecondNum
End If End Sub
Private Sub cmd8_Click()If flag = 0 ThenIf FirstNum = "" ThenLabel1.Caption = ""FirstNum = FirstNum + "8"
ElseFirstNum = FirstNum + "8"End If Label1.Caption = FirstNum
ElseIf SecondNum = "" ThenLabel1.Caption = ""SecondNum = SecondNum + "8"
ElseSecondNum = SecondNum + "8"End If Label1.Caption = SecondNum
End If End Sub
Private Sub cmd9_Click()If flag = 0 ThenIf FirstNum = "" ThenLabel1.Caption = ""FirstNum = FirstNum + "9"ElseFirstNum = FirstNum + "9"End If Label1.Caption = FirstNum
ElseIf SecondNum = "" ThenLabel1.Caption = ""SecondNum = SecondNum + "9"
ElseSecondNum = SecondNum + "9"End If Label1.Caption = SecondNum
End If End Sub
8/2/2019 VB Data&Programming
http://slidepdf.com/reader/full/vb-dataprogramming 25/25
Private Sub cmdDiv_Click()operation = "÷"flag = 1value1 = Val(Label1.Caption)End Sub
Private Sub cmdMinus_Click()operation = "-"flag = 1value1 = Val(Label1.Caption)
End Sub
Private Sub cmdMul_Click()
operation = "X"flag = 1value1 = Val(Label1.Caption)
End Sub
Private Sub cmdPlus_Click()operation = "+"flag = 1
value1 = Val(Label1.Caption)End Sub
Private Sub Form_Load()flag = 0Label1.Caption = ""cmdOFF.Caption = "OFF"
End Sub
Private Sub cmdOFF_Click()If cmdOFF.Caption = "OFF" Thencmd0.Enabled = Falsecmd1.Enabled = Falsecmd2.Enabled = Falsecmd3.Enabled = Falsecmd4.Enabled = Falsecmd5.Enabled = False
cmd6.Enabled = Falsecmd7.Enabled = Falsecmd8.Enabled = Falsecmd9.Enabled = FalsecmdPlus.Enabled = FalsecmdMinus.Enabled = FalsecmdMul.Enabled = FalsecmdDiv.Enabled = FalsecmdEqual.Enabled = FalsecmdCancel.Enabled = False
cmdOFF.Caption = "ON"Elsecmd0.Enabled = Truecmd1.Enabled = Truecmd2.Enabled = Truecmd3.Enabled = Truecmd4.Enabled = Truecmd5.Enabled = Truecmd6.Enabled = Truecmd7.Enabled = Truecmd8.Enabled = True
cmd9.Enabled = TruecmdPlus.Enabled = TruecmdMinus.Enabled = TruecmdMul.Enabled = TruecmdDiv.Enabled = TruecmdEqual.Enabled = TruecmdCancel.Enabled = TruecmdOFF.Caption = "OFF"
End If End Sub
Private Sub cmdEqual_Click()value2 = Val(Label1.Caption)If operation = "+" Thenvalue = value1 + value2Label1.Caption = Str$(value)
End If
If operation = "-" Thenvalue = value1 - value2Label1.Caption = Str$(value)
End If If operation = "X" Thenvalue = value1 * value2Label1.Caption = Str$(value)
End If
If operation = "÷" Thenvalue = value1 / value2Label1.Caption = Str$(value)
End If FirstNum = ""SecondNum = ""End Sub
Private Sub cmdCancel_Click()Label1.Caption = ""FirstNum = ""SecondNum = ""value1 = 0value2 = 0value = 0flag = 0
End Sub