Visual Basic 6.0

324
Visual Basic 6.0 1

description

Visual Basic 6.0. Check box. ใช้กับการเลือกแบบ ถูก/ผิด ( True/False, Yes/No). Combo box. เป็นตัว control เป็นการผสมระหว่าง Text box กับ List box ซึ่งจะปรากฏรายการ เมื่อมีการคลิกลูกศร และ Combo box ไม่สนับสนุนการเลือกแบบหลายค่า. Command button. - PowerPoint PPT Presentation

Transcript of Visual Basic 6.0

Visual Basic 6.0

Visual Basic 6.0

112

Check box / ( True/False, Yes/No)Combo box control Text box List box Combo box Command button control Click event procedure control Data control Visual Basic control table Data Database Jet ActiveX Data Object (ADO) 3

Directory List box List box Drive List box Combo box File list box List box Frame container control Horizontal Vertical Scroll Bar stand-alone control Image control Picture box container Image Picture box4

Label control Line control

List box control MultiSelectOLE container control Host window Microsoft Excel window Visual Basic5

Visual Basic Project 1. File >> New Project2. Standard EXE 3. Open

56 Form

67 Project Explorer1. 2. Remove Form (n)

78

89

PropertiesLabelNameCaptionlbl_nameLabelNameCaptionlbl_surnameText NameTexttxt_nameText NameTexttxt_surnameCommand buttonNameCaptioncmd_okFormNameCaptionFrm_login910 (Code)

Private Sub cmd_ok_Click()MsgBox " " & Text1.Text & " " & Text2.Text, vbOKOnly, " "End Sub Project2 Form1 101111121213131414

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

1616 Visual Basic Title Bar Menu Bar Tool Bar Form WindowsView Object

1717 Visual Basic Project ExplorerView Project Explorer Properties View Properties Window 1818 Visual Basic Form Layout View Form Layout Window ToolboxView Toolbox1919Application2020 Application File New Project Standard EXE OK2121 Application Form ProjectFile Save Form Project project Save2222 Form Project Add Form Toolbar Form

2323 Form Project Add File Open2424 Form Project Remove Form2525 Run ApplicationRun Start F5 Toolbar

2626 Stop ApplicationRun End Toolbar

2727 Project Project Properties General Startup Object2828 VB6

2929 VB6 Properties Windows Object List Box: Properties List: Description Pane: Code 3030 VB6 Code Event Code Editor Object Event Private Sub_ End Sub3131 Properties Object_Name.Properties_Name = properties Form1.Caption = " Form1.FontSize = 203232Properties ControlNameCaptionForeColorBackColorHeight, WidthLeft ,TopTabIndexEnabledVisibleFontBold,FontItalicFontName,FontSizeFontUnderlineMousePointer30 Form3434Properties FormNameBackColorForeColorCaptionEnabledFontIconMinButtonMaxButtonHeightWidthAutoRedraw3235Properties FormMousePointerMouseIcon ( MousePointer=Custom )PictureVisibleCurrentXCurrentY3336Method FormPrint "" & Form_Name.HideForm_Name.ShowForm_Name.Cls3737 Method Object_Name.Method_Name [ Method]Form1.Print "Siam Computer"Me.Show3838Event FormActivate Activate ClickDblClickLoadUnLoad3939Sub Form_Activate( )Form1.FontSize=20Print Test Visual Basic Print Siam ComputerEnd Sub4040Sub Form_Activate( )Form1.Font.Size=20Print Test Visual Basic ;Print Siam ComputerCurrentX = 1500CurrentY = 1000Print New PositionEnd Sub ( )

( ; )4141 2 Form NameForm1

AutoRedrawTrue

CommandButton NameCommand1

CaptionClear4242 2Sub Form_Activate() Form1.Print Form_Activate End SubSub Form_Click() Form1.Print Form_Click End SubSub Command1_Click() Form1.ClsEnd SubSub Form_DblClick() Form1.Print Double_Click End SubSub Form_Resize() Form1.Print Form_ResizeEnd Sub

4343Object Operator4444Label (properties)NameAlignmentAutoSizeBorderStyleBackStyleCaptionLeftTop4245Text Box (properties)NameTextMaxLenghtPasswordCharMultilineScrollBarsTabIndex 0TabStopToolTipText4646MethodObject_Name.SetFocus cursor focus ObjectText1.SetfocusCommand1. Setfocus4747Properties..SelStartSelLength

