Visual Basic 6
Visual Basic 6
0 Programming
Course Information
Course objectives:
Understand basic theories on Computer software programming Understand Microsoft Visual Basic 6.0 syntax and its major features Design and develop GUI Windows applications Develop critical thinking of software programming Visual Basic 6.0 how to program ,Deitel & Deitel Cyber classroom CD :Visual Basic 6.0 how to program Internet Web site access
2
Introduction
Computing Concepts
Computer
Processor I/O devices I/O Devices Storage system: Primary & Secondary
Whats Program Programming languages: machine code, high level languages Developing environmental Algorithms
4
Programming languages
GO TO Programming : basic, assembly Structured Programming: Pascal, C,.. Object Programming: Java, C++ Visual approach for GUI programming. Interpreter Compiler Project manager, Code editor, debug, compiler
Compiler
Whats Object? Object properties Object method Whats Class? Message/Even Object vs. Structure How can an OOP program works? Object and Visual Basic
Methods
Object 1
Messages Object 1
Object 1
Flowchart
Flowchart components
Start
Process Flow Input / Output data Start or Begin of algorithms. One START point only.
Evaluation Item
Value i Others
Stop
Flowchart Example
Start Read a, b a=0 ?
No Yes
b=0 ?
No
Yes
X=-b/a
No Solution
Stop
If <condition> then Statement; If <condition> then Statement 1 else Statement 2; Case <Value> of value 1 : Statement 1; .. value n : Statement n; else : Statement 0 end; While <condition> do Statement; Repeat Statement until <condition>; For counter=start value to end value do Statement; For counter=start value downto end value do Statement;
10
Structured data type: array, string, record,.. Variable, Constant Reserve words, keywords Error : Syntax error, Semantic error, Run time error Debug : trace, break point, test case Packet & installation tools
11
Microsoft Windows Programming language Microsoft IDE for Visual studio developer Visual Basic versions
Version history Standard , Professional & Enterprise Windows GUI applications Database applications Computer Graphic applications Internet / WEB applications
12
Forms design Objects/Components properties define Resource edit : icon, button image,..
Code Writing form even base concept. Compile/Build program Debug source code Packet application Deploy application. Maintenance
13
Integrated Development Environment Project Tools Box Form layout Properties Menu Bar and Tool Bar Simple Program develop
IDE Overview
Menu Bar
Tool Bar
Project Window
Properties Window
Department of Information Technology
Nguyn Cao Tr [email protected]
15
Project View
16
Tool Box
Content all objects/components for FORM design. Control all properties of Form/Objects/Components
Properties Windows
Project Windows
17
Program description
The program will show/hide the text Welcome to Visual Basic 6.0 when button Show/Hide is clicked The exit button used to exit the program. It is available after first click of Show button only.
Design form with Label object name Label1 and caption Welcome to Visual Basic 6.0 Set it visible properties to false. Add button cmdShowHide & Button cmdExit to form. Click on each button for writing code to it base on Click even Click Play button on IDE to run program.
Enable = false
cmdExit
cmdShowHide
Caption =&Show
Department of Information Technology
Nguyn Cao Tr [email protected]
19
20
Click Show button: Exit enable, show Text, Show -> Hide
Review from page 25 -> 47 Drawing the Flowchart for Solving the equation
ax2 +bx + c =0
Redo the simple program Using Visual Basic 6.0 IDE to build the form design from page 48->49 Submit to instructor by email. Pre-View chapters 3 and 4 for next lecture.
22
Visual tool of Visual basic for user interface design (GUI) Tool Box components
From Components Component evens Even procedure Button (CmdButton) Frame, Selected box, List box
24
Label
TextBox CommandButton Timer PictureBox Frame CheckBox OptionButton ComboBox ListBox Vertical scrollbar
Department of Information Technology
Nguyn Cao Tr [email protected]
DirListBox
FileListBox Shape Line Data OLE Animation UpDown MonthView DateTimePicker FlatScrollBar
25
The sub procedure will be done when an even happened to component Each component has its own evens.
26
Button Exit : exit program on click Button print: On click, print a line of text Hello, Welcome to Visual Basic on form.
CODE Private Sub Command1_Click() Print " Hello! Welcome to Visual Basic" End Sub Private Sub Command2_Click() End End Sub
27
Other Application
Accumulate ADD
Dim sum As Integer Private Sub cmdClear_Click() sum = 0 txtInput.Text = " " txtAdd.Text = 0 End Sub Private Sub cmdExit_Click() End End Sub Private Sub cmdAdd_Click() sum = sum + txtInput.Text txtAdd.text = sum txtInput.Text = "" End Sub Private Sub Form_Load() cmdClear_Click() End Sub
Program allow user to enter an integer number and click add button. The numbers will be accumulate and display on form.
28
Arithmetic
Visual Basic Operation Arithmetic operator Algebraic expression Visual basic expression
Addition Subtraction Multiplication Division (float) Division (Integer) Exponentiation Negation Modulus
+ * / \ ^ Mod
30
Operators Precedence
Operator () Operation Parentheses
Order of evaluation Evaluated first. If the parentheses are nested, the expression in the innermost pair is evaluated first. If there are several pairs at he same level nested, they are evaluated left to right. Evaluated second. If there are several, they are evaluated left to right Evaluation first. If there are several, they are evaluated left to right. Evaluation fourth. If there are several, they are evaluated left to right.
Evaluation
^ * and /
Exponentiation Negation Multiplication and floating point division Integer Division Modulus Addition and Subtraction
\ Mod + or -
Firths. If there are several, they are evaluated left to right Evaluation Firths. If there are several, they are evaluated left to right Evaluation Firths. If there are several, they are evaluated left to right
31
Comparison Operators
Standard Algebraic equality operator (relational operator) Visual Basic comparison operator Example of Visual Basic condition Meaning of Visual Basic condition
= > <
D is equal to g S is not equal to R Y is greater than i P is less than M C is greater than or equal to E M is less than or equal to S
32
Write a windows program which allow user input 2 numbers A and B and then compare and show the result.
Private Sub cmdClear_Click() txtInput1.Text = "" txtInput2.Text = " Label3.Caption = Result End Sub Private Sub cmdCompare_Click() Dim input1, input2 As Integer input1 = txtInput1.Text input2 = txtInput2.Text If input1 = input2 Then Label3.Caption = "First number equal second number" Else If input1 < input2 Then Label3.Caption = "First number less than second number" Else Label3.Caption = "First number greater than second number" End If End If End Sub
33
control structures of VB Flowchart and control structures Using control structure by samples
If/Then structure
Syntax
Example
Condition
Yes
Statements
35
If/Then/Else structure
Syntax
Example
If cmdShowHide.Caption = &Show then cmdShowHide.Caption = &Hide Label1.Visible = true else cmdShowHide.Caption = &Show Label1.Visible = false end if
Statements
Statements
36
While/Wend structure
Syntax While <condition> statements Wend
Example
Dim product As integer product = 1 While product <= 1000 product = product * 2 print product Wend Whats on form 4 8 16 32 64 128 256 512 1024
Condition
No
Yes
Statements
37
Do while/Loop structure
Syntax Do while <condition> statements Loop
Example
Dim product As integer product = 1 Do while product <= 1000 product = product * 2 print product Loop
While/Wend ||
Do while/Loop
Whats on form
4 8 16 32 64 128 256 512 1024
38
Do until/Loop structure
Syntax Do until <condition> statements Loop
Example
Dim product As integer product = 1 Do until product >1000 product = product * 2 print product Loop Whats on form 4 8 16 32 64 128 256 512 1024
Condition
No Yes
Statements
39
For/Next structure
Syntax
Example
Counter = StartValue
Counter = Counter + Stepsize statements
40
Sample of For/Next
For years = 1 To 10 Step 1 amount = principal * (1 + interestRate) ^ years lstDisplay.AddItem Format$(years, "@@@@") & vbTab & Format$(Format$(amount, "Currency"), _String$(17, "@")) Next years
41
Syntax
Select Case mAccessCode Case Is < 1000 message = "Access Denied" Beep Case 1645 To 1689 message = "Technician Personnel" Case 8345 message = "Custodial Services" Case 55875 message = "Special Services" Case 999898, 1000006 To 1000008 message = "Scientific Personnel" Case Else message = "Access Denied" End Select
Department of Information Technology
Nguyn Cao Tr [email protected]
42
Syntax
counter = 1 Do Print counter & Space$(2); counter = counter + 1 Loop While counter <= 10
Result
1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10
43
Syntax
Statements
Do Loop While Condition
No Yes
counter = 1 Do Print counter & Space$(2); counter = counter + 1 Loop Until counter >= 10
Result
Do
Loop Until
1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10
Statements
Condition
Yes
No
44
Result: 12345
Result: 12345
Why do exit do and exit be used.
45
NOT AND OR
46
Byte
Currency Date Double Integer Long
1
8 8 8 2 4
0 to 255
-922337203685477.5808 to 922337203685477.5807 1 Jan 100 to 31 Dec 9999 / 0:00:00 to 23:59:59 (see chapter 8) -1.79769313486232E308 to -4.94065645841247E-324 (Negative) 1.79769313486232E308 to 4.94065645841247E-324 (Positive) -32767 to 32768 -2147483648 to 2147483648
Object
Single String Variant
4
4 10+ 16
47
LAB Works
All Samples from text book Exercises at end of chapters Assignment Calculator application Your own applications (option)
48
Module programming
Whats module? Why do we need to write program in module? Modules in Visual Basic
Even procedure Visual basic procedure SUB procedure Function procedure Visual basic procedures Sub/function procedures
50
SUB procedure
51
Private Sub Command1_Click() MyProcedure End Sub Private Sub Command2_Click() MyProcedure2 "Hello, this is procedure 2 Call MyProcedure2 (Hello from call method) End Sub
52
Function Procedure
Sample structure of function Public Function MyFunction(X As Integer) As Integer MyFunction = X ^ 3 End Function Call a function
Private Sub Command3_Click() Dim output As Integer output = MyFunction(3) Print "Return value of MyFunction" Print output End Sub
53
Whats call by Value? Whats call by Reference? Call by Value vs. Call by Reference How to write a procedure as call by value / reference?
54
Private Sub callbyVal(ByVal x As Integer) x=x^2 Print "Value of x (has been tranfer as a) within procedure " & x End Sub Private Sub callbyref(x As Integer) x=x^2 Print "Value of x (has been tranfer as a) within procedure " & x End Sub Public Sub ByValandByRef(ByVal x As Integer, y As Integer) x=x^2 y=y^2 Print "Value of x ,y (know as a,b) within sub " & x &" "&y End Sub Private Sub Command4_Click() End End Sub
55
56
Using Rnd function . Rnd return a random number between 0 and 1 (but not 1)
Overdrive declaration
57
What s recursion?
Optional arguments
Private Sub FooBar ( y as Boolean, Optional z as long) Calling
Default Value of Optional arguments Number : 0 Boolean : False Setting default value for Optional argument Private Sub FooBar ( y as boolean, Optional z as long = 8)
59
Named Arguments
Public Sub Display (flag As Boolean, number As Long, name As String) Print Print flag Print number Print name Print End Sub
Private Sub Command1_Click() Print "call as normal arguments" Call Display (True, 32000, "String value") Print "call as named arguments" Call Display (name:="String Value", flag:=True, number:=3200) End Sub
Department of Information Technology
Nguyn Cao Tr [email protected]
60
Code modules
61
Review
Visual programming & Even base programming Control Structure of Visual basic Data type in VB 6.0 Other operators SUB Procedure & Function procedure Recursion LAB
62
Array structure
Introduce Array structure Understand using array structure; sort, search,.. Multi dimensions Dynamic array
Declaring an array in Visual Basic Dim ArrayVariable (Index) As Datatype Index= number of Items -1 ( starting index 0) Dim ArrayVariable (Lbound to Ubound) As Datatype
Lbound =0 Ubound = Number of Items -1 Dim myarray(9) As Integer Dim Mysecondarray (1 to 10) As Integer
Default Example :
Arrayname(index)
64
65
Oversize array by number of item +1 and ignore item(0) Changing base default set by using Option base in general declaration Option Base 1 Option Base is accept 0 or 1 only Using specification declaration of array Dim MyArray(1 to 10) As Integer Dim OtherArray( -10 to 20) As integer
66
67
Using array Items : Array Items can be using as single variable of the same datatype
Myarray(5) = x + 3 Myarray(7) = MyArray(3)+ 5*Myarray(7)
68
70
Sorting array
Search: Linear search , binary search Sort : bubble sort , Quick Sort
Finding the biggest item, put it at end of array Assume that array have one item less Repeat step 1 until the assumed array has only 1 items Array has been sorted
71
72
' Module modBubble.bas Option Explicit Public Sub BubbleSort(theArray() As Integer) Dim pass As Integer, compare As Integer Dim hold As Integer For pass = 1 To (UBound(theArray) - 1) For compare = 1 To (UBound(theArray) - 1) If theArray(compare) > theArray(compare + 1) Then hold = theArray(compare) theArray(compare) = theArray(compare + 1) theArray(compare + 1) = hold End If Next compare Next pass End Sub
73
Linear Search
74
Function LinearSearch(a() As Integer, key As Integer) As Integer Dim x As Integer For x = LBound(a) To UBound(a) If a(x) = key Then LinearSearch = x ' Return index Exit Function End If Next x LinearSearch = -1 found End Function ' Value not
75
Binary Search
Set startindex= lbound (myarray) Set endindex = ubound (myarray) Get miditem = (startindex + endindex ) /2 If searchkey = myarray(miditem) then FOUND Elseif searchkey >myarray(miditem) then startitem = miditem +1 and goto step 3 else enditem = miditem -1 and goto step 3 If startitem>=enditem then NOT FOUND
76
77
78
Multidimensional array
Col 2
Item(1,2) Item(2,2)
Col 2
Item(1,3) Item(2,3)
Row 3
Item(3,1)
Item(3,2)
Item(3,3)
80
Control Array
Select a control -> copy, past it to the same form as many control as you need, they will be a control array Using the same name for controls
All controls in a control array have the same name and therefore only need to write one even procedure for all control within a control array. Control array has lbound=0 and ubound (32767 max) Control array count value : number of items in control array.
Controlname.count Controlname.lbound Controlname.ubound
81
Private Sub cmdButton_Click(Index As Integer) txtDisplay.Text = txtDisplay.Text & Index End Sub
Department of Information Technology
Nguyn Cao Tr [email protected]
82
Dynamic array
Dynamic array is array with dynamic size. Dim myDynamicArray() as integer Define array size when using in code by Redim Redim myDynamicArray (20) Preserve keyword using to keep original value of items when Redim array
Redim Preserve myDynamicArray (50)
Multidimensional array also can be dynamic however the number of dimension cannot be.
83
' Determine state of CheckBox If chkPreserve.Value = vbUnchecked Then ReDim mDynamic(arrayLength) ElseIf chkPreserve.Value = vbChecked Then ' Allocate memory and preserve contents ReDim Preserve mDynamic(arrayLength) End If Call Displayarray cmdErase.Enabled = True End Sub
84
85
86
Character
Character data type include A,B,C,, 0,1,2,, as well as others characters like *, &, +, /, *, etc. Character are comparable by its numeric value in memory.
88
A string is a series of characters treated as a single unit. A string may include any character in ANSI character set. (value from 0 to 255) String in Visual basic has data type named string String is written as list of characters within a double quotation. "This is a string !" Declared a string variable/constant in VB:
Dim StringVariable As String Dim StringVariable As String * 20
Variable length - Default Fix length to 20
89
Variable length string are composed up to 2,147,483,648 characters. Fix length String are composed up to 65,568 characters Strings are comparable by its characters numeric values in order.
Example : "ABCDEF" is less than "ABCd" because D < d
If an Fix-length String is assign a shorter string, the rest will take space characters. For larger String assigned to fix-length string, it s automatically truncated to fix size of string.
90
vbUseCompareOption
Option Compare Type Binary Text Database
Department of Information Technology
Nguyn Cao Tr [email protected]
91
92
Larger string can be conducted by combining small strings together. This process is called string concatenation by using & and/or + operators.
Example: S1=Hello S2 = friends S 3 = S1 + S2 => S3 = Hello friends S4 = S1 & S2 => S4 = Hello friends
If all operands are string, the + and & are similar If an operand are other data type the + operator may have problem.
Example: s1 = Hello + 22 => Error since VB try to change Hello to number and add to 22 => type mismatch
93
Operator Like
Operator Like can using to compare 2 patterns of characters or strings. Return value is True/False
Example: ABCDEFGH like ABCD => false
94
95
Return a character/string with amount of characters which copied from string at position. If remaining is fewer than amount the remained of string is return. Mid$ also can used to replace a part of string with a substring. S = Visual Basic 6.0 Mid$(S,2,3) = XXX => S = VXXXal Basic 6.0
Function Len (string) Return length of string. Function Left$ (string, amount) Return amount leftmost characters Function Right$ (string, amount) Return amount rightmost characters Function InsStr (StartPos, String,SubString) Return the position
where the substring exist from startpos of string or return 0 if not exist. Function InsStrRev (String , SubString , Endpos) Return the position where the substring exist from endpos of string or return 0 if not exist.
Department of Information Technology
Nguyn Cao Tr [email protected]
96
Functions LTrim$(String) , RTrim$(String) and Trim$(String) return a string which have LEFT , RIGHT or BOTH space characters removed Function Space$ (amount) return a string with amount space characters. Function String$( amount, character) return a string with amount of characters Function Replace(String, OldChrs, Newchrs, start, amount, compareoption) return a string with all sub string OldChrs has been replace with substringNewchrs. Replacements done from start point of string with amount of time and compareoption used to fine the Oldchrs sub string. Function StrReverse (string) return a reversed string of string Function Ucase$ (string) , Lcase$(string) Uppercase and lowercase a string WHAT s ELSE? - See language reference
97
Conversion Functions
ASC (character) and Chr$(number) Functions Isnumeric(string) , Val (string) and Str$(number) CBool(string) CByte(string) CCur(string) CDate(string) CDbl(string) CDec(string) CInt(string) CLng(string) CSng(string) CVar(string) Other functions Format string, currency,.. See your text book
98
Function Now gets the current date and time. Function date gets the current date. Date related functions:
Weekday, WeekDayName, Month, Year IsDate : check if sting can be convert to date format DateSerial , DatePart, DateAdd, Dateiff Time, Hour, Minute, Second Timer , TimeSerial FormatDateTime & Format$
99
100
Graphic
Coordination system in computer graphic Drawing on window with VB
Coordinate system
(x,y)
(x,y)
Origin coordinate system The unit that the coordinate is measured in called a scale. Visual basic support difference scales in it system. Scale mode can be define by ScaleMode of properties. User-define coordinate system allow user to change the origin.
Department of Information Technology
Nguyn Cao Tr [email protected]
102
Constant
vbUser vbTwips
Value
0 1
Description
Scale defined by programmer. Default for forms and most controls. 1440 twips per inch. 567 twips per cm. 20 twips per point Commonly used for fonts. 72 points per inch. Commontly used with images. Represent a smallest unit of resolution on a screen. 120 twips horizontally, 240 twips vertically (12 points) Physical inch. Physical Millimeters. Physical centimeter.
2 3 4 5 6 7
103
Calling scale method to change the coordinate and scale system. Scale (left , top) (right , low) Scale (-500, 250) (500, -250)
The ScaleMode propertie will change to vbUser after call Scale. Scale can also be set by setting ScaleTop, ScaleLeft, ScaleWidth and ScaleHeight properties.
ScaleTop = 250 ScaleLeft = = -500 ScaleWidth = 500 ScaleHeight = -250
Drawing Methods
Print method used to print a text on screen at (CurrentX, CurrentY) Line method draw lines on a form or control. Can also draw
rectangles. Line (x1,y1) (x2,y2) Line (x1,y1) (x2,y2) , VbColor, B/BF (not-fill/filled)
105
Draw Method
106
107
108
109
110
Drawing Properties
Draw properties used to define how do items be drawn on form.
Property AutoRedraw
Description
A Boolean value that determones whether or not copy all graphic element drawn is store in memory
DrawMode
DrawStyle
An Integer value that specifies how new points generated from Line, Circle and Pset are draw (see DrawMode slide)
An Integer value that specifies how new points generated from Line, Circle and Pset are draw (see DrawStyle slide) An Integer value in range 1 to 32767 that specifies the drawing width in pixels. An Integer value that specifies how new points generated from Line, Circle and Pset are drawn.(see FillStyle slide)
Drawwidth
FillStyle
Department of Information Technology
Nguyn Cao Tr [email protected]
111
vbNotMergePen
vbMaskNotpen vbNotCopyPen vbMaskNotPen vbInvert vbXorPen
2
3 4 5 6 7
vbNotMaskPen
vnMaskPen vnNotXorPen
8
9 10
112
vbMergeNotPen
vbCopyPen vbMergePenNot vbMerPen vbWhiteness
12
13 14 15 16
Merge Not Pen combines the display color and the inverse of the pen color.
Copy Pen Default. Drawing is done in the ForeColor. Merge Pen Not Combines the pen color and the inverse of the display color. Merge Pen Combines the pen color and the display color. Whiteness Draw is done in white.
113
DrawMode Sample
114
vbDashDot
vbDashDotDot vbInvisible vbInsideSoloid
3
4 5 6
115
DrawStyle Sample
116
vbVerticalLine
vbUpwardDiagonal vbDownwardDiagonal vbCross
3
4 5 6
vbDiagonalCross
Diagonal Crossing Lines The fill is a series of upward and downward diagonal crossing lines.
117
FillStyle sample
118
Line and Shape control provide another way to drawing graphics. Lines Color is specified by using Line Controls BorderColor property Lines Style is specifies by using Line Controls BorderStyle property Lines width is specifies by using Line Controls BorderWidth property
119
120
Shape Control can be using to draw rectangles, ellipse, Circle, Some properties of Shape control: BorderStyle ,BorderColor, borderWidth FillStyle, BackStyle, FillColor, BackColor BorderStyles value is identifies as Lines BorderStyles. FillStyle , Drawmode have value as mention before.
121
Colors
Colors on visual basic is created from RGB values (Red, Green, Blue). Each has value from 0 to 255. RGB(Red,Green,Blue) return a value of a color as long data style. pinkColor = RGB(255,175,175) Some Visual Basic color constants
122
Colors Sample
ForeColor = RGB(Rnd() * 256, Rnd() * 256, Rnd() * 256) a = 3 * Rnd() ' Offset used in equation For theta = 0.001 To totalRadians Step 0.01 r = Sqr(a ^ 2 / theta) x = r * Cos(theta) ' y coordinate y = r * Sin(theta) ' x coordinate x1 = -r * Cos(theta) ' y coordinate y1 = -r * Sin(theta) ' x coordinate PSet (x, y) ' Turn pixel on PSet (x1, y1) ' Turn pixel on Next theta End Sub
Department of Information Technology
Nguyn Cao Tr [email protected]
123
Image can be displayed in form by Image control or PictureBox control. PictureBox control give more properties and method than image control
124
PictureBox Sample
Private Sub Form_Load() picPicture.Picture = LoadPicture("d:\images\ch09\cool.bmp") End Sub Private Sub cmdInvert_Click() Call picPicture.PaintPicture(picPicture.Picture, 0, 0, , , , , , , vbDstInvert) Call SavePicture(picPicture, "images\" & "cool_inverse.bmp") End Sub
125
Printer Object
Printer Object allow user sent text / graphic to printer. By default printer object s properties correspond to default printer in windows setup.
126
Printer object
127
control and ActiveX control Advance GUI design MDI & SDI interface
Controls
User graphic interface in VB is designed by using controls Standard Control: building with VB ActiveX control
Developed by others Need to add to VB by select Projects>Components menu
Menu design
129
Standard Controls
130
Standard Controls
131
Standard Controls
Standard control is ready to use by VB Controls have difference Properties and Methods Some standard controls are not available in standard version of Visual Basic. Its only available in professional or enterprise versions.
132
TextBox
133
TextBox
134
Used to define how/format/structure of data that user input to application Using by add Microsoft MaskEdit control
135
136
Telephone
6290
(091) 391137
Menu design
Menu is a common GUI componen in most windwos applications. Menu in VB Applications can be implement by design it with Menu Edit Tool. Select Tools -> <Menu Edit to open Menu editor.
138
Private Sub cmdExit_Click() End End Sub Private Sub mnuExit_Click() Call cmdExit_Click End Sub
How to assign function to menu Items?
Department of Information Technology
Nguyn Cao Tr [email protected]
139
Single Document Interface (SDI) : NotePad, Paint Multiple Document Interface (MDI): Word, Excel
140
141
142
FileListBox & DriveListBox Sequential File Processing Record data structure Random access file Using Common Dialog control
FileSystemObject, File,Filder,Drive &TextStream Objects See pages 586 for detail method
Dim mfileSysObj As New fileSystemObject
144
145
Record datatype can not do compare. However, its fields can. Fields of record can be used as a variable of its datatype. Filed indicated by RecordName.FieldName
146
147
File Open
dlgOpen.ShowOpen
148
Common Dialog
If dlgOpen.FileTitle <> "" Then Open filename For Random Access Write As #1 Len = recordLength
cmdOpenFile.Enabled = False cmdEnter.Enabled = True cmdDone.Enabled = True Else MsgBox ("You must specify a file name") End If
149
dlgOpen.ShowOpen filename = dlgOpen.filename If dlgOpen.FileTitle <> "" Then ' Open file for writing Open filename For Random Access Read As #1 Len = recordLength cmdOpenFile.Enabled = False ' Disable button
150
Database applications
Database management system (DBMS) Structured query Language (SQL) Using database with VB
Data stored Data management Data query Data relationship maintenance File vs. Database: Stored data, query, structured data Data management
Relationship database Database Management System (DBMS) Visual basic, relationship database and SQL
152
Redundancy can be reduced. Inconsistency can be avoided. The data can be shared. Standard can be enforced. Security restrictions can be applied. Integrity can be maintained. Conflicting requirement can be balanced. Exchangeable between applications Upgradeable Distributed database
153
Logical representation of the data that allow relationship between data to be considered. Composes of tables and their relationship all in once.
154
155
156
157
SQL is a standard language for query, management difference database systems. Some of SQL language keywords
158
SQL Command
Select * From tablename Order Fieldname ASC Select * From tablename Order Fieldname DESC Select * From AuthorTable Order by Author ASC
159
SQL Command
Select * From Table1 Inner Join Tabbe2 On Table1.field = Table2.field SELECT Authors, ISBN FROM Authors INNER JOIN TitleAuthor ON Authors.Au_ID = TitleAuthor.Au_ID ORDER BY Author ASC Add More ActiveX Designers -> Data environmont . The Data Environment Designer appears See document on Using Data Environment to connect to database (Page 797 TextBook)
160