Title: Visual Basic 6.0
1Visual Basic 6.0
2????????????? Visual Basic
- ?????????????? QBASIC
- ??????????????????????????????
- Visual Basic V. 1.0 ??????? 1991
- Visual Basic V. 6.0 ??????? 1998
- Visual Studio .NET ??????? 2002
3???????????????? Visual Basic
- 1. ??????????????????
- 2. ??????????????????
- 3. ???????????????? Microsoft
- 4. ??????????????????????
4???????????????? Visual Basic
- 5. Visual Basic for Application (VBA) ?????
Microsoft Office - 6. VB Script Edition ?????????????????? Home Page
- 7. ASP (Active Server Page)
5?????????????????? Event-driven
- ??????????????????????????????????????????????????
??????? ??????????? (Window) ?????????? ????
?????????, ??????????? - ????????????????????????????(Event) ???????????
6?????????????????? Procedural
- ????????????????????? Code ????????????????????
?????????????? ????????????????????????????
????????????????????
7???????????????????????
- 1. ?????????????????????????
- 2. ??????????????????????
- ?????????????????????
- ???????
- 3. ?????????????????????????
- 4. ?????????????????????
- 5. ??????????????????????
8????????? ??? Visual Basic
- Learning Edition
- Professional Edition
- Enterprise Edition
9?????????????????
- ?????????????? Windows 98-XP
- CPU Pentium ??????
- ??????????? (RAM) 32 MB ??????
- CD-ROM, Mouse, Keyboard
- ??????????? Microsoft Visual Studio 6.0
- ??????????? MSDN ??????????? Help
10???????????? Visual Basic
- ?????????????????????????????? Microsoft Windows
- ?????????? OOP
- (Object Oriented Programming)
11????????????? Visual Basic
- Object
- Properties
- Method
- Event
12(No Transcript)
13??????????????
- ???? Start gtgt Programs
- gtgt Microsoft Visual Studio 6.0
- gtgt Microsoft Visual Basic 6.0
14????????????? Visual Basic
- ??? Title Bar
- ??? Menu Bar
- ??? Tool Bar
- ???????? Form Windows
- View ?Object
15????????????? Visual Basic
- ???????? Project Explorer
- View ? Project Explorer ltCtrlRgt
- ???????? Properties
- View ? Properties Window ltF4gt
16????????????? Visual Basic
- ???????? Form Layout
- View ? Form Layout Window
- ????????????? Toolbox
- View ? Toolbox
17????????????????Application
18???????? Application ????
- File ? New Project
- ????? Standard EXE
- ???????? OK
19????????? Application
- ???????????????????? ??????? Form ??? Project
- File ? Save Form ???? Project
- ????????????? ???? ???? project
- ???????? Save
20???????? Form ????
- Project ? Add Form
- ????
- ???? Toolbar ?????????? Form
21???????? Form ?????????????
- Project ? Add File
- ????????????????????
- ???????? Open
22?????? Form ???
- ??????????
- Project ? Remove ????Form
23??? Run Application
- Run ? Start
- ????
- ?????? F5 ??????? Toolbar
24??? Stop Application
- Run ? End
- ????
- ??? Toolbar
25???????????????????
- ???? Project ? Project Properties
- ????? General
- ???????? Startup Object
26????????????????????????????? VB6
- ??????????????????????
- ??????????????
- ?????????????????????
- ???????????????????????
27????????????????????????????? VB6
- ???????????????????????????
- ???????????????? Properties Windows
- Object List Box ????????????????????????????????
??? - Properties List ????????????????????????????????
??????????????????????? - Description Pane ???????????????????????????????
??????????????? - ???????????????? Code ??????
28????????????????????????????? VB6
- ???????? Code ????????????????????? Event
- ???????????? Code Editor
- ??????????????????????? Object
- ?????????????????? Event
- ??????????????????????????? Private
Sublt???????????gt_lt????????????gt ??? End Sub
??????????????????????????????????????????????????
???
29???????? Properties ???????????????
- Object_Name.Properties_Name ??????properties
???? Form1.Caption ???????????????????"
Form1.FontSize 20
30Properties ?????????? Control
- Enabled
- Visible
- FontBold,FontItalic
- FontName,FontSize
- FontUnderline
- MousePointer
- Name
- Caption
- ForeColor
- BackColor
- Height, Width
- Left ,Top
- TabIndex
30
31??????????? Form
32Properties ??? Form
- Name
- BackColor
- ForeColor
- Caption
- Enabled
- Font
- Icon
- MinButton
- MaxButton
- Height
- Width
- AutoRedraw
32
33Properties ??? Form
- MousePointer
- MouseIcon
- ( MousePointerCustom )
- Picture
- Visible
- CurrentX
- CurrentY
33
34Method ??? Form
Form_Name.Hide
Form_Name.Show
Form_Name.Cls
35?????? Method ???????????????
- Object_Name.Method_Name ?????????????? Method
???? Form1.Print "Siam Computer" Me.Show
36Event ??? Form
- Activate ?????????? Activate
- Click ?????????????????
- DblClick ?????????????????????????
- Load ?????????????????????????
- UnLoad ?????????????
37???????????
- Sub Form_Activate( )
- Form1.FontSize20
- Print Test Visual Basic
- Print Siam Computer
- End Sub
38???????????
????? ????????? ( )
- Sub Form_Activate( )
- Form1.Font.Size20
- Print Test Visual Basic
- Print Siam Computer
- CurrentX 1500
- CurrentY 1000
- Print New Position
- End Sub ( )
39??????????? 2
??????? ????????? ??????????? Form
Name Form1 AutoRedraw True CommandButton
Name Command1 Caption Clear
40??????????? 2
Sub Form_Activate() Form1.Print
Form_Activate End SubSub Form_Click()
Form1.Print Form_Click End SubSub
Command1_Click() Form1.ClsEnd Sub
Sub Form_DblClick() Form1.Print Double_Click
End SubSub Form_Resize() Form1.Print
Form_ResizeEnd Sub
41Object ???????????????? Operator
42Label (properties)
- Name
- Alignment
- AutoSize
- BorderStyle
- BackStyle
- Caption
- Left
- Top
42
43Text Box (properties)
- Name
- Text
- MaxLenght
- PasswordChar
- Multiline
- ScrollBars
- TabIndex ???????? 0
- TabStop
- ToolTipText
44Method
- Object_Name.SetFocus
- ???????? cursor ?? focus ??? Object
???? Text1.Setfocus Command1. Setfocus
45Properties..
- SelStart ??????????????????????
- SelLength ?????????????????????? ????????????
46Event
- Change ???????????????????????? Text
- GotFocus ????? Text ?????? Focus
- LostFocus ????? Text ??????? Focus
47Command Button (properties)
- Name
- Caption
- Default
- Picture
- Style
48???????????
?????????????? 2 Text Box
49Source Code
Sub cmdMultiply_Click() a txtnum1.Text b
txtnum2.Text lblResult.Caption a " "
b " " a b End Sub
50Operator ????????????????????
' ???????????????????????????????Comment
51?????????? Font ?? View Code
- ???????????????? Code ??????????????
- ???? Tools ?Option ?Editor Format
- ?????? Font ????????? Font ????????????? UPC
???? DSE - ???? BrowalliaUPC
52????????????????????
- ????????????????????????????????
- ???? Tools ?Option ?Editor
- Require Variable Declaration
- ????? Option Explicit ?? View Code
53??????????????????????????
- Dim variable_name As Data_Type
Const const_name Value
???? Dim data1 As Integer Const name Somjate
54???????????????????
- ??????????????????????????????
- ????????????????????? 255 ????????
- ???????????,????????? _ ?????????????????
- ???????????????? ???? Dim
- ???????????????????????????????????????????
55?????????????
- Byte? 0 ??? 255 (1 Byte)
- Integer ? -32,768 ??? 32,767 (2 Byte)
- Long ? -2,147,483,648 ??? 2,147,483,647
- (4 Byte)
- Currency ?-922,337,203,685,477.5808 ???
922,337,203,685,477.5807 (8 Byte)
56????????????? (???)
- Single ?????????????????? (4 Byte)
- ????? -3.402823x1038 ??? -1.401298x10-45 ???
- ?????? 1.401298x10-45 ??? 3.402823x1038
- Double ? ????????????????? (8 Byte)
- ????? 1.79769313486232x10308 ???
- 4.94065645841247x10-324 ???
- ?????? 4.94065645841247 x10-324 ???
1.79769313486232x10308
57????????????? (???)
- Date ? ??????????????????? (8 Byte)
- String ? ???????????????????
- Boolean ? ??????????? (2 Byte)
- Variant ? ??????????? (22 Byte)
58Operator ?????????????
- ?????? ????????
- ???
- - ??
- ???
- / ???
- \ ????????????
- Mod ????????????
- ???????
59???????????
??????????? Operator ?????????????
60Private Sub Command1_Click() Dim a As Integer Dim
b As Integer a Text1.Text b
Text2.Text Label3.Caption a " / " b " "
a / b Label4.Caption a " \ " b " "
a \ b Label5.Caption a " mod " b " "
a Mod b Label6.Caption a " " b " "
a b End Sub
61??????????????? (Scope of variable)
- ?????????????? (Local)
- ??????????????? (Global)
- Private ?????????????????????? Form ?????????
- Public ?????????????????????????????
62Operator ?????????????????
- ?????? ????????
- ???????
- gt ???????
- gt ??????????????????
- lt ????????
- lt ???????????????????
- lt gt ??????????
63???????????
??????????? Operator ?????????????????
64Private Sub cmdCompare_Click() Dim a As
String Dim b As String a txtNumber1.Text b
txtNumber2.Text lblNum1.Caption a " gt " b
" " (a gt b) lblNum2.Caption a " lt " b
" " (a lt b) lblNum3.Caption a " " b
" " (a b) lblNum4.Caption a " ltgt " b
" " (a ltgt b) End Sub
65Operator ????????
66?????????????
Arithmetic Comparison Logical
Exponentiation () Equality () Not
Negation (-) Inequality (ltgt) And
Multiplication and division (, /) Less than (lt) Or
Integer division (\) Greater than (gt) Xor
Modulus arithmetic (Mod) Less than or equal to (lt) Eqv
Addition and subtraction (, -) Greater than or equal to (gt) Imp
String concatenation () Is
66
67?????????????????????
- Round(number)
- ???????????????????????????????????????
Int(number) ?????????????????????????????????????
????
68?????????????????????
- Rnd(Number)
- Rnd ????????????????????????
???? ???????????????? 0-9 Label1.Caption
Int(Rnd 9) (Randomize ????????????????????????)
69?????????????????????
- Sqr(number)
- ??????????????????????????
Abs(number) ?????????????????????????????????
70??????????????????????????
- InStr(Start,String1,String2,Compare)
- ?????????????????? String
Replace(String1,Find, Replace) ??????????????????
String ??????????????
71??????????????????????????
- UCase(String)
- ?????????? String ????????????????????
LCase(String) ?????????? String
????????????????????
72???????????
73???????????
Private Sub txtTEXT1_Change() txtText2.Text
UCase(txtTEXT1.Text) txtText3.Text
LCase(txtTEXT1.Text) End Sub
Private Sub cmdClear_Click() txtTEXT1.Text
"" txtTEXT1.SetFocus End Sub
74??????????????????????????
- Str(Numeric)
- ??????? Numeric ???? String
Val(String) ??????? String ???? Numeric
75??????????????????????????
- IsNumeric(String)
- ?????????????? Numeric ???????
IsDate(String) ?????????????? Date ???????
76??????????????????????????
- LTrim(String)
- ???????????????????????????? String ???
RTrim(String) ????????????????? ?????????? String
???
77??????????????????????????
- Trim(String) ???????????????????????????????????
String
Format(value , "??????") ???????????????????????
78??????????????? (Date)
- "dd/mm/yy" ? "Short Date"
- "dd/mmm/yyyy" ? "Medium Date"
- "dd/mmmm/yyyy" ? "Long Date"
79????????????????????????????????
- Now
- ????????????????????? ? ????????
Time ???????????? ? ????????
80????????????? (Time)
- "HHMM" ? "Short Time"
- "HHMM AMPM" ? "Medium Time"
- "HHMMSS" ? "Long Time"
81???????????
???????????????????
82???????????
Dim a As Date Dim b As Date Sub Command1_Click()
a Time Text1.Text Format(a,
"HHMMSS") Text2.Text "" Label1.Caption
"" End Sub
83???????????
- Sub Command2_Click()
- b Time
- Text2.Text Format(b, "HHMMSS")
- End Sub
- Sub Command3_Click()
- Label1.Caption Format(b - a, "HHMMSS")
- End Sub
84IfThenElse Statement
- If ???????? Then
- Statement
- Else
- Statement
- End If
85Flow-Chart
86IfThenStatement
- If ???????? Then Statement
87IfThenElse Statement
- If ???????? Then
- Statement
- Else
- Statement
- End If
If ???????? Then Statement Elseif ????????
Then Statement Elseif ????????
Then Statement Else Statement End if
88?????????????? ElseIf
- Dim Number, Digits, MyString
- Number Text1.Text
- If Number lt 10 Then
- Digits 1
- ElseIf Number lt 100 Then
- Digits 2
- Else
- Digits 3
- End If
89Unload Statement
???? Private Command1_Click() Unload Form1
'???? Unload Me End Sub
90End Command
???? Private Command1_Click() End '
?????????? End Sub
91???????????
Private Sub cmdOK_Click() If txtPass.Text
"basic" Then frmCalculate.Show
Unload Me Else txtPass.Text ""
txtPass.SetFocus End If End Sub
???????????????
Lcase(Text1.text)
92???????????
??????????????????????
93???????????
Private Sub Command1_Click() If Text1.Text
"basic" Then Form1.Show Unload
Me Else Text1.Text ""
Text1.SetFocus End If End Sub
Private Sub Command2_Click() End End Sub
Lcase(Text1.text)
94Select Case Statement
- Select Case ??????
- Case ????????1 ???? ????????1
- statement
- Case ????????2 ???? ????????2
- statement
- Case Else
- statement
- End Select
95Flow-Chart
96???????????
??????????????
97???????????
Private Sub CmdGrade_Click() Dim score As
Integer Dim grade As String score
Val(txtmark.Text)
98???????????
Select Case score Case Is gt 80 grade
"A" Case Is gt 70 grade "B" Case
Is gt 60 grade "C" Case Is gt 50 grade
"D" Case Else grade "F" End
Select lblgrade.Caption txtName.Text "
your grade is " grade End Sub
99Check Box (properties)
- Value
- 0 (Unchecked)
- 1 (Checked)
- 2 (Grayed)
100???????????
????????????????? ?????? Check Box
101???????????
Private Sub chkTime_Click() If chkTime.Value
1 Then lbltime.Caption Format(Now,
"HHMMSS") Else lbltime.Caption ""
End If End Sub
102Private Sub Chkdate_Click() If chkDate.Value 1
Then lblDate.Caption Format(Now,"dd/mmmm/yyyy
") Else lblDate.Caption "" End
If End Sub
103Option Button (properties)
- Value
- True (Select)
- False (Not Select)
104???????????
?????????????? Option Button
105???????????
Private Sub Optmale_Click() lblgender.Caption
"Male" End Sub
Private Sub Optfemale_Click()
lblgender.Caption "Female" End Sub
106???????????
???????????????
107Private Sub OptRectangle_Click() txtnumber1.Text
"" txtNumber2.Text "" lblResult.Caption
"" txtNumber1.SetFocus lblName1.Caption
"?????" lblName2.Caption "???" lblName3.Caption
"?????????????????" End Sub
108Private Sub OptTriangle_Click() txtNumber1.Text
"" txtNumber2.Text "" lblResult.Caption
"" txtNumber1.SetFocus lblName1.Caption
"???" lblName2.Caption "???" lblName3.Caption
"?????????????????" End Sub
109Private Sub cmdCal_Click() txtNumber1.SetFocus
If Optrectangle.Value True Then
lblResult.Caption Val(txtnumber1.Text)
Val(txtNumber2.Text) Else
lblResult.Caption 0.5 Val(txtNumber1.Text)
Val(txtNumber2.Text) End If End Sub
110Frame (properties)
111???????????
?????????????????????????????
112????????
???????? ??? ???? ????????? ??????? ???? ???.
???? ????????????? ???. ??????? ???????
113Private Sub cmdposition_Click() If Optmale.Value
True Then If Optedu1.Value True Then
lblCareer.Caption "???????" ElseIf
Optedu2.Value True Then
lblCareer.Caption "????" ElseIf
Optedu3.Value True Then
lblCareer.Caption "???????" End If Else
' ElseIf Option2.Value True Then
114 If Optedu1.Value True Then
lblCareer.Caption "????" ElseIf
Optedu2.Value True Then
lblCareer.Caption "?????????????"
ElseIf Optedu3.Value True Then
lblCareer.Caption "???????" End If End
If End Sub
115Function MsgBox
- MsgBox Prompt ,Buttons ,Title
- Prompt? ?????????????????????
- Buttons? ?????????????????????
- Title ? ???????????????????? Box
116???????? Message Box
117???????????????????? (Icon)
- vbCritical
- vbInformation
- vbExclamation
- vbQuestion
117
118Function MsgBox
?????? MsgBox(Prompt ,Buttons ,Title)
119?????????????? Msgbox
120HScrollBar ??? VScrollBar (properties)
Min
Max
121Event
- Change ??????????????????? LargeChange ????
SmallChange - Scroll ??????????????????? Scroll Box
122???????????
?????????? Properties ??? Scrollbar
123Sub HScroll1_Change() lblInfo.Caption "Value
" HScroll1.Value End Sub
Sub HScroll1_Scroll() lblInfo.Caption "Value
" HScroll1.Value End Sub
124????????????????
- Object_Name.Properties Color_Name
???? lblName.ForeColor VbRed frmData.BackColor
VbGreen
125???????????
??????????????????????
126???????????
??????????????????????
127(No Transcript)
128Dim data As String Private Sub Form_Load()
'Width 4125 Height 1440 End Sub
129Private Sub cmdFont_Click() data
txtName.Text lblName.Caption data 'Width
4125 Height 4080 End Sub
130Private Sub chklowercase_Click() If
chklowercase.Value 1 Then
chkuppercase.Value 0 lblName.Caption
LCase(data) Else lblName.Caption
data End If End Sub
131Private Sub chkuppercase_Click() If
chkuppercase.Value 1 Then
chklowercase.Value 0 lblName.Caption
UCase(data) Else lblName.Caption
data End If End Sub
132Private Sub chkItalic_Click() If
chkitalic.Value 1 Then lblName.Font.Italic
True Else lblName.Font.Italic
False End If End Sub
133Private Sub chkBold_Click() If chkbold.Value
1 Then lblName.Font.Bold True Else
lblName.Font.Bold False End If End Sub
134Private Sub HScsize_Change() lblName.Font.Size
HScsize.Value End Sub Private Sub
Command3_Click() 'Width 4125 Height
1440 End Sub
135Private Sub optRed_Click() lblName.ForeColor
vbRed End Sub Private Sub optBlue_Click()
lblName.ForeColor vbBlue End Sub
136Private Sub cmdOk_Click() 'Width 4125
Height 1440 txtName.Text lblName.Caption
txtName.Font.Bold lblName.Font.Bold
txtName.Font.Italic lblName.Font.Italic
txtName.Font.Size lblName.Font.Size
txtName.ForeColor lblName.ForeColor End Sub
137?????????????????????
- QBColor(n)
- ??? n ???????????? 0 - 15
???? Label1.BackColor QBColor(1)
138?????????????????????
- RGB(Red,Green,Blue)
- ?????????????????? 0 - 255
???? Label1.BackColor RGB(0,0,255)
Label1.ForeColor RGB(255,0,255)
139???????????
?????????????? Scroll Bars
140Private Sub Form_Load() lblRed.Caption "Red
" HScRed.Value lblGreen.Caption "Green
" HScGreen.Value lblBlue.Caption "Blue "
HScBlue.Value lblShow.BackColorRGB(0,0,0)
lblshow.ForeColorRGB(255,255,255) End Sub
141(No Transcript)
142Private Sub HScGreen_Change()
lblShow.BackColor RGB(HScRed.Value, _
HScGreen.Value, HScBlue.Value)
lblShow.ForeColor RGB(255 - HScRed.Value, _
255 - HScGreenValue, 255
HScBlue.Value) lblGreen.Caption "Green "
HScGreen.Value End Sub
143Private Sub HScBlue_Change() lblShow.BackColor
RGB(HScRed.Value, _
HScGreen.Value, HScBlue.Value)
lblShow.ForeColor RGB(255 - HScRed.Value, _
255 - HScGreen.Value, 255 -
HScBlue.Value) lblBlue.Caption Blue "
HScBlue.Value End Sub
144LOOP
145ForNext Statement
- For ?????? ??????????? To ??????????
- Step ?????/???????????
- statement
- statement
- Next ?????????
146???????? ForNext Statement
- For I 0 To 100 Step 2
- statement
- statement
- Next I
147Flow-Chart
148???????????
?????????? 1 ??? 20
Private Sub Form_Click() Dim i As Integer
For i 1 To 20 Print i Next
i End Sub
149DoLoop Statement
- Do while (????????)
- Statement
-
- Loop
Do Until (????????) Statement Loop
150DoLoop Statement (???)
- Do
- Statement
-
- Loop while (????????)
Do Statement Loop Until (????????)
151Flow-Chart (Do While)
152Flow-Chart (DoUntil)
153?????????? 1 ??? 20
???????????
Private Sub Form_Click() Dim i As Integer i
1 Do While (i lt 20) Print i i
i 1 Loop End Sub
Private Sub Form_Click() Dim i As Integer i
1 Do Print i i i 1 Loop
Until (i gt 20) End Sub
152
154?????????? 10 ?????? 1
???????????
Private Sub Form_Click() Dim i As Integer i
10 Do While (i gt 1) Print i i
i - 1 Loop End Sub
Private Sub Form_Click() Dim i As Integer i
10 Do Print i i i - 1 Loop
Until (i 0) End Sub
155WhileWend Statement
- While (????????)
- statements
-
- Wend
156???????????
?????????? 10 ?????? 1
Private Sub Form_Click() Dim i As Integer i
10 While i gt 0 Print i i i -
1 Wend End Sub
157List Box (properties)
- Sorted
- Style
- Standard
- Checkbox
- Name
- Columns
- List
- ListIndex
- Text
- ListCount
156
158???????? List Box
159Method
- List1.AddItem ??????, index
List1.RemoveItem index
List1.Clear
160With End With Statement
- With Object_Name
- .Properties Value
- .Method
- End With
161Goto Statement
- Goto label
- Statement
- label
- Statement
Sub Command1_Click() GoTo aa Label1.Caption
VB" aa Label1.Caption "Siam End Sub
162On Error Goto
- On Error Goto label
- Statement
- label
- Statement
163On Error Resume Next
- On Error Resume Next
- Statement
- Statement
164???????????????????????
- Resume ????????????????????? Error ????
- Resume Next ??????????????????????????????
Error ????
165Error Object
- ???? Object ??????????????????????????????????????
????? Run Time - ??????
- Err.Properties
166Properties
167OnGoto OnGoSub
- On expression GoSub destinationlist
- On expression GoTo destinationlist
168???????????
169???????????
??????????????? List
170Private Sub Form_Load() lstPrg.AddItem
"Widows" lstPrg.AddItem "Word"
lstPrg.AddItem "Excel" lstPrg.AddItem
"Access" lstPrg.AddItem "Power Point" End Sub
????
171Private Sub Form_Load() With lstPrg .AddItem
"Widows" .AddItem "Word" .AddItem
"Excel" .AddItem "Access" .AddItem "Power
Point" End With End Sub
172(No Transcript)
173???????????
???????????? List
174Private Sub cmdADD_Click() If
Trim(txtData.Text) ltgt "" Then
lstInfo.AddItem txtData.Text End If
txtData.Text "" txtData.SetFocus End Sub
175Private Sub cmdRemove_Click() If
lstInfo.ListIndex gt 0 Then
lstInfo.RemoveItem lstInfo.ListIndex
lstInfo.ListIndex 0 End If End Sub Private
Sub cmdClear_Click() lstInfo.Clear '
??????????????? End Sub
176???????????
??????????????? List 2 List
177Private Sub Form_Load() List1.AddItem
"Pascal" List1.AddItem "Basic"
List1.AddItem "C" List1.AddItem "Delphi"
List1.AddItem "Visual Basic" List1.AddItem
"Visual C" End Sub
178(No Transcript)
179Private Sub cmdMoveall_Click() Dim i As Integer
For i 0 To List1.ListCount - 1
List2.AddItem List1.List(i) Next i
List1.Clear End Sub
180Combo Box (properties)
- Name
- Style
- Dropdown Combo
- Simple Combo
- Dropdown List
????????????????????? List Box
181???????????
??????????????????????? Combo
182???????????
???????????
??????
?????
183Private Sub Form_Load() cmbColor.AddItem
"Blue" cmbColor.AddItem "Green" cmbColor.AddItem
Magenta" cmbColor.AddItem "Red"
cmbColor.AddItem "Yellow" End Sub
184Private Sub cmbColor_Click() Select Case
cmbColor.ListIndex Case 0 Me.BackColor
vbBlue Case 1 Me.BackColor vbGreen
Case 2 Me.BackColor vbMagenta Case
3 Me.BackColor vbRed Case 4
Me.BackColor vbYellow End Select End Sub
185Function InputBox
- ?????? InputBox(Prompt ,Title ,Default)
Prompt ????????????????????? Title
??????????????????????? Box Default
?????????????????
186??????????? InputBox
187???????????
??????????? Question ???????????????????????
188Dim n As Integer Dim Ans As String Private Sub
Form_Load() n 0 End Sub
189Private Sub cmdQuestion1_Click() Ans
InputBox("?????????????? ?" Chr(13) _
"VB, Delphi", "Question") If LCase(Ans)
"vb" Then n n 1 End If
cmdQuestion2.Enabled True cmdQuestion1.Enable
d False End Sub
190Private Sub cmdQuestion2_Click() Ans
InputBox("???????????????????????? ?" _
Chr(13) "MsgBox, InputBox", "Question") If
LCase(Ans) "inputbox" Then n n 1
End If cmdQuestion3.Enabled True
cmdQuestion2.Enabled False End Sub
191Private Sub cmdQuestion3_Click() Ans
InputBox("?????????????????????????????
InputBox ???????????????? ?" Chr(13) _
"Integer, String", "Question") If LCase(Ans)
"string" Then n n 1 End If
cmdQuestion3.Enabled False lblResult.Caption
"??????????????? " n " ???" End Sub
192DriveListBox (properties)
???? EditPlus
Event ??????????? Change
193DirListBox (properties)
Event ??????????? Change
194FileListBox (properties)
- Name
- Path
- Filename
- Pattern ???? .exe.xls
Event ??????????? Click
195???????????
???????????? ??? Path ???????
196(No Transcript)
197Timer (properties)
Event ??? Timer
198????????????????????????????????
- Now
- ????????????????????? ? ????????
Time ???????????? ? ????????
199???????????
???????????????? Timer
198
200- Private Sub Timer1_Timer()
- lblTime.Caption Time
- End Sub
201?????? Static
- ???????????????????????????????
- ????????????? (????? Event)
- ??????
- Static Name As Data_Type
202???????????
?????????????????
203- Private Sub cmdCount_Click()
- Static n As Integer
- n n 1
- lblShowNumber.Caption "Count " n
- End Sub
- ' ???????????????? n ??????? Private
204???????????
??????? Password
Dim n As Integer Dim x As Integer
205Private Sub cmdOK_Click() n n 1 If
LCase(txtPassword.Text) dusit" Then
frmCaluculate.Show form ??????????????
Unload Me Else x MsgBox("??????????????"
Chr(13) _ " ??????????????????????????", 5,
"Answer")
206 If n lt 3 And (x 4) Then
txtPassword.Text "" txtPassword.SetFocu
s ElseIf x 2 Then End
Else MsgBox "??????????? 3 ?????", 0,
"Answer" End End If End If End Sub
207???????????
??? Timer ???????? Label ??????????
208???????????
Private Sub cmdStart_Click() If
cmdStart.Caption "?????" Then
Timer1.Enabled True cmdStart.Caption
"????" Else Timer1.Enabled False
cmdStart.Caption "?????" End If End Sub
209Private Sub Timer1_Timer() lblWalk.Left
lblWalk.Left 100 End Sub
210Private Sub Timer1_Timer() lblWalk.Left
lblWalk.Left 100 If lblWalk.Left gt Me.Width
Then lblWalk.Left 0 End If End Sub
211Private Sub cmdDecrease_Click()
Timer1.Interval Timer1.Interval - 50 End Sub
212Private Sub cmdDecrease_Click()
Timer1.Interval Timer1.Interval - 50 If
Timer1.Interval lt 10 Then
cmdDecrease.Enabled False End If End Sub
213Private Sub cmdIncrease_Click()
cmdDecrease.Enabled True Timer1.Interval
Timer1.Interval 50 End Sub
214???????? Label ????????????
Sub Form_Load() fac "b" End Sub
215???????? Label ????????????
Dim fac As String Private Sub Timer1_Timer() If
fac "r" Then lblWalk.Left lblWalk.Left
75 lblWalk.Top lblWalk.Top - 50
If lblWalk.Top lt 0 Then fac "t"
End If
215
216 ElseIf fac "t" Then lblWalk.Left
lblWalk.Left 75 lblWalk.Top lblWalk.Top
50 If lblWalk.Left gt Me.Width - 1000
Then fac "l" End If
217 ElseIf fac "l" Then lblWalk.Left
lblWalk.Left - 50 lblWalk.Top lblWalk.Top
50 If lblwalk.Top gt Me.Height - 1000
Then fac "b" End If
218 ElseIf fac "b" Then lblWalk.Left
lblWalk.Left - 50 lblWalk.Top lblWalk.Top
- 50 If lblWalk.Left lt 0 Then fac
"r" End If End If End Sub
219PictureBox (properties)
- Name
- AutoSize
- BorderStyle
- Picture
???????????????
220ImageBox (properties)
- Name
- BorderStyle
- Picture
- Stretch
??????????????? Form
221Method ??? Picture ??? Image
- LoadPicture(Directory\...\???????????)
???? Image1.Picture LoadPicture("c\cat.jpg")
222???????????
?????????????? ???????????????
223Sub Form_Click() Image2.Picture
Picture1.Picture Picture1.Picture
Image1.Picture Image1.Picture
Image2.Picture End Sub
224???????????
??????????????????????
225(No Transcript)
226Sub File1_Click() txtPath.Text File1.Path
txtFile.Text File1.FileName Image1.Picture
LoadPicture(File1.Path _
"\" File1.FileName) '
?????????? Pattern ???? End Sub
227?????????????? Root Drive A\ ??? C\
Sub File1_Click() txtPath.Text File1.Path
txtFile.Text File1.FileName If File1.Path
"C\" Or File1.Path "a\" Then
Image1.Picture LoadPicture(File1.Path _
File1.FileName) Else Image1.Picture
LoadPicture(File1.Path _
"\" File1.FileName) End If End
Sub
228Line (properties)
- Name
- BorderColor
- BorderStyle
- BorderWidth
229?????????????????????
- line(x1,y1) (x2,y2),Color
???? Line (500, 200)-(2000, 1000), QBColor(11)
230???????????
????????????????
231???????????
Sub frmShowline_Click() Dim i As Integer For i
1 To 4 Line (500, 500 i)-(2000, 500
i) Line (500 i, 500)-(500 i, 2000)
Next i End Sub
232Shape (properties)
- Name
- BackStyle
- BackColor
- BorderColor
- BorderStyle
- BorderWidth
- FillColor
- FillStyle
- Shape
233???????????
Random Shape
234Sub cmdShow_Click() Shape1.Shape (Rnd 5)
Shape1.FillColor QBColor(Rnd 15)
Shape1.FillStyle (Rnd 7)
Shape1.BorderColor QBColor(Rnd 15) End Sub
235???????????????????
???? Circle (1000, 1000), 500
236???????????
?????????
237Sub Timer1_Timer() Dim i As Integer For i 1 To
2000 Step 10 Circle (Me.Width \ 2, Me.Height \
2), i, _ RGB(Rnd 255, Rnd 255, Rnd
255) Next i End Sub
238??????????? Event ??? Mouse
- MouseDown ???????????????????
- MouseUp ??????????????????????
- MouseMove ????????????????
239???????????? Mouse ???????? Shift
- ?????? Button ?????? Shift
- 1 ???????? 1 ?????? Shift ????
- 2 ??????? 2 ?????? Ctrl ????
- 4 ???????? 4 ?????? Alt ????
240????????????????????????????????????????
Private Sub ?????????????_MouseDown( Button As
Integer, _ Shift As Integer, X As Single, Y As
Integer)
Private Sub ?????????????_MouseUp( Button As
Integer, _ Shift As Integer, X As Single, Y As
Integer)
Private Sub ?????????????_MouseMove( Button As
Integer, _ Shift As Integer, X As Single, Y As
Integer)
241???????????
??????????? Label ????????????? Mouse
242Private Sub Form_MouseMove(Button As Integer, _
Shift As Integer, X As Single, Y As
Single) Me.Caption " Value X " X "
Value Y " Y Label1.Move X, Y End Sub
243???????????
????????????? Mouse
244Dim d As Boolean Dim CurrentX as Single,CurrentY
as Single Sub Form_MouseDown(Button As Integer,
_ Shift As Integer, X As Single, Y As Single)
d True CurrentX X CurrentY Y End Sub
245Sub Form_MouseUp(Button As Integer, _ Shift As
Integer, X As Single, Y As Single) d
False End Sub
246Sub Form_MouseMove(Button As Integer, _ Shift As
Integer, X As Single, Y As Single) If d True
Then Line -(X, Y)' Line Form1.CurrentX,Form1.Curr
entY(X,Y) End Sub
247?????????????????????? ??????????????????????
Sub Form_MouseMove(Button As Integer, _ Shift As
Integer, X As Single, Y As Single) If d True
Then If Button 1 Then Line -(X,
Y) Else Circle (X, Y), 100,
QBColor(Rnd 15) End If End If End Sub
248?????????????????????? ????????????????????????
Shift ????????
Sub Form_MouseMove(Button As Integer, _ Shift As
Integer, X As Single, Y As Single) If d True
Then If Button 1 And Shift 1 Then
Circle (X, Y), 100, QBColor(Rnd 15)
Else Line -(X, Y) End If End
If End Sub
249?????? Common Dialog
- ???? Project ? Components
- Microsoft Common Dialog Control 6.0
250Dialog Open
251Dialog Font
252Dialog Color
253???????????
??????????? Dialog
251
254Common Dialog (properties)
- Name
- Action
- DialogTitle
- Filter
- FilterIndex
- Flags
- InitiDir
- CancelError
255Common Dialog (properties) (???)
- FileName
- FontName
- FontSize
- FontBold
- FontItalic
- FontStrikethru
- FontUnderline
- Color
256Common Dialog (Method)
- ShowOpen
- ShowSave
- ShowColor
- ShowPrinter
257?????????????? Filter
- .Filter "All Files (.)."
- .Filter "All Files (.).Text Files
(.txt).txt" - "All Pictures (.bmp.gif.jpg).bmp.gif.jp
g" - FilterIndex 2
258??????????? Dialog Open
- Private Sub cmdShowOpen_Click()
- dlg1.Flags cdlOFNHideReadOnly
- dlg1.Filter "All Files (.).Text Files"
_ - "(.txt).txt"
- dlg1.FilterIndex 2
- dlg1.ShowOpen
- MsgBox dlg1.FileName
- End Sub
259??????????? Dialog Color
- Private Sub cmdShowColor_Click()
- dlg1.Flags cdlCCRGBInit
- dlg1.ShowColor
- Label1.ForeColor dlg1.Color
- End Sub
260??????????? Dialog Font
- Private Sub cmdShowFont_Click()
- dlg1.Flags cdlCFBoth
- dlg1.ShowFont
- lblShow.FontNamedlg1.FontName
- lblShow.FontSizedlg1.FontSize
- lblShow.FontBolddlg1.FontBold
- lblShow.FontItalicdlg1.FontItalic
- End Sub
261- Private Sub cmdExit_Click()
- End
- End Sub
262??????????? Dialog Save
- Private Sub cmdShowSave_Click()
- dlg1.Flags cdlOFNHideReadOnly
- dlg1.Filter "All Files (.).Text Files"
_ - "(.txt).txt"
- dlg1.FilterIndex 2
- dlg1.ShowSave
- MsgBox dlg1.FileName
- End Sub
263??????????? Dialog Print
- Private Sub cmdShowPrinter_Click()
- dlg1.ShowPrinter
- End Sub
264??????????? Dialog Help
- Private Sub cmdShowHelp_Click()
- dlg1.HelpFile _
- "c\windows\help\winhlp32.hlp"
- dlg1.HelpCommand cdlHelpContents
- dlg1.ShowHelp
- End Sub
265MDI Form
Multiple Document Interface
- ????? MDI Form
- Project ? Add MDI Form
- ????? MDI Form
- Open
266???????????
????????? MDI Form
267??????????????????? MDI Form
- ???????? Properties ? MDIChild
- ??????????????? True
268???????????? (Menu)
- Tools ?Menu Editor...
- Caption ????????????????????????
- Name ?????????????
- ???????? ? ??????????????????
- ???????? 6 ?????
269???????????
???????????????
270????????
Caption Name File mnufile Openform1 mnuform1 Op
enform2 mnuform2 - mnuline Exit mnuexit
271???? Font
Caption Name Font mnufont 10 mnu10 12 mnu12 15
mnu15 20 mnu20 Color mnucolor Red mnured Gree
n mnugreen Blue mnublue
272???????????????? Menu
Sub mnuexit_Click() End End Sub
273????? MDI Form ??????? ??????
274???????? ???????????? Form1 ??? Form2
275????????????????????????? 2 ??? 3
276Popup Menu
- Tools ?Menu Editor...
- ?????????????????????????????????
???????????????? ?????? Visible ???
277???????????
????? Popmenu
Caption Name popup mnupopup Cut mnucut Copy m
nucopy Paste mnupaste
VisibleFalse
278?????????????? Popup Menu
???? PopupMenu mnupopup
279??????????? popup menu ?????????????????????
Private Sub Form_MouseDown(Button As Integer, _
Shift As Integer, X As Single, Y As
Single) If Button 2 Then PopupMenu
mnupopup End If End Sub
280??????????? (Procedure)
- Sub (Sub Program)
- Function
281Sub Program
- Sub ??????????????? (parameter)
- Statement
-
- End Sub
282????????? Sub Program
- Private Sub ??????????????? (parameter)
- ?????????????????????? Form ?????
- Public Sub ??????????????? (parameter)
- ?????????????????????????? Form
- Sub ??????????????? (parameter)
- ????????? Public Sub
283??????????? Sub Program
- Call ???????????????(?????????)
????
???????????????(?????????)
284???????????
Sub Program ???????? Parameter
285Sub Color() lblShow.BackColor
RGB(HScroll1.Value, _
HScroll2.Value, HScroll3.Value)
lblShow.ForeColor RGB(255 - HScroll1.Value, _
255 - HScroll2.Value, 255 -
HScroll3.Value) End Sub
286(No Transcript)
287Private Sub HScBlue_Change() Call Color
lblBlue.Caption BLUE " HScBlue.Value End
Sub
288???????????
Sub Program ????? Parameter
289Sub table(r As Integer, c As Integer) Dim i As
Integer For i 1 To r 1 Line (500,
500 i)-(500 (c 1), 500 i) Next i
For i 1 To c 1 Line (500 i,
500)-(500 i, 500 (r 1)) Next i End Sub
290Private Sub cmdTable_Click() Me.Cls Call
table(Val(txtRow.Text), Val(txtCol.Text))
txtRow.Text "" txtCol.Text ""
txtRow.SetFocus End Sub
291Function
- Function ???? function (parameter) As datatype
- Statement
-
- End Function
292??????????? Function
- ?????? ???? Object ???? Function(??????
Parameter)
293???????????
???????? Factorial
294Function Fac(n As Integer) As Long If n 1
Then Fac 1 Else Fac n
Fac(n - 1) End If End Function
295Private Sub cmdFac_Click() Dim data As Long
data Fac(Val(txtNumber.Text))
lblResult.Caption txtNumber.Text " ! "
data txtNumber.Text ""
txtNumber.SetFocus End Sub
296??????????????? Array
- Dim ??????????(UpperBound) As Type
???? Dim Cost(5) As Integer Cost(0) 20
Cost(5) val(Text1.Text)
297??????????????? Array
- Dim ??????????(LBound To UBound) As Type
???? Dim Score(1 To 4) As Integer Dim Name(97
To 100) As String
298Object ??? Array
- ????????????? Object ??? Array ??????????????
Object
299???????????
????????????????? Array
300Private Sub cmdAverage_Click() Dim n(2) As
Integer Dim i As Integer Dim sum As Integer
sum 0 For i 0 To 2 n(i)
Val(txtNum(i).Text) sum sum n(i)
Next i lblResult.Caption "Average " sum
/ 3 End Sub
301????????????????????
299
302Data Control (properties)
- Name
- Caption
- Connect
- DatabaseName
- RecordSource
303Method ??? Record Set
- AddNew
- Update
- CancelUpdate
304Method ??? Record Set
- MoveFirst
- MoveLast
- MoveNext
- MovePrevious
- FindFirst
- FindLast
- FindNext
- FindPrevious
305??????????? Object ????????????????????????
- ??????????????
- DataSource
- DataField
306???????????????????????? Data Control
????????????????????????? ?? ReccordSet
- MoveFirst ????????????????????
- MoveLast ????????????????????????
- MoveNext ??????????????????????
- MovePrevious ?????????????????????????
- Move ????????????????????????
307???????????????????????? Data Control
???????????????? ReccordSet
- FindFirst ?????????????????????????????????
- FindLast ?????????????????????????????????????
- FindNext ???????????????????????????????????
- FindPrevious ?????????????????????????????????????
?
308???????????
??????????????????????????????????
Data1 ????? DatabaseName ??? RecordSource Text
????? DataSource ??? DataField
309Private Sub cmdAdd_Click() ' ???? Add
Data1.Recordset.AddNew txtId.SetFocus
cmdOK.Visible True cmdADD.Visible
False End Sub
310Private Sub cmdOK_Click() '???? OK
Data1.Recordset.Update cmdADD.Visible True
cmdOK.Visible False End Sub
???????????????? ???? OK ???????? Add
311Private Sub cmdDelete_Click() '???? Delete X
MsgBox("Delete " Text2.Text _ " Yes or No
?", 1, "Check Data") If X 1 Then
Data1.Recordset.Delete Data1.Recordset.MoveFirs
t End If End Sub
312Private Sub cmdFind_Click() '???? Find Dim str As
String str "id'" txtEnID.Text "'"
Data1.Recordset.FindFirst str If
Data1.Recordset.NoMatch Then MsgBox "Data
Not Found" End If txtEnID.Text ""
txtEnID.SetFocus End Sub
313(No Transcript)
314 ' ???????????????????????? Database Private Sub
Form_Load() cmbPosition.AddItem "Manager"
cmbPosition.AddItem "Saleman"
cmbPosition.AddItem Reception" End Sub
315Dim t As String Private Sub cmdFind1_Click()
'???? Find If optName.Value True Then
t "name'" txtFindName.Text "'" ElseIf
optSex.Value True Then If optMale.Value
True Then t "sex'f " Else
t "sex'm " End If
316??????? Find
ElseIf optPosition.Value True Then t
"position'" cmbPostion.Text "'" End If
Data1.Recordset.FindFirst t If
Data1.Recordset.NoMatch Then MsgBox "Data
Not Found", 16 End If End Sub
317Private Sub cmdFindNext_Click() '???? FindNext
Data1.Recordset.FindNext t If
Data1.Recordset.NoMatch Then MsgBox "End of
Data", 32 End If End Sub
318???????????
???? user name ??? password ??????????????
Database ??????? admin ??? password dusit
????????? Database ?????? ??????? user ???
password sitd ????????? Database ???????
319Private Sub cmdOK_Click() If txtUser.Text
"admin" And txtPass.Text dusit" Then
Form35.Visible True Form36.Visible
False ElseIf txtUser.Text "user" And
txtPass.Text "masi" Then Form35.Visible
True Form35.Command1.Visible False
Form35.Command3.Visible False
Form36.Visible False
320Else MsgBox "Password or User name not
Correct", 16 txtUser.SetFocus
txtUser.SelStart 0 txtUser.SelLength
Len(Text1.Text) txtPass.Text "" End
If End Sub
Sub cmdCancel_Click() End End Sub
321?????????
319