4848Event Change TextGotFocus Text FocusLostFocus Text Focus4949Command Button (properties)NameCaptionDefaultPictureStyle5050 2 Text Box

5151Sub cmdMultiply_Click() a = txtnum1.Text b = txtnum2.Text lblResult.Caption = a & " * " & b & " = " & a * bEnd Sub

Source Code5252Operator & + ' Comment5353 Font View Code Code Tools Option Editor Format Font Font UPC DSE BrowalliaUPC5454 Tools Option Editor Require Variable Declaration Option Explicit View Code5555Dim variable_name As Data_Type Const const_name = Value Dim data1 As IntegerConst name = Somjate5656 255 , _ Dim 5757Byte 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)5858 ()Single (4 Byte) -3.402823x1038 -1.401298x10-45 1.401298x10-45 3.402823x1038Double (8 Byte)1.79769313486232x10308 4.94065645841247x10-324 4.94065645841247 x10-324 1.79769313486232x103085959 ()Date (8 Byte)String Boolean (2 Byte)Variant (22 Byte)6060Operator + - * / \ Mod ^ 6161 Operator

6262Private Sub Command1_Click()Dim a As IntegerDim b As Integera = Text1.Textb = Text2.TextLabel3.Caption = a & " / " & b & " = " & a / bLabel4.Caption = a & " \ " & b & " = " & a \ bLabel5.Caption = a & " mod " & b & " = " & a Mod bLabel6.Caption = a & " ^ " & b & " = " & a ^ bEnd Sub6363 (Scope of variable) (Local) (Global)Private Form Public 6464Operator = >> =6565 Operator

6666Private Sub cmdCompare_Click()Dim a As StringDim b As Stringa = txtNumber1.Textb = txtNumber2.TextlblNum1.Caption = a & " > " & b & " = " & (a > b)lblNum2.Caption = a & " < " & b & " = " & (a < b)lblNum3.Caption = a & " = " & b & " = " & (a = b)lblNum4.Caption = a & " " & b & " = " & (a b)End Sub6767Operator

6868ArithmeticComparisonLogicalExponentiation (^)Equality (=)NotNegation (-)Inequality ()AndMultiplication and division (*, /)Less than ()XorModulus arithmetic (Mod)Less than or equal to (=)ImpString concatenation (&)Is&6669Round(number) Int(number) 7070Rnd[(Number)] Rnd 0-9Label1.Caption = Int(Rnd * 9)(Randomize )7171Sqr(number) Abs(number) 7272InStr([Start],String1,String2,[Compare]) StringReplace(String1,Find, Replace) String 7373UCase(String) String LCase(String) String 7474

7575Private Sub txtTEXT1_Change() txtText2.Text = UCase(txtTEXT1.Text) txtText3.Text = LCase(txtTEXT1.Text)End SubPrivate Sub cmdClear_Click() txtTEXT1.Text = "" txtTEXT1.SetFocusEnd Sub7676Str(Numeric) Numeric String Val(String) String Numeric 7777IsNumeric(String) Numeric IsDate(String) Date 7878LTrim(String) String RTrim(String) String 7979Trim(String) StringFormat(value , "") 8080 (Date)"dd/mm/yy" "Short Date""dd/mmm/yyyy" "Medium Date""dd/mmmm/yyyy" "Long Date" 8181Now Time 8282 (Time)"HH:MM" "Short Time""HH:MM AMPM" "Medium Time""HH:MM:SS" "Long Time" 8383

8484Dim a As DateDim b As DateSub Command1_Click() a = Time Text1.Text = Format(a, "HH:MM:SS")Text2.Text =""Label1.Caption =""End Sub8585Sub Command2_Click() b = Time Text2.Text = Format(b, "HH:MM:SS")End SubSub Command3_Click() Label1.Caption = Format(b - a, "HH:MM:SS")End Sub8686IfThenElse StatementIf ThenStatementElseStatementEnd If8787Flow-ChartconditionStatement ;Statement ;TrueFalse88IfThenStatementIf Then Statement8989IfThenElse StatementIf ThenStatementElseStatementEnd IfIf ThenStatementElseif ThenStatementElseif ThenStatementElseStatementEnd if9090 ElseIfDim Number, Digits, MyString Number = Text1.Text If Number < 10 Then Digits = 1 ElseIf Number < 100 Then Digits = 2 Else Digits = 3 End If 9191Unload StatementUnload ObjectNamePrivate Command1_Click()Unload Form1 'Unload Me End Sub9292End CommandEndPrivate Command1_Click()End ' End Sub9393

