database structure and terminology

Upload: kristine-ann-reclosado

Post on 06-Apr-2018

214 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/3/2019 Database Structure and Terminology

    1/11

    Database Structure and Terminology

    yIn simplest terms, a database is a collection of information. This collection is stored in well-definedtables, or matrices.

    yThe rows in a database table are used to describe similar items. The rows are referred to asdatabase records. In general, no two rows in a database table will be alike.

    yThe columns in a database table provide characteristics of the records. These characteristics arecalled database fields. Each field contains one specific piece of information. In defining a databasefield, you specify the data type, assign a length, and describe other attributes.

    ADO Data Control

    yThe ADO (ActiveX Data Object) data control is the primary interface between a Visual Basicapplication and a database. It can be used without writing any code at all! Or, it can be a central partof a complex database management system.This icon may not appear in your Visual Basic toolbox. If it doesnt, select Project from the mainmenu, then click Components. The Components window will appear. Select Microsoft ADO DataControl, and then click OK. The control will be added to your toolbox.

    yAs mentioned in Review and Preview, previous versions of Visual Basic used another data control.That control is still included with Visual Basic 6.0 (for backward compatibility) and has as its icon:

    Make sure you are not using this data control for the work in this class. This control is suitable forsmall databases. You might like to study it on your own.

    yThe data control (or tool) can access databases created by several other programs besides VisualBasic (or Microsoft Access). Some other formats supported include Btrieve, dBase, FoxPro, andParadox databases.

    yThe data control can be used to perform the following tasks:1. Connect to a database.2. Open a specified database table.3. Create a virtual table based on a database query.4. Pass database fields to other Visual Basic tools, for display orediting. Such tools are bound tools(controls), or data aware.5. Add new records or update a database.6. Trap any errors that may occur while accessing data.7. Close the database.

    Data Control Properties:

    Align Determines where data control is displayed.Caption Phrase displayed on the data control.Connection String Contains the information used to establish a connection to a database.Lock Type Indicates the type of locks placed on records during editing (default setting makesdatabases read-only).Record set A set of records defined by a data controls Connection String and Record Sourceproperties. Run-time only.

    Record Source Determines the table (or virtual table) the datacontrol is attached to.

    yAs a rule, you need one data control for every database table, or virtual table, you need access to.One row of a table is accessible to each data control at any one time. This is referred to as thecurrent record.Data Links

    yAfter placing a data control on a form, you set the Connection String property.The ADO data control can connect to a variety of database types. There are three ways to connect toa database: using a data link, using an ODBC data source, or using a connection string. In this class,we will look only at connection to a

  • 8/3/2019 Database Structure and Terminology

    2/11

    MicrosoftAccess database using a data link. A data link is a file with a UDL extension that containsinformation on database type.

    yIf your database does not have a data link, you need to create one. This process is best illustratedby example. We will be using the BIBLIO.MDB database in our first example, so these steps showyou how to create its data link:1. Open Windows Explorer.2. Open the folder where you will store your data link file.

    3. Right-click the right side of Explorer and choose New. From the list of files, select Microsoft DataLink.4. Rename the newly created file BIBLIO.UDL5. Right-click this new UDL files and clicks Properties.6. Choose the Providertab and select Microsoft Jet 3.51OLE DB Provider(an Access database).7. Click the Next button to go to the Connection tab.8. Click the ellipsis and use the Select Access Database dialog box to choose the BIBLIO.MDB filewhich is in the Visual Basic main folder. Click Open.9. Click Test Connection. Then, click OK (assuming it passed). The UDL file is now created and canbe assigned to Connection String, using the steps below.

    yIf a data link has been created and exists for your data base, click the ellipsis that appears next to

    the Connection String property. Choose Use Data Link File.Then, click Browse and find the file. Click Open. The data link is now assigned to the property. ClickOK.Assigning Tables

    yOnce the ADO data control is connected to a database, we need to assign a table to that control.Recall each data control is attached to a single table, whether it is a table inherent to the database orthe virtual table we discussed.Assigning a table is done via the Record Source property.

    yTables are assigned by making queries of the database. The language used to make a query isSQL (pronounced sequel, meaning structured query language).SQL is an English-like language that has evolved into the most widely used data base query

    language. You use SQL to formulate a question to ask of the database. The data base answers thatquestion with a new table of records and fields that match your criteria.

    yA table is assigned by placing a valid SQL statement in the Record Source property of a datacontrol. We wont be learning any SQL here. There are many texts on the subject - in fact; many ofthem are in the BIBLIO.MDB database weve been using. Here we simply show you how to use SQLto have the data controlpoint to an inherent database table.

    yClick on the ellipsis next to RecordSource in the property box. APropertyPages dialog box will appear. In the box marked Command Text (SQL), type this line:SELECT * FROM Table NameThis will select all fields (the * is a wildcard) from a table named Table Name in the database. ClickOK.

    ySetting the Record Source property also establishes the Record set property, which we will seelater is a very important property.

    Bound Data Tools

    yMost of the Visual Basic tools weve studied can be used as bound, ordata aware, tools (orcontrols). That means, certain tool properties can be tied to a particular database field. To use abound control, one or more data controls must be on the form.

    ySome bound data tools are:Label Can be used to provide display-only access to a specified text data field.

    Tex

    t Box

    Can be used to provide read/write access to a specified text data field. Probably, the mostwidely used data bound tool.Check BoxUsed to provide read/write access to a Boolean field.Combo BoxCan be used to provide read/write access to a text data field.List BoxCan be used to provide read/write access to a text data field.Picture BoxUsed to display a graphical image from a bitmap, icon, or metafile on your form.Provides read/write access to a image/binary data field.Image BoxUsed to display a graphical image from a bitmap, icon, or metafile on your form (usesfewer resources than a picture box). Provides read/write access to an image/binary data field.

  • 8/3/2019 Database Structure and Terminology

    3/11

    yThere are also three custom data aware tools, the Data Combo (better than using the boundcombo box), Data List (better than the bound list box), andData Grid tools, we will look at later.

    yBound Tool Properties:Data Changed Indicates whether a value displayed in a bound control has changed.Data Field Specifies the name of a field in the table pointed to by the respective data control.Data Source Specifies which data control the control is bound to another control or tool, the database

    will automatically be updated with the new data (assuming LockType is set to allow an update).yTo make using bound controls easy follow these steps (in order listed) in placing the controls on aform:1. Draw the bound control on the same form as the data control to which it will be bound.2. Set the Data Source property. Click on the drop-down arrow to list the data controls on your form.Choose one.3. Set the Data Field property. Click on the drop-down arrow to list the fields associated with theselected data control records. Make your choice.4. Set all other properties, as required.

    Finding Specific RecordsyIn addition to using the data control to move through database records, we can write Visual Basiccode to accomplish the same, and other, tasks. This is referred to as programmatic control. In fact,many times the data controlVisible property is set to False and all data manipulations are performed in code.We can also use programmatic control to find certain records.

    yThere are four methods used for moving in a database. These methods replicatethe capabilities of the four arrow buttons on the data control:Move First - Move to the first record in the table.Move Last -Move to the last record in the table.Move Next - Move to the next record (with respect to the current record) in the table.

    Move Previous Move to the previous record (with respect to the current record) in the table.yWhen moving about the database programmatically, we need to test the BOF(beginning of file)and EOF (end of file) properties. The BOF property is true when the current record is positionedbefore any data. The EOF property is True when the current record has been positioned past the endof the data. If either property is true, the current record is invalid. If both properties are true, then thereis no data in the database table at all.

    yThese properties, and the programmatic control methods, operate on the Record set property ofthe data control. Hence, to move to the first record in a table attached to a data control nameddtaExample, the syntax is:dtaExample.Recordset.MoveFirst

    yThere is a method used for searching a database:

    Find Find a record that meets the specified search criteria.This method also operates on the Record set property and has three arguments we will beconcerned with. To use Find with a data control named dtaExample:dtaExample.Recordset.Find Criteria,NumberSkipped,SearchDirection

    yThe search Criteria is a string expression like a WHEREclause in SQL. We wont go into muchdetail on such criteria here. Simply put, the criteria describe what particular records it wants to look at.For example, using our book database, if we want to look at books with titles (the Title field)beginning with S, we would use:Criteria = Title >= SNote the use of single quotes around the search letter. Single quotes are used to enclose strings inCriteria statements. Three logical operators can be used: equals (=), greater than (>), and less than(

  • 8/3/2019 Database Structure and Terminology

    4/11

    argument can be used to provide a variety of search types (search from the top, search from thebottom, etc.)

    yIf a search fails to find a record that matches the criteria, the Record sets EOF orBOF property is set to True (depending on search direction). Another property used in searches is theBookmark property. This allows you to save the current record pointer in case you want to return tothat position later. The example illustrates its use.

    Data Manager

    yAt this point, we know how to use the data control and associated data bound tools to access adatabase. The power of Visual Basic lies in its ability to manipulate records in code. Such tasks asdetermining the values of particular fields, adding records, deleting records, and moving from recordto record are easily done. This allows us to build a complete database management system (DBMS).

    yWe dont want to change the example database, BIBLIO.MDB. Lets create our own database tochange. Fortunately, Visual Basic helps us out here. TheVisual Data Manageris a Visual Basic Add-In that allows the creation and management ofdatabases. It is simple to use and can create a database compatible with the Microsoft Jet (orAccess) database engine.

    yTo examine an existing database using the Data Manager, follow these steps:

    1. Select Visual Data Managerfrom Visual Basics Add-In menu (you may be asked if you want toadd SYSTEM.MDA to the .INI file answer no.)2. Select Open Database from the Data ManagerFile menu.3. Select the database type and name you want to examine.Once the database is opened, you can do many things. You can simply look through the varioustables. You can search for particular records. You can apply SQL queries. You can add/deleterecords. The Data Manager is a DBMS in itself. You might try using the Data Manager to look throughthe BIBLIO.MDB example database.

    yTo create a new database, follow these steps:

    1. Select Visual Data Managerfrom Visual Basics Add-In menu (you may be asked if you want to

    add SYSTEM.MDA to the .INI file answer No.)2. Select New from the Data ManagerFile menu. Choose database type(Microsoft Access, Version 7.0), then select a directory and enter a name for your database file. ClickOK.3. The Database window will open. Right click the window and select New Table. In the Name box,enter the name of your table. Then define the tables fields, one at a time, by clicking Add Field, thenentering a field name, selecting a data type, and specifying the size of the field, if required. Once thefield is defined, click the OK button to add it to the field box. Once all fields are defined, click theBuild theTable button to save your table.

    Database Management

    yThe Data Manager is a versatile utility for creating and viewing databases.However, its interface is not that pretty and its use is somewhat cumbersome. We would not want touse it as a database management system (DBMS). Nor, would we expect users of our programs tohave the Data Manager available for their use. The next step in our development of our databaseskills is to use VisualBasic to manage our databases, that is develop a DBMS.

    yWe will develop a simple DBMS. It will allow us to view records in an existing database. We will beable to edit records, add records, and delete records.Such advanced tasks as adding tables and fields to a database and creating a new database can bedone with Visual Basic, but are far beyond the scope of the discussion here.

    yTo create our DBMS, we need to define a few more programmatic control methods associated withthe data control Record set property. These methods are:Add New A new record is added to the table. All fields are set to Null and this record is made thecurrent record.Delete The current record is deleted from the table. This method must be immediately followed byone of the Move methods because the current record is invalid after a Delete.Update Saves the current contents of all bound tools.

  • 8/3/2019 Database Structure and Terminology

    5/11

    yTo edit an existing record, you simply display the record and make any requiredchanges. The LockType property should be set to adLockPessimistic (locks each record as it is edited). Then, whenyou move off of that record, either with a navigation button or through some other action, Visual Basicwill automatically update the record. If desired, or needed, you may invoke the Update method toforce an update (use Lock Type = asLockOptimistic). For a data control named dtaExample, thesyntax for this statement is:

    dtaExample.Recordset.Update

    yTo add a record to the database, we invoke the AddNew method. The syntax forour example data control is:dtaExample.Recordset.AddNewThis statement will blank out any bound data tools and move the current record tothe end of the database. At this point, you enter the new values. When you moveoff of this record, thechanges are automatically made to the database. Anotherway to update the database with the changes is via the Update method.After adding a record to a database, you should invoke the Refresh property ofthe data control to insure proper sorting (established by RecordSource SQLstatement) of the new entry. The format is:dtaExample.Refresh

    yTo delete a record from the database, make sure the record to delete is thecurrent record. Then, we use the Delete method. The syntax for the example data control is:dtaExample.Recordset.Delete

    Once we execute a Delete, we must move (using one of the Move methods) off of the current recordbecause it no longer exists and an error will occur if we dont move. This gets particularly tricky ifdeleting the last record (check the EOF property). If EOF is true, you must move to the top of thedatabase (Move First). You then must make sure there is a valid record there (check the BOFproperty). The example code demonstrates proper movement.

    Custom Data Aware Controls

    yAs mentioned earlier, there are three custom data aware tools, in addition to the standard VisualBasic tools: the Data List, Data Combo, and Data Grid ADO tools. Well present each of these,giving their suggested use, some properties and some events. If the icons for these tools are not inthe toolbox, select Project from the main menu, then click Components. Select Microsoft DataListControls 6.0 (OLEDB) and Microsoft Data Grid 6.0 (OLEDB) in the Components window. Click OK- the controls will appear.

    yLike the data control, previous versions of Visual Basic used DAO versions of the list, combo, andgrid controls, named DBList, DBCombo, and DBGrid. Make sure you are not using these tools.

    yData List Box:The first bound data custom tool is the DataList Box. The list box is automatically filled with a fi eldfrom a specified data control. Selections from the list box can then be used to update another fieldfrom the same data control or, optionally, used to update a field from another data control.Some properties of the Data List box are:

    Data Source Name of data control that is updated by the selection.Data Field Name of field updated in Record set specified by Data Source.Row Source Name of data control used as source of items in list box.List Field Name of field in Record set specified by Row Source used to fill list box.Bound Column Name of field in Record set specified by Row Source to be passed to Data Field,once selection is made. This is usually the same as List Field.Bound Text Atext value of Bound Column field. This is the value passed to Data Field property.

    Text the value of selected item in list. Usually the same as Bound Text.The most prevalent use of the Data List box is to fill the list from the database, then allow selections.The selection can be used to fill any tool on a form, whether it isdata aware or not.

    yData Combo Box:The Data Combo Boxis nearly identical to the DataList box, hence we wont look at a separate setof properties. The only differences between the two tools is that, with the Data Combo box, the listportion appears as a drop-down box and the user is given the opportunity to change the contents ofthe returned Text property.

    yData Grid Tool:

  • 8/3/2019 Database Structure and Terminology

    6/11

    The Data Grid tool is, by far, the most useful of the custom data bound tools. It can display an entiredatabase table, referenced by a data control. The table can then be edited as desired.The Data Grid control is in a class by itself, when considering its capabilities. It is essentially aseparate, highly functional program. The only property well be concerned with is the DataSourceproperty, which, as always, identifies the table associated with the respective data control. Refer tothe Visual BasicProgrammers Guide and other references for complete details on using the Data Grid control.

    Database Access and Management 8-35As an example of the power of the DataGrid control, heres what is obtained by simply setting theDataSource property to the dtaExample data control, which is bound to the Titles table in theBIBLIO.MDB database:At this point, we can scroll through the table and edit any values we choose. Any changes areautomatically reflected in the underlying database. Column widths can be changed at run-time!Multiple row and column selections are possible! Like we said a very powerful tool.Creating a Data Report

    yOnce you have gone to all the trouble of developing and managing a database, it is nice to havethe ability to obtain printed or displayed information from your data.The process of obtaining such information is known as creating a data report.

    yThere are two steps to creating a data report. First, we need to create a Data Environment. This isdesigned within Visual Basic and is used to tell the data report what is in the database. Second, wecreate the Data Report itself. This, too, is done within Visual Basic. The Data Environment and DataReport files then become part of the Visual Basic project developed as a database managementsystem.

    yThe Visual Basic 6.0 data report capabilities are vast and using them is a detailed process. The useof these capabilities is best demonstrated by example. We will look at the rudiments of report creationby building a tabular report for our phone database.

    Graphics Methods

    yGraphics methods apply to forms and picture boxes (remember a picture box is like a form withina form). With these methods, we can draw lines, boxes, and circles. Before discussing the commandsthat actually perform the graphics drawing, though, we need to look at two other topics: screen

    management and screen coordinates.

    yIn single program environments (DOS, for example), when something is drawn on the screen, itstays there. Windows is a multi-tasking environment. If you switch from a Visual Basic application tosome other application, your Visual Basic form may become partially obscured. When you return toyour Visual Basic application, you would like the form to appear like it did before being covered. Allcontrols are automatically restored to the screen. Graphics methods drawings may or may not be

    restored - we need them to be, though. To accomplish this, we must use properscreenmanagement.

    yThe simplest way to maintain graphics is to set the form or picture box's AutoRedraw property toTrue. In this case, Visual Basic always maintains a copy of graphics output in memory (createspersistent graphics). Another way to maintain drawn graphics is (with AutoRedraw set to False) toput all graphics commands in the form or picture box's Paint event. This event is called whenever anobscured object becomes unobscured. There are advantages and disadvantages to both approaches(beyond the scope of discussion here). For now, we will assume our forms won't get obscured and,hence, beg off the question of persistent graphics and using the AutoRedraw property and/or Paintevent.

    yPSet Method:To set a single point in a graphic object (form or picture box) to a particular color, use the PSetmethod. We usually do this to designate a starting point for other graphics methods. The syntax is:ObjectName.PSet (x, y), Color where ObjectName is the object name, (x, y) is the selected point,and Coloris the point color(discussed in the next section). If the ObjectName is omitted, the currentform is assumed to be the object. If Color is omitted, the object'sForeColorproperty establishes the color. PSet is usually used to initialize some further drawingprocess.

    yLine Method:

  • 8/3/2019 Database Structure and Terminology

    7/11

    The Line method is very versatile. We can use it to draw line segments, boxes, and filled boxes. Todraw a line, the syntax is:ObjectName.Line (x1, y1) - (x2, y2), Color where Object Name is the object name, (x1, y1) thestarting coordinate, (x2, y2) the ending coordinate, and Colorthe line color. Like PSet, if ObjectName is omitted, drawing is done to the current form and, if Color is omitted, the objectsFore Colorproperty is used.To draw a line from (CurrentX, Current Y) to (x2, y2), use:ObjectName.Line - (x2, y2), Color

    There is no need to specify the start point since Current X and Current Y are known.To draw a box bounded by opposite corners (x1, y1) and (x2, y2), use:

    ObjectName.Line (x1, y1) - (x2, y2), Color, B and to fill that box (using the current FillPattern), use:ObjectName.Line (x1, y1) - (x2, y2), Color, BF

    yCircle Method:The Circle method can be used to draw circles, ellipses, arcs, and pie slices.We'll only look at drawing circles - look at on-line help for other drawing modes.The syntax is:ObjectName.Circle (x, y), r, Color

    This command will draw a circle with center(x, y) and radius r, using Color.

    y Print Method:Another method used to 'draw' to a form or picture box is the Print method. Yes, for these objects,printed text is drawn to the form. The syntax is:ObjectName.Print [information to print]Here the printed information can be variables, text, or some combination. If no object name isprovided, printing is to the current form.Information will print beginning at the object's CurrentX and CurrentY value. The color used isspecified by the object's ForeColorproperty and the font is specified by the object's Fontcharacteristics.

    y Cls Method:

    To clear the graphics drawn to an object, use the Cls method. The syntax is:

    ObjectName.Cls

    If no object name is given, the current form is cleared. Recall Cls only clears thelowest of the three display layers. This is where graphics methods draw.

    yFor each graphic method, line widths, fill patterns, and other graphics features can be controlled viaother object properties. Consult on-line help for further information.

    Using Colors

    yNotice that all the graphics methods can use a Colorargument. If that argument is omitted, theForeColorproperty is used. Color is actually a hexadecimal (long integer) representation of color -look in the Properties Window at some of the values of color for various object properties. So, oneway to get color values is to cut and paste values from the Properties Window. There are other ways,though.

    ySymbolic Constants:

    Visual Basic offers eight symbolic constants(see

    Appendix I) to representsome basic colors. Any of these constants can be used as a Colorargument.

    Constant Value ColorvbBlack 0x0 BlackvbRed 0xFF RedvbGreen 0xFF00 GreenvbYellow 0xFFFF YellowvbBlue 0xFF0000 BluevbMagenta 0xFF00FF MagentavbCyan 0xFFFF00 Cyan

  • 8/3/2019 Database Structure and Terminology

    8/11

    vbWhite 0xFFFFFF White

    yQBColor Function:For Microsoft QBasic, GW-Basic and QuickBasic programmers, Visual Basic replicates the sixteenmost used colors with the QBColorfunction. The color is specified by QBColor(Index), where thecolors corresponding to the Index are:Index Color Index Color0 Black 8 Gray1 Blue 9 Light blue

    2 Green 10 Light green3 Cyan 11 Light cyan4 Red 12 Light red5 Magenta 13 Light magenta6 Brown 14 Yellow7 White 15 Light (bright) white

    yRGB Function:The RGB function can be used to produce one of 224 (over 16 million) colors! The syntax for usingRGB to specify the color property is: RGB (Red, Green, Blue) where Red, Green, and Blue areinteger measures of intensity of the corresponding primary colors. These measures can range from 0

    (least intensity) to 255 (greatest intensity). For example, RGB(255, 255, 0) will produce yellow.yAny of these four representations of color can be used anytime your Visual Basiccode requires acolor value.

    yColor Examples:frmExample.BackColor = vbGreenpicExample.FillColor = QBColor(3)lblExample.ForeColor = RGB(100, 100,100)

    Mouse Events

    yRelated to graphics methods are mouse events. The mouse is a primary interface to performinggraphics in Visual Basic. We've already used the mouse to Click and DblClick on objects. Here, wesee how to recognize other mouse events to allow drawing in forms and picture boxes.

    yMouseDown Event:

    The MouseDown event procedure is triggered whenever a mouse button is pressed while the mousecursor is over an object. The form of this procedure is:Sub ObjectName_MouseDown(Button As Integer, Shift As Integer, X AsSingle, Y As Single)..End SubThe arguments are:Button Specifies which mouse button was pressed.

    Shift Specifies state of Shift, Ctrl, and Alt keys.X, Y Coordinate of mouse cursor when button was pressed.Values for the Button argument are:Symbolic Constant Value DescriptionvbLeftButton 1 Left button is pressed.vbRightButton 2 Right button is pressed.vbMiddleButton 4 Middle button is pressed.Only one button press can be detected by the MouseDown event. Values for theShift arguments are:Symbolic Constant Value DescriptionvbShiftMask 1 Shift key is pressed.vbCtrlMask 2 Ctrl key is pressed.vbAltMask 4 Alt key is pressed.The Shift argument can represent multiple key presses. For example, if Shift = 5(vbShiftMask + vbAltMask), both the Shift and Alt keys are being pressed when the MouseDownevent occurs.

    yMouseUp Event:

  • 8/3/2019 Database Structure and Terminology

    9/11

    The MouseUp event is the opposite of the MouseDown event. It is triggered whenever a previouslypressed mouse button is released. The procedure outline is:

    Sub ObjectName_MouseUp(Button As Integer, Shift As Integer, X As Single, YAs Single)..End SubThe arguments are:Button Specifies which mouse button was released.

    Shift Specifies state of Shift, Ctrl, and Alt keys.X, Y Coordinate of mouse cursor when button wasreleased.The Button and Shift constants are the same as those for the MouseDown event.

    yMouse Move Event:The MouseMove event is continuously triggered whenever the mouse is being moved. Theprocedure outline is:

    Sub ObjectName_MouseMove(Button As Integer, Shift As Integer, X AsSingle, Y As Single)..End Sub

    The arguments are: Button Specifies which mouse button(s), if any, are pressed.Shift Specifies state of Shift, Ctrl, and Alt keysX, Y Current coordinates of mouse cursor.

    Drag and Drop Events

    yRelated to mouse events are drag and drop events. This is the process of using the mouse to pickup some object on a form and move it to another location.We use drag and drop all the time in Visual Basic design mode to locate objects on our applicationform.

    yDrag and drop allows you to design a simple user interface where tasks can be performed without

    commands, menus, or buttons. Drag and drop is very intuitive and, at times, faster than othermethods. Examples include dragging a file to another folder or dragging a document to a printerqueue.

    yAny Visual Basic object can be dragged and dropped, but we usually use picture and imageboxes. The item being dragged is called the source object. The itembeing dropped on (if there is any) is called the target.

    yObject Drag Properties:If an object is to be dragged, two properties must be set:

    Drag Mode Enables dragging of an object (turns off ability to receive Click or Mouse Down events).Usually use 1-Automatic (vbAutomatic).

    Drag Icon Specifies icon to display as object is being dragged.As an object is being dragged, the object itself does not move, only the Drag Icon. to move the object,some additional code using the Move method (discussed ina bit) must be used.

    yDragDrop Event:

    The Drag Drop event is triggered whenever the source object is dropped on the target object. Theprocedure form is:

    Sub ObjectName_DragDrop(Source As Control, X As Single, Y As Single)

    .

    .

    End Sub

    The arguments are:

    Source Object being dragged.

    X, Y Current mouse cursor coordinates.

  • 8/3/2019 Database Structure and Terminology

    10/11

    yDrag Over Event:The Drag Overevent is triggered when the source object is dragged over another object. Itsprocedure form is:

    Private Sub ObjectName_DragOver(Source As Control, X As Single, YAs Single, State As Integer)..End Sub

    The first three arguments are the same as those for the Drag Drop event. TheState argument tells the object where the source is. Its values are 0-Entering(vbEnter), 1-Leaving (vbLeave), 2-Over(vbOver).

    yDrag and Drop Methods:Drag Starts or stops manual dragging (won't be addressed here - we use Automatic dragging)

    Move Used to move the source object, if desired.Timer Tool and Delays

    yMany times, especially in using graphics, we want to repeat certain operations at regular intervals.

    The timer tool allows such repetition. The timer tool does not appear on the form while theapplication is running.

    yTimer tools work in the background, only being invoked at time intervals you specify. This is multi-tasking - more than one thing is happening at a time.

    yTimer Properties:Enabled Used to turn the timer on and off. When on, it continues to operate until the Enabledproperty is set to False. Interval Number of milliseconds between each invocation of the Timer Event.

    yTimer Events:The timer tool only has one event, Timer. It has the form:Sub TimerName_Timer()..End SubThis is where you put code you want repeated every Interval seconds.

    yTimer Example:To make the computer beep every second, no matter what else is going on, you add a timer tool(named timExample) to the form and set the Interval property to1000. That timer tool's event procedure is then:Sub timExample_Timer()BeepEnd Sub

    yIn complicated applications; many timer tools are often used to control numerous simultaneousoperations. With experience, you will learn the benefits and advantages of using timer tools.

    Animation Techniques

    yOne of the more fun things to do with Visual Basic programs is to create animated graphics. We'lllook at a few simple animation techniques here. I'm sure you'll come up with other ideas foranimating your application.

    yOne of the simplest animation effects is a chieved by toggling between two images. For example,you may have a picture of a stoplight with a red light. By quickly changing this picture to one with agreen light, we achieve a dynamic effect - animation. Picture boxes and image boxes are used to

    achieve this effect.

    yAnother approach to animation is to rotate through several pictures - each a slight change in theprevious picture - to obtain a longer animation. This is the principle motion pictures are based on -pictures are flashed by us at 24 frames per second and our eyes are tricked into believing things aresmoothly moving.

    Control arrays are usually used to achieve this type of animation.

  • 8/3/2019 Database Structure and Terminology

    11/11

    yMore elaborate effects can be achieved by moving an image while, at the same, time changing thedisplayed picture. Effects such as a little guy walking across the screen are easily achieved. An objectis moved using the Move method. You can do both absolute and relative motion (using an object'sLeft and Top properties).