Presentation is loading. Please wait.

Presentation is loading. Please wait.

Tutorial 81 Field, Record, Data File Field - a single item of information about a person, place, or thing Record - a group of related fields that contain.

Similar presentations


Presentation on theme: "Tutorial 81 Field, Record, Data File Field - a single item of information about a person, place, or thing Record - a group of related fields that contain."— Presentation transcript:

1 Tutorial 81 Field, Record, Data File Field - a single item of information about a person, place, or thing Record - a group of related fields that contain all of the necessary data about a specific person, place, or thing Data file - a collection of related records

2 Tutorial 82 Random vs Sequential Sequential access files are similar to cassette tapes Random access files are similar to CDs Each record in a random access file has a unique number, called a record number, that indicates its position in the file

3 Tutorial 83 Random vs Sequential Records in a sequential access files are referred to as variable-length records Records in a random access file are referred to as fixed-length records Random access files are called direct access files

4 Tutorial 84 Sequential vs Random Access File “Jackets”,45 “Hats”,15 “Gloves”,10 Sequential Access: Random Access: Jackets-  Hats  Gloves 

5 Tutorial 85 Type Statement Before you can create a random access file, you need to use the Type statement to define the file’s record structure You enter the Type statement in the General declarations section of a code module

6 Tutorial 86 Type Statement Type structurename fieldname1 As datatype [fieldname2 As datatype] [fieldnameN As datatype] End Type Option Explicit Type ItemStruc strName As String * 7 intPrice As Integer End Type

7 Tutorial 87 Declaring a Record Variable Dim udtItemRec As ItemStruc Public udtItemRec As ItemStruc

8 Tutorial 88 Referencing a Field Variable To refer to individual field variables within a record variable, precede the field variable’s name with the name of the record variable in which it is defined. Separate the record variable’s name from the field variable’s name with a period udtItemRec.strName udtItemRec.intPrice

9 Tutorial 89 Open Statement Open filename [ For mode ] As # filenumber Len = reclength Open “a:\item.dat” For Random As #1 Len = Len(udtItemRec)  filename is the name of the file you want to open  filenumber is the number assigned to the file  mode is always random  reclength must be a positive integer between 1 and 32767, inclusive  you calculate the record length by adding together the length of each field in the record variable

10 Tutorial 810 Len Function Len(variablename)  variablename refers to the record variable’s name  measures the length of the record variable as specified in the Type statement

11 Tutorial 811 Close Statement Close[#filenumber] filenumber is the number used in the Open statement to open the file

12 Tutorial 812 Write # vs Put You use the Write # statement to write a record to a sequential access file You use the Put statement to write a record to a random access file

13 Tutorial 813 Put Statement Put # filenumber, [ recordnumber ], variablename Put #1, 3, udtItemRec Put #1, intItemNum, udtItemRec filenumber is the number used in the Open statement to open the file recordnumber is the number of the record to be written variablename is the name of the record variable

14 Tutorial 814 Initializing Random Access Files Always initialize a random access file Always prompt the user to verify that he or she wants to initialize the file Before you can initialize a file, you must estimate the maximum number of records the file will contain

15 Tutorial 815 Space Function Space(number) strName = Space(20) number represents the number of spaces you want to assign to the string

16 Tutorial 816 GUI Rules It is customary in Windows applications to prompt the user to verify that he or she wants to proceed with a destructive operation Display messages to inform the user of the status of important events—such as “File was initialized.” or “File was not initialized.”

17 Tutorial 817 Input # vs Get You use the Input # statement to read a record from a sequential access file You use the Get statement to read a record from a random access file

18 Tutorial 818 Get Statement Get # filenumber, [ recordnumber ], variablename Get #1, 3, udtItemRec Get #1, intItemNum, udtItemRec filenumber is the number used in the Open statement to open the file recordnumber is the number of the record to be read variablename is the name of the record variable

19 Tutorial 819 Startup Form When two or more forms are contained in a project, only one can be the startup form Use the Properties command on the Project menu to define the startup form for the project

20 Tutorial 820 Control Arrays Group of controls of the same type that have the same name and share the same set of event procedures Each control in the array is identified by the array’s name and a unique index The first control in the array has an index of 0

21 Tutorial 821 Creating a Control Array If the controls are not already on the form, place the first control on the form and set its name and other properties Copy the control to the clipboard, then paste the appropriate number of controls on the form When you are asked if you want to create a control array, click the Yes button To make existing controls into an array, simply assign the same name to each control. When you are asked if you want to create a control array, click the Yes button

22 Tutorial 822 Control Array Code Window Index As Integer appears in the Code windows for a control array All controls in the array share the same set of Code windows Index contains an integer that represents the value stored in the Index property of the control receiving the event

23 Tutorial 823 Index Property vs Index Argument The Index property stores a number that identifies each control in the array Each control in the array has a value in its Index property The Index property is like an address The Index argument found in the Code window is a local variable created by Visual Basic The Index argument contains the address of the control receiving the event

24 Tutorial 824 Call Statement Call name[(argumentlist)] Call Initialize(dlgSeat.FileName) In the argumentlist, you enter the information you want to pass to the sub procedure

25 Tutorial 825 Intrinsic Color Constants

26 Tutorial 826 Examples of Passing Information Call DoubleNumber(intNum) Private Sub DoubleNumber(intNum As Integer) Call Display(strName, intAge) Private Sub Display(strStudent as String, intNum as Integer) Call Update(intNum) Private Sub Update(ByVal intNumber As Integer)

27 Tutorial 827 Referencing a Control in Another Form The period between the form and the control, as well as the period between the control and the property, is called the dot member selection operator form.control frmPatron.lblNum form.control.property frmPatron.lblNum.Caption

28 Tutorial 828 Loading and Displaying a Form Visual Basic has two statements and two methods that control the loading and displaying of forms. Load statement Unload statement Hide method Show method

29 Tutorial 829 Load and Unload Statements Load statement Brings a form into memory, but does not display the form on the screen Syntax: Load object Unload statement Removes a form from both memory and the screen Syntax Unload object

30 Tutorial 830 Show and Hide Methods Show method Displays a form on the screen; loads the form if it is not already in memory Syntax: object.Show [style], where style, which is optional, can be either 0 or 1 Hide method Removes a form from the screen, but leaves it in memory Syntax: object.Hide

31 Tutorial 831 Style 0 or omitted means that the form is modeless Example: MSDN Library window 1 means that the form is modal Example: Visual Basic’s Open Project dialog box

32 Tutorial 832 Trim, LTrim, RTrim Trim(string) - removes leading and trailing spaces from a string LTrim(string) - removes leading spaces from a string RTrim(string) - removes trailing spaces from a string

33 Tutorial 833 Debugging Technique You can use Visual Basic’s MsgBox statement to assist you when debugging an application The syntax of the MsgBox statement is MsgBox prompt, where prompt is the message you want displayed in the dialog box If you use the Err object’s Description property as the prompt, the MsgBox statement will display a message indicating the error that occurred in the procedure


Download ppt "Tutorial 81 Field, Record, Data File Field - a single item of information about a person, place, or thing Record - a group of related fields that contain."

Similar presentations


Ads by Google