Private Sub cmdOK_Click() If txtPass.Text = "basic" Then frmCalculate.Show Unload Me Else txtPass.Text = "" txtPass.SetFocus End IfEnd SubLcase(Text1.text)9494

9595Private Sub Command1_Click() If Text1.Text = "basic" Then Form1.Show Unload Me Else Text1.Text = "" Text1.SetFocus End IfEnd SubPrivate Sub Command2_Click() EndEnd SubLcase(Text1.text)9696Select Case StatementSelect Case Case 1 1statement:Case 2 2statement:Case Elsestatement:End Select9797Flow-Chartconditionvalue1value2value n elseS ;Statement ;S ;Statement ;98

9999Private Sub CmdGrade_Click()Dim score As IntegerDim grade As String score = Val(txtmark.Text) 100100Select Case score Case Is >= 80: grade = "A" Case Is >= 70: grade = "B" Case Is >= 60: grade = "C" Case Is >= 50: grade = "D" Case Else: grade = "F" End Select lblgrade.Caption = txtName.Text & " your grade is " & gradeEnd Sub101101Check Box (properties)NameAlignmentCaptionValue 0 (Unchecked) 1 (Checked) 2 (Grayed)

102102

Check Box103103Private Sub chkTime_Click() If chkTime.Value = 1 Then lbltime.Caption = Format(Now, "HH:MM:SS") Else lbltime.Caption = "" End IfEnd Sub104104Private Sub Chkdate_Click() If chkDate.Value = 1 Then lblDate.Caption = Format(Now,"dd/mmmm/yyyy") Else lblDate.Caption = "" End IfEnd Sub105105Option Button (properties)NameAlignmentCaptionValue True (Select)False (Not Select)

106106 Option Button

107107Private Sub Optmale_Click() lblgender.Caption = "Male"End SubPrivate Sub Optfemale_Click() lblgender.Caption = "Female"End Sub108108

109109Private Sub OptRectangle_Click()txtnumber1.Text = ""txtNumber2.Text = ""lblResult.Caption = ""txtNumber1.SetFocuslblName1.Caption = ""lblName2.Caption = ""lblName3.Caption = ""End Sub110110Private Sub OptTriangle_Click()txtNumber1.Text = ""txtNumber2.Text = ""lblResult.Caption = ""txtNumber1.SetFocuslblName1.Caption = ""lblName2.Caption = ""lblName3.Caption = ""End Sub111111Private 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 IfEnd Sub112112Frame (properties)NameCaption

113113

114114..115115Private 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 Then116116 If Optedu1.Value = True Then lblCareer.Caption = "" ElseIf Optedu2.Value = True Then lblCareer.Caption = "" ElseIf Optedu3.Value = True Then lblCareer.Caption = "" End IfEnd IfEnd Sub117117Function MsgBoxMsgBox Prompt [,Buttons] [,Title]Prompt Buttons Title Box118118 Message Box

IconTitleButtons119 (Icon)

vbCriticalvbInformationvbExclamationvbQuestion

117Function MsgBox

= MsgBox(Prompt [,Buttons] [,Title])121121 Msgbox

122HScrollBar VScrollBar (properties)Name

MinMaxLargeChangeSmallChangeScroll Box Value SmallChange LargeChange Min Max123123EventChange LargeChange SmallChangeScroll Scroll Box124124 Properties Scrollbar

PropertiesMin = 0Max = 100LargeChange = 10SmallChange = 2125125Sub HScroll1_Change() lblInfo.Caption = "Value = " & HScroll1.ValueEnd SubSub HScroll1_Scroll() lblInfo.Caption = "Value = " & HScroll1.ValueEnd Sub126126Object_Name.Properties = Color_NamelblName.ForeColor = VbRedfrmData.BackColor = VbGreen127127

