Visual Basic
description
Transcript of Visual Basic
SQA
of 86Slide 1
Visual Basic
SQA
of 86Slide 2
About the Lecturer
โข Age 24
โข Professional experience:โข Two years as a Developer at Intel Corp.
โข 1 year as Web Developer in a small firm.
โข Head of Department in Basmach (computer science school - IDF) in the field of methodology.
โข Now at Technical System Designer in IDF
โข Specializing in Teaching:โข OO Design Principles
โข .NET
โข C++
SQA
of 86Slide 3
4. ืืืื...............................................014. ืืกืืืืช.............................................131. ืคืงืืื ื'.........................................242. ืชื ืืื.............................................349. ืืืืืืช............................................4 53. ืืขืจืืื..........................................557. ืคืื ืงืฆืืืช.........................................673. ืคืงืืื............................................7
SQA
of 86Slide 4
Visual Basic
ืืืื
SQA
of 86Slide 5
ืืืจืืช ืขื ืชืื ืืช ืืื ืื ืืจืืขืืโข
ืขืืืื ืขื ืืืฉืงื ืืฉืชืืฉ ืืจืคืืืโข
VBืฉืคืช โข
ืืืจืช ืืงืืจืก
SQA
of 86Slide 6
Toolbox
Project Explorerwindow
Properties window
Form
ToolbarMenu bar
ืกืืืืช ืืขืืืื
SQA
of 86Slide 7
Visual Basic 6ืืชืื ืืช ืกืืืืช ืืขืืืื โขโข Start->Programs->Microsoft Visual Studio 6.0-
>Microsoft Visual Basic 6.0Hello.exeืฆืืจ ืคืจืืืงื ืืืฉ โ โข" ืฉื ืืฆื ืืืจืื ืืืืื ืืืจืืจ Buttonืืืฅ ืขื ืคืงื ืืืคืชืืจ "โข
Formืืืชื ื-ืืืฅ ืคืขืืืื ืขื ืืืคืชืืจ ืืื ืืืขืืืช ืืช ืขืืจื ืืงืืโขืจืฉืื ืืช ืืงืื:โข
ืืืฅ ืขื ืืคืชืืจ ืืืคืขืืโข
ืชืืื ืืช ืจืืฉืื ื
Private Sub Command1_Click()MsgBox ("Hello world")End Sub
SQA
of 86Slide 8
ืฉืคื ืืื ืืืช ืืจืืขืืโข
ืงืื ืืฉืืืืฉโข
RAD(Rapid Applictionืืชืืืื ื-โขDevelopment)
VBืืื
SQA
of 86Slide 9
โขVB ืืฉืชืืฉืช ืืืืฉื formืืื ืืืชืืืื ืืืืื
frm. ื ืฉืืจ ืืงืืืฅ formืืืืืข ืขื โข
ืืืชืื form ืืฆืืืจืช ืืช ืVBืืืขืจืืช ืฉื โขืืืืืข ืืื
OOP ืืื ืืืืืงืืช ืFormsื ืืชื ืืืชืืืืก ื-โข
Forms
SQA
of 86Slide 10
ืืคืชืืจืื, ืชืืืืช ืืงืกื, ืชืืืืช, ืชืืืืช ืกืืืื.....โข
= ืืืื ื ืฉื ืืืฉืง ืืฉืชืืฉVBืคืงื ืฉื โข
ืืืงื ืืืชื ื ืจืืื (ืืื ืืืืืจ)โข
ืืคืงืืื ืืฉ ืืืคืืื ืื (ืืืืืื ืฆืืข ืจืงืข)โข
ืฉืืืฉื ืกืืืื:โขืกืื ืืจืืืโข
)MSืื ืกืื ืืจืืื ืฉื ืืืจื ืฆื ืฉืืืฉื (ืืื โข
โขActiveXืฉื ืืชืืื ืคื ืืืืช
Controls
SQA
of 86Slide 11
โ ืื ืฉืคื ืืื ืืืช ืืืืืืงืืื VB ื-OOืืฉ ืืขื โขืืืืจื
)Formืืฉ ืืคืฉืจืืช ืืืฆืืจ ืืืืืืงืืื (ืืืืืื โข
ืชืืื ื = ืขืจื ืืืืข ืฉืืืืืก ืืืืืืืงืโข
ืืชืืื = ืืฉืื ืฉืืืืืืืงื ืืืื ืืขืฉืืชโข
ืืืืืืงืืื
SQA
of 86Slide 12
OOืืืืื ื
Dim f As Form2Set f = New Form2
f.Show
f.BackColor = RGB(255, 0, 0)
Form2 is a class
f is an object โ an instance of class Form2
the Form2 class has a method called show
It has a property called BackColor
SQA
of 86Slide 13
Event-driven programming
GUIืืืฉื ืกืื ืืจืืืช ืโข
ืื ืืืื ืืืืฉื ืืืฉื ื (ืืืคืกืืช ืขื ืืืกื) ืฉืื โขืืชืืื ืืช ืงืืขื ืื ืฆืจืื ืืงืจืืช
) ืื ืืืคืืืงืฆืื triggers ืืืฉืชืืฉ ืงืืืข (GUIืโขืชืขืฉื (ืืขืืงืจ)
): ืืืืฆืช ืืงืฉ, ืืืืช Eventsืืืืืืืช ืืืืจืืขืื (โข ืฉื ืืืืืจtimeoutืขืืืจ,
โขEvent Handler ืืชืืื ืฉืชืชืืฆืข ืืืฉืจ ืืืืจืืข โ ืงืืจื
SQA
of 86Slide 14
Visual Basic
ืืกืืืืช
SQA
of 86Slide 15
Project
ืคืจืืืงื = ืงืื ืืฉืืื ืืคืืืงืฆืืโข
โขForm ืืืื โ ืืชืื ื ืืกืคืจ ืืคืจืืืงื ืืื =
โขModule ืงืื = VB
โขClassืืืืจืช ืืืืงืืช ืืฉื ืขืฆืื ื =
exeืืชืืฆืจ ืฉื ืืคืจืืืงื ืืื .โข
SQA
of 86Slide 16
ืงืืฆื ืคืจืืืงื
SQA
of 86Slide 17
VERSION 5.00Begin VB.Form Form1 Caption = "Form1" ClientHeight = 2445 ClientLeft = 5145 ClientTop = 4110 ClientWidth = 5070 LinkTopic = "Form1" ScaleHeight = 2445 ScaleWidth = 5070 Begin VB.CommandButton Command1 Caption = "Command1" Height = 615 Left = 1200 TabIndex = 0 Top = 600 Width = 1815 EndEndAttribute VB_Name = "Form1"Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = FalseAttribute VB_PredeclaredId = TrueAttribute VB_Exposed = FalseOption Explicit
Private Sub Command1_Click()MsgBox ("Hello world")
End Sub
Inside a .frm file
SQA
of 86Slide 18
Visual Basic
ืืฉืชื ืื
SQA
of 86Slide 19
Variables
ืืื ืืฉืชื ื ืืชืืื ืืช ืืืงืฆื ืืืคืืก ื ืชืื ืืโข
ืืื ืืืฆืืืจ ืขื ืืืืคืืก ืฉื Dimืืฉืชืืฉื ืโขืืืฉืชื ื
โข Dim x as Integer
โข Dim x,y as Integer NO!
โขCase sensitive)ืืขืจื(
ืืฉืคื ืืฉืืโข
X = 4
SQA
of 86Slide 20
Variables
ื ืืชื ืืืฉืชืืฉ ืืืฉืชื ื ืื ืื ืื ืืืืจื ื VBืโขืืืชื (ืื ืืืืืฅ) ืืื ืื ื ืืกืืฃ ืืช ืืคืงืืื
Option Explicit
ืืืืจืช ืงืืืขืืโข
Private const MyInt As Integer = 5
Stringืืื ืืืืืืง ืืืจืืืืช ืืฉืชืืฉื ืืืืคืืก โข
Dim flower As String
SQA
of 86Slide 21
ืืืคืืกืื
โข Integer Long โข Single Double โข Currencyโข Byte unsigned 0 - 255โข Stringโข Booleanโข Dateโข Objectโข Variant - do not use except explicit reason
SQA
of 86Slide 22
Variant
ืืืื ืืืืื ืื ืกืื ืฉื ืืืืขVariantืืืืคืืก โข
ื ืืชื ืืืขืช ืื ืืืคืืก ืืืืืข ืืืื ืจืืฆื ืข"ื โขVarTypeDim x As Variant
x = 1MsgBox (VarType(x))
SQA
of 86Slide 23
VarTypeืขืจืื 0 Empty (uninitialized)1 Null (no valid data)2 Integer3 Long integer4 Single-precision floating-point number5 Double-precision floating-point number6 Currency value7 Date value8 String9 Object10 Error value11 Boolean value12 Variant (used only with arrays of variants)13 A data access object14 Decimal value17 Byte value36 Variants that contain user-defined types8192 Array
SQA
of 86Slide 24
Operator operation Basic expression
^ Exponentiation A ^ B
* Multiplication A * B
/ Division A / B
+ Addition A + B
- Subtraction A - B
ืคืขืืืืช ืืจืืชืืืืืช
SQA
of 86Slide 25
ืฉืจืฉืืจ
ื ืืชื ืืฉืจืฉืจ ืฉืชื ืืืจืืืืช ืืขืืจืช ืืืคืจืืืจ ืืฉืจืฉืืจ โข&
Private Sub cmdConcatenation_Click()Dim strVar1 As StringDim strVar2 As StringDim result As StringstrVar1 = โHelloโstrVar2 = โWorldโresult = strVar1 & strVar2
End Sub
SQA
of 86Slide 26
HEXืืขืจืืช, ืืืฉื ืฉืืจื ื
ืืขืจืืช ืืชืืืืืช ืขื ืืจืฉ ', ืืืืฉืืืืช ืขื ืืกืืฃ โขืืฉืืจื
'this line is a comment
ืืืืื ืืจืื ืืืื ื ืืชื ืืคืฆื ืืฉืืจืืช ืืขืืจืช โขืงื-ืชืืชืื _
ืืื ืืืืฉืื ืืฉืืจื ืืืื
HFF0012&ืงืืืขืื ืืงืกื-ืืฆืืืืื ื ืืชืืื ืืฆืืจื: โข
SQA
of 86Slide 27
Visual Basic
ืืืจืืช
SQA
of 86Slide 28
Conversion function Converts an expression to
Cbool Boolean
Cbyte Byte
Ccur Currency
Cdate Date
CDbl Double
Cint Integer
CLng Long
CSng Single
CStr String
Cvar Variant
CVErr Error
DIM x as integerx = Cint("10")
ืืืจืืช
SQA
of 86Slide 29
Form properties
SQA
of 86Slide 30
Controls and properties
SQA
of 86Slide 31
Visual Basic
1ืคืงืืื โ ืืืง
SQA
of 86Slide 32
ืืคืงืืื ืืฉืืืืฉืืื ืืืืชืจ
โข Text Boxes
โข Labels
โข Command Buttons
โข Picture Boxes
SQA
of 86Slide 33
TextBox
ืืืฆื ืคืขืืืื ืขื ืชืืืช ืืืงืกื ืืืจืื ืืืืื ืืื โขืืืืกืืฃ ืืืืื
)F4ืืคืขืืื ืืช ืืืื ืืืืคืืื ืื (ืข"ื ืืืืฆื ืขื โข
ืืฆืืื ืขืจืืื ืืืืคืืื ืื ืฉื ืชืืืช ืืืงืกืโข
SQA
of 86Slide 34
TextBox
Text box
SQA
of 86Slide 35
ืืืคืืื ืื ืืฉืืืื
โข Name
โข Caption
โข Border style
โข Visible
โข Back Color
โข Alignment
โข Font
SQA
of 86Slide 36
.ืืืจืืืชืืืชืืื ืฉื ืชืืืืช ืืงืกื ืืื ืชืืื โข
ืื ืืกืคืจืื ืืืืืกื ืื ืืชืืืืช ืืงืกื ืืชืืจ โขืืืจืืืช.
ืืืื ื ืืืข ืฉืฆืจืื ืืืืืจ ืืช ืืืืจืืืช ืฉื ืชืืืช โขืืืงืกื ืืคื ื ืฉืืฉืชืืฉืื ืื ืืืกืคืจ
โขVal (txtBox.Text) ืืฉื ื ืืช ืืืจืืืช ืืงืื ืืืกืคืจ
numVar = Val (txtBox.Text)
txtBox.Text = Str(numVar)
ืฉืืืืฉ ืืชืืืืช ืืงืกื ืืงืื ืืคืื
SQA
of 86Slide 37
Object Prefix Example
Command Button cmd cmdStart
Form frm frmPayroll
Label lbl lblName
Picture box pic picClouds
Text box txt txtAddress
ืืืงืื ืื ืชืื ืช ืฉืืืช
SQA
of 86Slide 38
Private Sub Command1_Click()Dim num1 As IntegerDim num2 As IntegerDim result As Integernum1 = val(Text1.Text)num2 = val(Text2.Text)result = num1 + num2Label1.Caption = str(result)End Sub
Example - calculator
SQA
of 86Slide 39
ืชืจืืื
ืืืกืืคื ืืืืฉืืื ืชืืืื ืืืืกืืจ, ืืคื, ืืืืืืงโข
ืืชืขืืื ืืกืคืจืื ืื ืืืงืืื ืืืืืงื ืืืคืก โ โขื ืชืืืืก ืืื ืืืืฉื
SQA
of 86Slide 40
ืืืงืื input boxืขืืืจ ืงืื ืืืื ื ืืชื ืืืฉืชืืฉ ืโขืชืืืช ืืงืกื
โขInput Box ืืื ืชืืืช ืืืืืื ืืืืืจืช ืืจืืฉ
โข Input Box is a predefined dialog box.
ืชืืืืจ:โข
stringVar = InputBox (prompt, title)
ืงืื ืืชืืืช ืงืื
SQA
of 86Slide 41
Private Sub cmdDisplay_Click()
Dim fileName As String
fileName = InputBox("Enter the name of the file containing the information.", "Name of File")
End Sub
After executing an inputbox would pop up
Input Boxืืืืื ื-
SQA
of 86Slide 42
Visual Basic
ืชื ืืื
SQA
of 86Slide 43
If c > 5 Then x = 1 y = 3End If
If c > 5 Then x = 1: y = 3
If c > 5 Then x = 1 y = 3Else z = 7End If
If c > 5 Then x = 1 y = 3ElseIf c = 4 Then z = 7Else x = 9End If
IFืืฉืคื
SQA
of 86Slide 44
ืชืจืืื โ ืคืืชืจืื ืืฉืืืื ืจืืืืขืืช
ืขื:formืฆืจื โข a,b,c ืชืืืืช ืืงืกื ืฉืืืืื ืืช ืขืจืื 3โข
ืชืืืืช ืฉืืื ืืชืืฆืืืช ืืืฆืื2โข
ืืคืชืืจ ืืฉื "ืคืชืืจ" โ ืืงืื ืฉืืฉืืื ืืืคืชืืจ ืืคืชืืจ ืืช ืืืฉืืืืโข
sqr* ืคืื ืงืฆืื ืืฉืืจืฉ ืืื
a
acbbx
2
42
SQA
of 86Slide 45
Dim Number Number = 8 ' Initialize variable. Select Case Number ' Evaluate Number.
Case 1 To 5 ' Number between 1 and 5, inclusive. x=4Case 6, 20, 8 ' Number is 6 or 20 or 8. x=5Case 9 To 10 ' Number is 9 or 10. x=6Case is<0X=7Case Else ' Other values. x=8
End Select
select
SQA
of 86Slide 46
Visual Basic
ืืืคืื ืืฉืืืืืช
SQA
of 86Slide 47
โขExceptionืืขืื ืฉืขืืื ืืืื ืจืืฆื =
I/O ืื"ื ืงืฉืืจื ื-โข
ืืืืืื:ืงืืืฅ ืฉืื ื ืืฆื, ืืขืืช ืืืืืจ ืืฉืจืช, โขืงืื ืฉืืื ืฉื ืืืฉืชืืฉ
ืื ืืื ืชืืื ืืชืโข
โขVBืงืืจื ื exception- ืืฉื error
Error and exception handling
SQA
of 86Slide 48
Private Sub Command1_Click()Dim num1 As IntegerDim num2 As IntegerDim result As Integer
On Error GoTo myErrorHandlernum1 = Text1.Textnum2 = Text2.Textresult = num1 + num2Label1.Caption = resultExit Sub
myErrorHandler:If Err.Number = 13 Then MsgBox ("Please enter a valid number")Else MsgBox (Err.Description)End IfResume Next
End Sub
ืชืจืืื
ืืืกืืคื ืืืคืื ืืฉืืืืืช ืืืืฉืืื ืฉืืื
(11ืืคืื ืืืขืืช ืืืืืงื ืืืคืก)
ืืืืื ืืืืคืื ืืฉืืืืืช โ ืืกืคืจืื ืื ืืืงืืื
SQA
of 86Slide 49
Visual Basic
ืืืืืืช
SQA
of 86Slide 50
Dim x as Integer, total As Integertotal = 0For x = 1 To 5 total = total + xNext
Dim x as Integer, total As Integertotal = 0For x = 1 To 5 Step 2 total = total + xNext
For next loops
SQA
of 86Slide 51
Do While name<>โืกืืฃโname = InputBox)โืืงืื ืืช ืฉืื ืื ืกืืฃ ืืื ืืฆืืชโ(if name<>โืกืืฃโ Then Print name
Loop
Do while
Do name = InputBox)โืืงืื ืืช ืฉืื ืื ืกืืฃ ืืื ืืฆืืชโ(if name<>โืกืืฃโ Then Print name
Loop While name<>โืกืืฃโ
SQA
of 86Slide 52
Dim c As Integerc = 1Do While c < 5 c = c + 1Loop
Dim c As Integerc = 1Do Until c >4 c = c + 1Loop
Dim c As Integerc = 1Do c = c + 1Loop While c < 5
Dim c As Integer, x as integerc = 1x=2Do c = c + 1Loop Until c>4 And x<>3
ืืืืืืช ื ืืกืคืืช
SQA
of 86Slide 53
Visual Basic
ืืขืจืืื
SQA
of 86Slide 54
Dim x(100) As IntegerDim i As IntegerFor i = 0 To 100 x(i) = 99Next
Dim x(1 To 3, 1 To 3) As IntegerDim i as integer, j As IntegerFor i = 1 To 3 For j = 1 To 3 x(i, j) = 99 NextNext
ืืขืจืืื ืืขืื ืืืื ืงืืืข
SQA
of 86Slide 55
Dim x() As IntegerReDim x(5)
Dim i, j As IntegerFor i = 1 To 5 x(i) = 99Next
ReDim Preserve x(10)For i = 6 To 10 x(i) = 100Next
ืืขืจืืื ืืื ืืืื
ืืืืจ ืืืขืจืืช
ืืฉืืืจ ืืช ืืขืจืืื ืฉืืื
SQA
of 86Slide 56
โข Debug.print x,y,z
โข Immediate window โ CTRL G
โ ืชืจืืืืืชืื ืชืืื ืืช ืฉืชืืคืืก ืืืืฆืขืืช ืืืืืช
FOR ืืช ืืกืืื ืฉื ืื ืืืกืคืจืื . ืืฉืชืืฉื ืืืืคืกืช 9 ืขื 1ืืื-ืืืืืื ื
Debug
Debugging โ debug.print
SQA
of 86Slide 57
Visual Basic
ืกืืจืืืื ืืช ืืคืื ืงืฆืืืช
SQA
of 86Slide 58
Private Sub Command1_Click)(Dim x, y As Doublex = 1y = 2Debug.Print addUp)x, y(
End Sub
Private Function addUp)a as double, b As Double(addUp = a + bEnd Function
x and y copied to a and b
ืคืื ืงืฆืืืช
SQA
of 86Slide 59
Rnd Returns a number between 0 and 1.(excluding 1)
Sqr(n) Returns the square root of a number.
Round(n,r) The number n is rounded to r decimalplaces.
Int(n) Returns the largest integer less thanor equal to a number
ืคืื ืงืฆืืืช ื ืืืจืืืช
SQA
of 86Slide 60
Private Sub cmdEvaluate_Click()
Dim n As Single
Dim root As Single
picResults.Cls
n = 6.76
root = Sqr(n)
picResults.Print root; Int(n); Round(n,1)
End Sub
ืืืืื
SQA
of 86Slide 61
Private Sub Command1_Click()Dim x As Double, y As Doublex = 1y = 200Call bigger(x, y)End Sub
Private Sub bigger(first As Double, second As Double)If first > second Then Debug.Print firstElse Debug.Print secondEnd IfEnd Sub
Functions return values
Procedures do not โ they just do something
ืกืืจืืืื ืืช = ืคืื ืงืฆืืืช ืืื ืขืจื ืืืืจ
SQA
of 86Slide 62
ื ืืชื ืืืขืืืจ ืคืจืืืจืื ืืฉืชื ืฆืืจืืชโขโขBy value
โขBy reference
ืืขืืจืช ืคืจืืืจืื
SQA
of 86Slide 63
ืืขืชืืงืื ืืช By Valueืคืจืืืจืื ืืืืขืืจืื โขืืชืืื ืฉืืื ืืคืื ืงืฆืื
ืฉืื ืื ืขืจื ืืคืื ืงืฆืื ืื ืืฉืคืืข ืขื ืืืฉืชื ืื โขืืืงืืจืืื
ืืืฆืจ ืืฉืชื ืื ื ืืกืคืื โ ืืืจ ืืืฉืคืืข ืขื ืืืืืจืื โข(ืืฉืืขืืชื ืืืขืจืืื ืืืืืื)
VBืืืื ืืจืืจืช ืืืืื ืโข
By valueืืขืืจืช ืคืจืืืจืื -
SQA
of 86Slide 64
ืืืชืืืช ืฉื ืืคืจืืืจืื ืืืขืืจืื ืืคืื ืงืฆืืโข
ืฉืื ืื ืฉื ืขืจื ืืคืื ืงืฆืื ืืืจื ืืฉืื ืื ืืืฉืชื ืื โขืืืงืืจืืื
ืืืกื ืืืืืจืื ืืืืืจ ืืืชืจโข
ืืกืืื ืืืชืจโข
ืืื ืืืฉืชืืฉ ืืฉืืื ืื ืืฉ ืืจืฉืื ืืื ืืคืจืืืจ โขByRef
By referenceืืขืืจืช ืคืจืืืจืื -
SQA
of 86Slide 65
Private Sub Command1_Click)(Dim x As Double, y As Doublex = 1y = 200Call swap)x, y(Debug.Print x, yEnd Sub
Private Sub swap)ByRef first As Double, ByRef second As Double(Dim temp As Doubletemp = firstfirst = secondsecond = tempEnd Sub
by referenceืืขืืจื
SQA
of 86Slide 66
Private Sub Command1_Click()Dim x As Double, y As Doublex = 1y = 2Debug.Print addUp(second:=x, first:=y)End Sub
Private Function addUp(first As Double, second As Double)addUp = firstEnd Function
Named arguments
SQA
of 86Slide 67
Visual Basic
ืืืืืืื
SQA
of 86Slide 68
ืงืืฆืื ื ืคืจืืืโข
ืืืืืื ืคืื ืงืฆืืืช, ืคืจืืฆืืืจืืช ืืืฉืชื ืื ืืืืืืืโข
ืืืformืืฉืืฉ ืืงืื ืืืืืข ืฉืืงืืงืื ืื ืืืืชืจ ืโข
Modules
SQA
of 86Slide 69
Module example
SQA
of 86Slide 70
ืืฉืชื ืื ืฆืจืืืื ืืืืืช ืืืงืืืื ืขื ืืื ืฉืืคืฉืจ
Scope ืืืง ืืชืืื ืืช ืฉืื ื ืืชื :ืืคื ืืช ืืืฉืชื ื
Scope โ public private dim
SQA
of 86Slide 71
โขDIMืืืงืื ืืกืืจืืืื ื โ ืื ืขืื ืืกืืจืืืื ื ืจืฆื โ
โขPrivte\Public ืขื FORMืื ืขืื ื โ FORMืคืชืื
โขPublicืืืืืื โ ืื ืขืื ืืืคืืืงืฆืื ืจืฆื
โขStatic ืืืงืื ืืกืืจืืืื ื โ ืฉืืืจ ืขืจืื ืืื ืจืืฆืืช โ ืฉื ืืกืืจืืืื ื โ ืื ืขื ืกืืฃ ืืชืืื ืืช
ืืื ืืืื โ ืืื ืืื ืืฉืชื ื ืื
SQA
of 86Slide 72
Visual Basic
ืคืงืืื - ืืืง ื'
SQA
of 86Slide 73
ืืืฉืืจ ืืคืงืืื
SQA
of 86Slide 74
Scrollbar control
SQA
of 86Slide 75
Label1
ScrollBar1
Label2 Picture1
Private Sub VScroll1_Change()Picture1.BackColor = RGB(0, 0, VScroll1.Value)Label2.Caption = "Colour is 0, 0, " & VScroll1.ValueEnd Sub
Scrollbarืืืืื ืืฉืืืืฉ ื-
SQA
of 86Slide 76
ื ืืกืคืื ืืืจืืง ืืืืืscrollbarsืืืกืืคื โข
ืชืจืืื
SQA
of 86Slide 77
Radio buttons
SQA
of 86Slide 78
Checkboxes
SQA
of 86Slide 79
Listbox
SQA
of 86Slide 80
Tab Control ืืืกืคื -
SQA
of 86Slide 81
Tab Control ืฉืืืืฉ -
SQA
of 86Slide 82
โข Hidden control
โข Interval
โข Tick event
โข Enabled or not
Timer
SQA
of 86Slide 83
Private Sub Timer1_Timer()Dim currentTime As DatecurrentTime = Now()Label1.Caption = currentTimeEnd Sub
ืืืืื ืืืืืืจ - ืฉืขืื
SQA
of 86Slide 84
ืืชืื ืชืืื ืืช ืฉืขืืฉื ืื ืืืฆืื ืฉื ืืืืจ ืฉืื ืขื โขืืืกื
ืืืืืืจshapeืืฉืชืืฉื ืืคืงื ืฉื โข
ืืืืื ืืช ืืฆืืจื:tickืื ืคืขื ืฉืืฉ โข
Shape.left โ shape.lest+speed
ืชืจืืื ืืืืืจ
SQA
of 86Slide 85
ื ืืชื ืืฆืจืฃ ืืกืคืจ ืคืงืืื ืืืืชื ืกืื ืืืขืจื โขืคืงืืื
ืืฆืืจื ืืื ื ืืื ืืฉืชืฃ ืงืื ืฉืืืื ืชืงืฃ ืืืืื โขืื ืืื ืืืืืช ืืืื ืืืคืขื ืข"ื ืืื ืืงืก.
ืืื ืืืฆืืจ ืืขืจื ืคืงืืื ืืฉ ืืืขืชืืง ืืืืืืืง โขืืช ืืคืงื ืืจืืฉืื
ืืขืจื ืคืงืืื
SQA
of 86Slide 86
Backup
SQA
of 86Slide 87
ืืืคืฉืจืช ืืฉืื ืชืืื ื ืืืืื ืฉืื ืโขืืืคืืื ืื ืืฉืืืืโข
โขPictureืืืื ืืช ืฉื ืืงืืืฅ ืฉืืฉ ืืืฆืื โ
โขSrrech ืื ืฉืืืื ืืชืืื ืชืชืืื ืืช ืขืฆืื ืืชืืื ื ืืื โ ืืืืื ืืชืืื ื ืชืชืืื ืืช ืขืฆืื ืืชืืื
ืืืคืฉืจืช ืื ื ืืืขืื ืชืืื ื LoadPictureืืชืืืช โข
ืชืืืช ืชืืื ื
SQA
of 86Slide 88
ืืชืื ืคืจืืืงื ืืืฉ ืืืืกืฃ ืืืกื ืชืืืช ืชืืื ื ืืืช1)
ืืชืืืช ืฉื ืงืืืฅ ืชืืื ื Pictureืืฆื ืืชืื ืืืืคืืื 2) C:\Program Files\Microsoft(ื ืืชื ืืืฆืื ืชืืื ืืช ื
Visual Studio\Common\Graphics\Bitmaps(
ืืืืง ืื ืงืืจื ืืืฉืจ ืืืชืืื ืืช ืชืืืช ืืชืืื ื3)
ืชืืืช ืชืืื ื - ืืืืื
SQA
of 86Slide 89
ืืืคืฉืจ ืืืฉืชืืฉืื ืืืืืจ ืืื ื ืืืื ืจืืฆืโข
ืืืคืืื ืื ืืฉืืืืโขโขDriveืืืื ืืช ืฉื ืืืื ื ืฉืืจืืข ื ืืืจ โ
ืคืงื ืจืฉืืืช ืืื ื ืื
SQA
of 86Slide 90
ืืฆืื ืืืฉืชืืฉืื ืจืฉืืื ืฉื ืชืืงืืืชโข
ืืืคืืื ืื ืืฉืืืืโขโขPathืืืชืืืช ืฉื ืืชืืงืื ืื ืืืืืช ืฉืื ืื ื ืขืืืืื ืื โ
ืคืงื ืจืฉืืืช ืชืืงืืืช
SQA
of 86Slide 91
ืืฆืื ืืืฉืชืืฉืื ืจืฉืืื ืฉื ืงืืฆืืโข
ืืืคืืื ืื ืืฉืืืืโขโขPathืืืชืืืช ืฉื ืืชืืงืื ืื ืืืืืช ืฉืื ืื ื ืขืืืืื ืื โ
โขFileNameืฉื ืืงืืืฅ ืื ืืืจ โ
โขPatternืืืจืืืช ืขื ืชืื ืืช ืฉื ืงืืฆืื ืฉืืฉ ืืืฆืื โ dat ืืฆืื ืจืง ืืฆืื ืขื ืกืืืืช dat*.ืืืืืื:
ืคืงื ืจืฉืืืช ืงืืฆืื
SQA
of 86Slide 92
dirExampleื ื ืื ืืืฉ ืื ื ืคืงื ืชืืงืืืช ืืฉื โข drvExample ืคืงื ืืื ื ืื ืืฉื
filExampleืืคืงื ืงืืฆืื ืืฉื
โข dirExample.Path = drvExample.Driveโข filExample.Path = dirExample.Pathโข filExample.Path = dirExample.Path
ืกืื ืืจืื ืืืื ื ื, ืชืืงืื ืืงืืืฅ
SQA
of 86Slide 93
Dim YourFile as String If Right(filExample.Path,1) = "\" Then YourFile = filExample.Path + filExample.FileName Else YourFile = filExample.Path + "\" + filExample.FileName End If imgExample.Picture
ืืืืจืช ืชืืื ื ืืฆืืจื ืืื ืืืช
SQA
of 86Slide 94
ืฆืืจ ืชืืื ืืช ืฉืชืชื ืืคืฉืจืืช ืืืืืจ ืชืืื ื ืืชืฆืื ืืืชื
ืชืจืืื โ ืืฆืืช ืชืืื ืืช