128128

129129

130130Dim data As StringPrivate Sub Form_Load() 'Width = 4125 Height = 1440End Sub131131Private Sub cmdFont_Click() data = txtName.Text lblName.Caption = data 'Width = 4125 Height = 4080End Sub132132Private Sub chklowercase_Click()If chklowercase.Value = 1 Then chkuppercase.Value = 0 lblName.Caption = LCase(data)Else lblName.Caption = dataEnd IfEnd Sub133133Private Sub chkuppercase_Click()If chkuppercase.Value = 1 Then chklowercase.Value = 0 lblName.Caption = UCase(data)Else lblName.Caption = dataEnd IfEnd Sub134134Private Sub chkItalic_Click() If chkitalic.Value = 1 Then lblName.Font.Italic = True Else lblName.Font.Italic = False End IfEnd Sub135135Private Sub chkBold_Click() If chkbold.Value = 1 Then lblName.Font.Bold = True Else lblName.Font.Bold = False End IfEnd Sub136136Private Sub HScsize_Change() lblName.Font.Size = HScsize.ValueEnd Sub

Private Sub Command3_Click() 'Width = 4125 Height = 1440End Sub137137Private Sub optRed_Click() lblName.ForeColor = vbRedEnd SubPrivate Sub optBlue_Click() lblName.ForeColor = vbBlueEnd Sub138138Private 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.ForeColorEnd Sub139139QBColor(n) n 0 - 15 Label1.BackColor = QBColor(1)140140RGB(Red,Green,Blue) 0 - 255 Label1.BackColor = RGB(0,0,255) Label1.ForeColor = RGB(255,0,255)141141 Scroll Bars

142142Private Sub Form_Load() lblRed.Caption = "Red = " & HScRed.Value lblGreen.Caption = "Green = " & HScGreen.Value lblBlue.Caption = "Blue = " & HScBlue.Value lblShow.BackColor=RGB(0,0,0) lblshow.ForeColor=RGB(255,255,255)End Sub143143Private Sub HScRed_Change() lblShow.BackColor = RGB(HScRed.Value, _ HScGreen.Value, HScBlueValue) lblShow.ForeColor = RGB(255 - HScRed.Value, _ 255 - HScGreen.Value, 255 - HScBlue.Value) lblRed.Caption = "Red = " & HScRed.ValueEnd Sub Scroll144144Private 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.ValueEnd Sub145145Private 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.ValueEnd Sub146146LOOP147ForNext StatementFor = To [ Step / ]statementstatementNext 148148 ForNext StatementFor I = 0 To 100 Step 2statementstatementNext I149149Flow-Chartfor loopStatement ;..end150Private Sub Form_Click() Dim i As Integer For i = 1 To 20 Print i ; Next iEnd Sub 1 20151151DoLoop StatementDo while ()Statement:LoopDo Until () Statement :Loop152152DoLoop Statement ()Do Statement:Loop while ()

Do Statement :Loop Until () 153153Flow-Chart (Do While)conditionTrueFalseStatement ;Statement ;....end154Flow-Chart (DoUntil)Statement ;..conditionFalseTrue155 1 20Private Sub Form_Click() Dim i As Integer i = 1 Do While (i 20)End Sub152156 10 1Private Sub Form_Click() Dim i As Integer i = 10 Do While (i >= 1) Print i i = i - 1 LoopEnd SubPrivate Sub Form_Click()Dim i As Integer i = 10 Do Print i i = i - 1 Loop Until (i = 0)End Sub157157WhileWend StatementWhile () statements:Wend158158 10 1Private Sub Form_Click()Dim i As Integer i = 10 While i > 0 Print i i = i - 1 WendEnd Sub159159List Box (properties)NameColumnsListListIndexTextListCountSortedStyle Standard Checkbox156160 List Box

161161MethodList1.AddItem , indexList1.RemoveItem indexList1.Clear162162With End With StatementWith Object_Name.Properties = Value.Method End With163Goto StatementGoto labelStatement label :StatementSub Command1_Click()GoTo aa Label1.Caption = VB"aa: Label1.Caption = "SiamEnd Sub164164On Error GotoOn Error Goto labelStatement label :Statement165165On Error Resume NextOn Error Resume NextStatementStatement166166Resume : Error Resume Next : Error 167Error Object Object Run TimeErr.Properties168168PropertiesNumberDescription

169169OnGoto & OnGoSubOn expression GoSub destinationlistOn expression GoTo destinationlist170170Private Sub Command1_Click()Dim n As Integer n = 1 On n GoTo a, bExit Sub a: Print "1" Exit Sub b: Print "2" Exit SubEnd Sub171171 List

Sorted = True172172Private Sub Form_Load() lstPrg.AddItem "Widows" lstPrg.AddItem "Word" lstPrg.AddItem "Excel" lstPrg.AddItem "Access" lstPrg.AddItem "Power Point"End Sub173173Private Sub lstPrg_DblClick() lstShow.AddItem lstPrg.Text lstPrg..RemoveItem lstPrg..ListIndexEnd SubPrivate Sub lstShow_DblClick() lstPrg.AddItem lstShow.Text lstShow.RemoveItem lstShow.ListIndexEnd Sub175175 List

176176Private Sub cmdADD_Click() If Trim(txtData.Text) "" Then lstInfo.AddItem txtData.Text End If txtData.Text = "" txtData.SetFocusEnd Sub177177Private Sub cmdRemove_Click() If lstInfo.ListIndex >= 0 Then lstInfo.RemoveItem lstInfo.ListIndex lstInfo.ListIndex =0 End IfEnd SubPrivate Sub cmdClear_Click() lstInfo.Clear ' End Sub178178 List 2 List

MultiSelect=Extended179179Private Sub Form_Load() List1.AddItem "Pascal" List1.AddItem "Basic" List1.AddItem "C++" List1.AddItem "Delphi" List1.AddItem "Visual Basic" List1.AddItem "Visual C++"End Sub180180Sub cmdMove_Click()Dim i As IntegerDim n As Integer n = List1.ListCount i = 0 Do While (i < n) If List1.Selected(i) ThenList2.AddItem (List1.List(i))List1.RemoveItem (i)n = List1.ListCount Else i = i + 1 End If LoopEnd Sub181181Private Sub cmdMoveall_Click()Dim i As Integer For i = 0 To List1.ListCount - 1 List2.AddItem List1.List(i) Next i List1.ClearEnd Sub182182Combo Box (properties)NameStyleDropdown ComboSimple ComboDropdown List List Box183183

Combo184184

185185Private Sub Form_Load() cmbColor.AddItem "Blue"cmbColor.AddItem "Green"cmbColor.AddItem Magenta"cmbColor.AddItem "Red" cmbColor.AddItem "Yellow"End Sub186186Private 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 SelectEnd Sub187187Function InputBox = InputBox(Prompt [,Title] [,Default])Prompt : Title : BoxDefault : 188188 InputBox

TitlePrompt189

Question 190190Dim n As IntegerDim Ans As String

Private Sub Form_Load() n = 0End Sub191191Private Sub cmdQuestion1_Click() Ans = InputBox(" ?" & Chr(13) & _ "VB, Delphi", "Question") If LCase(Ans) = "vb" Then n = n + 1 End If cmdQuestion2.Enabled = True cmdQuestion1.Enabled = FalseEnd Sub192192Private 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 = FalseEnd Sub193193Private 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 Sub194194DriveListBox (properties)NameDriveEvent Change EditPlus195195DirListBox (properties)NamePathEvent Change196196FileListBox (properties)NamePathFilenamePattern *.exe;*.xls Event Click197197 Path

198198Sub File1_Click() txtPath.Text = File1.Path txtFilename.Text = File1.FileNameEnd SubSub Drive1_Change() Dir1.Path = Drive1.DriveEnd SubSub Dir1_Change() File1.Path = Dir1.PathEnd Sub199199Timer (properties)NameEnabledIntervalEvent Timer200200Now Time 201201

Timer

198Private Sub Timer1_Timer() lblTime.Caption = TimeEnd Sub203 Static ( Event)Static Name As Data_Type204

205Private Sub cmdCount_Click() Static n As Integer n = n + 1 lblShowNumber.Caption = "Count = " & nEnd Sub' n Private206

PasswordDim n As IntegerDim x As Integer207207Private Sub cmdOK_Click() n = n + 1 If LCase(txtPassword.Text) = dusit" Then frmCaluculate.Show form Unload MeElse x = MsgBox("" & Chr(13) & _ " ", 5, "Answer")208208 If n < 3 And (x = 4) Then txtPassword.Text = "" txtPassword.SetFocus ElseIf x = 2 Then End Else MsgBox " 3 ", 0, "Answer" End End IfEnd IfEnd Sub209209

Timer Enabled = False Interval = 510 Timer Label 210210Private Sub cmdStart_Click() If cmdStart.Caption = "" Then Timer1.Enabled = True cmdStart.Caption = "" Else Timer1.Enabled = False cmdStart.Caption = "" End IfEnd Sub211211Private Sub Timer1_Timer() lblWalk.Left = lblWalk.Left + 100End Sub212212Private Sub Timer1_Timer() lblWalk.Left = lblWalk.Left + 100 If lblWalk.Left >= Me.Width Then lblWalk.Left = 0 End IfEnd Sub213Private Sub cmdDecrease_Click() Timer1.Interval = Timer1.Interval - 50End Sub214214Private Sub cmdDecrease_Click() Timer1.Interval = Timer1.Interval - 50 If Timer1.Interval = Me.Width - 1000 Then fac = "l" End If219219 ElseIf fac = "l" Then lblWalk.Left = lblWalk.Left - 50 lblWalk.Top = lblWalk.Top + 50 If lblwalk.Top >= Me.Height - 1000 Then fac = "b" End If220220 ElseIf fac = "b" Then lblWalk.Left = lblWalk.Left - 50 lblWalk.Top = lblWalk.Top - 50 If lblWalk.Left < 0 Then fac = "r" End IfEnd IfEnd Sub221221PictureBox (properties)NameAutoSizeBorderStylePicture222222ImageBox (properties)NameBorderStylePictureStretch Form223223Method Picture ImageLoadPicture(Directory\...\) Image1.Picture =LoadPicture("c:\cat.jpg")224224

225225Sub Form_Click() Image2.Picture = Picture1.Picture Picture1.Picture = Image1.Picture Image1.Picture = Image2.PictureEnd Sub226226

227227Sub Dir1_Change() File1.Path = Dir1.PathEnd SubSub Drive1_Change() Dir1.Path = Drive1.DriveEnd Sub228228Sub File1_Click() txtPath.Text = File1.Path txtFile.Text = File1.FileName Image1.Picture = LoadPicture(File1.Path & _ "\" & File1.FileName) ' Pattern End Sub229229 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 IfEnd Sub230230Line (properties)NameBorderColorBorderStyleBorderWidthX1X2Y1Y2231231line(x1,y1) (x2,y2),ColorLine (500, 200)-(2000, 1000), QBColor(11)232232

233233Sub 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 iEnd Sub234234Shape (properties)NameBackStyleBackColorBorderColorBorderStyleBorderWidthFillColorFillStyleShape235235Random Shape

236236Sub cmdShow_Click() Shape1.Shape = (Rnd * 5) Shape1.FillColor = QBColor(Rnd * 15) Shape1.FillStyle = (Rnd * 7) Shape1.BorderColor = QBColor(Rnd * 15)End Sub237237Circle(x,y),radius,colorCircle (1000, 1000), 500238238

239239Sub Timer1_Timer()Dim i As IntegerFor i = 1 To 2000 Step 10 Circle (Me.Width \ 2, Me.Height \ 2), i, _ RGB(Rnd * 255, Rnd * 255, Rnd * 255)Next iEnd Sub240240 Event MouseMouseDownMouseUpMouseMove241241 Mouse Shift Button Shift 11 Shift 22 Ctrl 44 Alt 242242Private Sub _MouseDown( 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)Private Sub _MouseUp( Button As Integer, _Shift As Integer, X As Single, Y As Integer)243243 Label Mouse

244244Private Sub Form_MouseMove(Button As Integer, _ Shift As Integer, X As Single, Y As Single)Me.Caption = " Value X = " & X & " Value Y = " & YLabel1.Move X, YEnd Sub245245

Mouse246246Dim d As BooleanDim CurrentX as Single,CurrentY as SingleSub Form_MouseDown(Button As Integer, _ Shift As Integer, X As Single, Y As Single) d = True CurrentX = X CurrentY = YEnd Sub247247Sub Form_MouseUp(Button As Integer, _ Shift As Integer, X As Single, Y As Single) d = FalseEnd Sub248248Sub 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.CurrentY(X,Y)End Sub249249Sub 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 IfEnd Sub 250250Sub 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 IfEnd Sub Shift 251251 Common Dialog Project ComponentsMicrosoft Common Dialog Control 6.0

252Dialog Open

253Dialog Font

254Dialog Color

255 Dialog

251Common Dialog (properties)NameActionDialogTitleFilterFilterIndexFlagsInitiDirCancelError257257Common Dialog (properties) ()FileNameFontNameFontSize FontBold FontItalicFontStrikethruFontUnderlineColor258258Common Dialog (Method)ShowOpenShowSaveShowColorShowPrinterShowFontShowHelp259259 Filter.Filter= "All Files (*.*)|*.*"

.Filter= "All Files (*.*)|*.*|Text Files (*.txt)|*.txt"

"All Pictures (*.bmp;*.gif;*.jpg)|*.bmp;*.gif;*.jpg"

FilterIndex = 2260Private Sub cmdShowOpen_Click()dlg1.Flags = cdlOFNHideReadOnly dlg1.Filter = "All Files (*.*)|*.*|Text Files" & _ "(*.txt)|*.txt" dlg1.FilterIndex = 2 dlg1.ShowOpen MsgBox dlg1.FileName End Sub Dialog Open261Private Sub cmdShowColor_Click()dlg1.Flags = cdlCCRGBInitdlg1.ShowColor Label1.ForeColor = dlg1.ColorEnd Sub Dialog Color262Private Sub cmdShowFont_Click()dlg1.Flags = cdlCFBothdlg1.ShowFontlblShow.FontName=dlg1.FontNamelblShow.FontSize=dlg1.FontSizelblShow.FontBold=dlg1.FontBoldlblShow.FontItalic=dlg1.FontItalicEnd Sub Dialog Font263Private Sub cmdExit_Click()EndEnd Sub

264Private Sub cmdShowSave_Click()dlg1.Flags = cdlOFNHideReadOnly dlg1.Filter = "All Files (*.*)|*.*|Text Files" & _ "(*.txt)|*.txt" dlg1.FilterIndex = 2 dlg1.ShowSave MsgBox dlg1.FileName End Sub Dialog Save265Private Sub cmdShowPrinter_Click() dlg1.ShowPrinterEnd Sub Dialog Print266Private Sub cmdShowHelp_Click()dlg1.HelpFile = _ "c:\windows\help\winhlp32.hlp"dlg1.HelpCommand =cdlHelpContentsdlg1.ShowHelp End Sub Dialog Help267MDI Form MDI FormProject Add MDI Form MDI FormOpenMultiple Document Interface268268 MDI Form

MDI FormMDI Child Form269269 MDI Form Properties MDIChild True270270 (Menu)Tools Menu Editor...Caption : Name : : ** 6

271271

272272

CaptionName&FilemnufileOpenform1mnuform1Openform2mnuform2 - mnulineExitmnuexit273273 FontCaptionName&Fontmnufont10mnu1012mnu1215mnu15 20mnu20ColormnucolorRedmnuredGreenmnugreenBluemnublue

274274 MenuSub mnuform1_Click() Form1.ShowEnd Sub

Sub mnuform2_Click() Form2.ShowEnd SubSub mnuexit_Click() EndEnd Sub275275 MDI Form

276276 Form1 Form2

277277Sub mnuform1_Click() Form1.ShowEnd Sub

Sub mnuform2_Click() Form2.ShowEnd SubSub mnuform3_Click() Form3.ShowEnd Sub

Sub mnuexit_Click() EndEnd Sub 2 3278278Popup MenuTools Menu Editor... Visible 279279 Popmenu

CaptionNamepopupmnupopupCutmnucutCopymnucopyPastemnupasteVisible=False280280 Popup MenuPopupmenu PopupMenu_Name PopupMenu mnupopup281281 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 IfEnd Sub282282 (Procedure)Sub (Sub Program)Function283283Sub ProgramSub (parameter)Statement:End Sub284284 Sub ProgramPrivate Sub (parameter) Form Public Sub (parameter) FormSub (parameter) Public Sub285285 Sub ProgramCall ()()286286Sub Program Parameter

287287Sub Color() lblShow.BackColor = RGB(HScroll1.Value, _ HScroll2.Value, HScroll3.Value) lblShow.ForeColor = RGB(255 - HScroll1.Value, _ 255 - HScroll2.Value, 255 - HScroll3.Value)End Sub288288Private Sub HScRed_Change() Call Color lblRed.Caption = "Red = " & HScRed.ValueEnd SubPrivate Sub HScGreen_Change() Call Color lblGreen.Caption = "Green = " & HScGreen.ValueEnd Sub289289Private Sub HScBlue_Change() Call Color lblBlue.Caption = BLUE = " & HScBlue.ValueEnd Sub290290Sub Program Parameter

291291Sub 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 iEnd Sub292292Private Sub cmdTable_Click() Me.Cls Call table(Val(txtRow.Text), Val(txtCol.Text)) txtRow.Text = "" txtCol.Text = "" txtRow.SetFocusEnd Sub293293FunctionFunction function (parameter) As datatypeStatement:End Function294294 Function Object = Function( Parameter)295295 Factorial

296296Function Fac(n As Integer) As Long If n = 1 Then Fac = 1 Else Fac = n * Fac(n - 1) End IfEnd Function297297Private Sub cmdFac_Click() Dim data As Long data = Fac(Val(txtNumber.Text)) lblResult.Caption = txtNumber.Text & " != " & data txtNumber.Text = "" txtNumber.SetFocusEnd Sub298298 ArrayDim (UpperBound) As TypeDim Cost(5) As Integer Cost(0) = 20 Cost(5) = val(Text1.Text)299299 ArrayDim (LBound To UBound) As TypeDim Score(1 To 4) As IntegerDim Name(97 To 100) As String 300300Object Array Object Array Object301301 Array

Text1 2 302302Private Sub cmdAverage_Click()Dim n(2) As IntegerDim i As IntegerDim 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 / 3End Sub303303299Data Control (properties)NameCaptionConnectDatabaseNameRecordSource305305Method Record SetAddNewUpdateCancelUpdateDeleteRefresh306306Method Record SetMoveFirstMoveLastMoveNextMovePreviousFindFirstFindLastFindNext FindPrevious307307 Object DataSourceDataField308308 Data ControlMoveFirstMoveLastMoveNextMovePreviousMove ReccordSet309309 Data ControlFindFirst FindLast FindNext FindPrevious ReccordSet310310Data1 DatabaseName RecordSourceText DataSource DataField

311311Private Sub cmdAdd_Click() ' Add Data1.Recordset.AddNew txtId.SetFocus cmdOK.Visible = True cmdADD.Visible = FalseEnd Sub312312Private Sub cmdOK_Click() ' OK Data1.Recordset.Update cmdADD.Visible = True cmdOK.Visible = FalseEnd Sub OK Add313313Private Sub cmdDelete_Click() ' Delete X = MsgBox("Delete " & Text2.Text & _ " Yes or No ?", 1, "Check Data") If X = 1 Then Data1.Recordset.Delete Data1.Recordset.MoveFirst End IfEnd Sub314314Private Sub cmdFind_Click() ' FindDim 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.SetFocusEnd Sub315315

316316 ' DatabasePrivate Sub Form_Load() cmbPosition.AddItem "Manager" cmbPosition.AddItem "Saleman" cmbPosition.AddItem Reception"End Sub317317Dim t As StringPrivate 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 If318318ElseIf 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 IfEnd Sub Find319319Private Sub cmdFindNext_Click() ' FindNext Data1.Recordset.FindNext t If Data1.Recordset.NoMatch Then MsgBox "End of Data", 32 End IfEnd Sub320320

user name password Database admin password = dusit Database user password = sitd Database 321321Private 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 = False322322Else MsgBox "Password or User name not Correct", 16 txtUser.SetFocus txtUser.SelStart = 0 txtUser.SelLength = Len(Text1.Text) txtPass.Text = ""End IfEnd SubSub cmdCancel_Click()EndEnd Sub323323 319