0% found this document useful (0 votes)
144 views

Database Structure and Terminology

The document discusses database structure and terminology, the ADO data control, assigning tables to the data control using record sources, using bound data tools to connect controls to database fields, and finding specific records programmatically. It explains that a database contains tables with records and fields, the ADO data control connects a Visual Basic application to a database, tables are assigned via the record source property using SQL queries, controls can be bound to display and edit database fields, and records can be navigated or found using methods that operate on the data control's recordset property.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
144 views

Database Structure and Terminology

The document discusses database structure and terminology, the ADO data control, assigning tables to the data control using record sources, using bound data tools to connect controls to database fields, and finding specific records programmatically. It explains that a database contains tables with records and fields, the ADO data control connects a Visual Basic application to a database, tables are assigned via the record source property using SQL queries, controls can be bound to display and edit database fields, and records can be navigated or found using methods that operate on the data control's recordset property.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Database Structure and Terminology yIn simplest terms, a database is a collection of information.

This collection is stored in well-defined tables, or matrices.  yThe rows in a database table are used to describe similar items. The rows are referred to as database 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 are called database fields. Each field contains one specific piece of information. In defining a database field, 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 Basic application and a database. It can be used without writing any code at all! Or, it can be a central part of a complex database management system. This icon may not appear in your Visual Basic toolbox. If it doesnt, select Project from the main menu, then click Components. The Components window will appear. Select Microsoft ADO Data Control, 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 for small databases. You might like to study it on your own.  yThe data control (or tool) can access databases created by several other programs besides Visual Basic (or Microsoft Access). Some other formats supported include Btrieve, dBase, FoxPro, and Paradox 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 makes databases read-only). Record set A set of records defined by a data controls Connection String and Record Source properties. 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 the current 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 to a 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

Microsoft Access database using a data link. A data link is a file with a UDL extension that contains information on database type.  yIf your database does not have a data link, you need to create one. This process is best illustrated by example. We will be using the BIBLIO.MDB database in our first example, so these steps show you 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 Data Link. 4. Rename the newly created file BIBLIO.UDL 5. Right-click this new UDL files and clicks Properties. 6. Choose the Provider tab 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 file which 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 can be 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. Click OK. 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 or the 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 is SQL (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 that question 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 data control. We wont be learning any SQL here. There are many texts on the subject - in fact; many of them are in the BIBLIO.MDB database weve been using. Here we simply show you how to use SQL to have the data control point to an inherent database table. yClick on the ellipsis next to RecordSource in the property box. A Property Pages dialog box will appear. In the box marked Command Text (SQL), type this line: SELECT * FROM Table Name This will select all fields (the * is a wildcard) from a table named Table Name in the database. Click OK. ySetting the Record Source property also establishes the Record set property, which we will see later is a very important property.  Bound Data Tools yMost of the Visual Basic tools weve studied can be used as bound, or data aware, tools (or controls). That means, certain tool properties can be tied to a particular database field. To use a bound 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. Text Box Can be used to provide read/write access to a specified text data field. Probably, the most widely used data bound tool. Check Box Used to provide read/write access to a Boolean field. Combo Box Can be used to provide read/write access to a text data field. List Box Can be used to provide read/write access to a text data field. Picture Box Used 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 Box Used to display a graphical image from a bitmap, icon, or metafile on your form (uses fewer resources than a picture box). Provides read/write access to an image/binary data field.

yThere are also three custom data aware tools, the Data Combo (better than using the bound combo box), Data List (better than the bound list box), and Data 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 a form: 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 the selected data control records. Make your choice. 4. Set all other properties, as required. Finding Specific Records yIn addition to using the data control to move through database records, we can write Visual Basic code to accomplish the same, and other, tasks. This is referred to as programmatic control. In fact, many times the data control Visible 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 replicate the 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 positioned before any data. The EOF property is True when the current record has been positioned past the end of the data. If either property is true, the current record is invalid. If both properties are true, then there is no data in the database table at all.  yThese properties, and the programmatic control methods, operate on the Record set property of the data control. Hence, to move to the first record in a table attached to a data control named dtaExample, 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 be concerned 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 WHERE clause in SQL. We wont go into much detail 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 >= S Note the use of single quotes around the search letter. Single quotes are used to enclose strings in Criteria statements. Three logical operators can be used: equals (=), greater than (>), and less than (<). yThe Number Skipped argument tells how many records to skip before beginning the Find. This can be used to exclude the current record by setting Number Skipped to 1. yThe Search Direction argument has two possible values: adSearchForward or adSearchBackward. Note, in conjunction with the four Move methods, the Search Direction

argument can be used to provide a variety of search types (search from the top, search from the bottom, etc.) yIf a search fails to find a record that matches the criteria, the Record sets EOF or BOF property is set to True (depending on search direction). Another property used in searches is the Bookmark property. This allows you to save the current record pointer in case you want to return to that 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 a database. The power of Visual Basic lies in its ability to manipulate records in code. Such tasks as determining the values of particular fields, adding records, deleting records, and moving from record to 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 to change. Fortunately, Visual Basic helps us out here. The Visual Data Manager is a Visual Basic Add-In that allows the creation and management of databases. It is simple to use and can create a database compatible with the Microsoft Jet (or Access) database engine. yTo examine an existing database using the Data Manager, follow these steps: 1. Select Visual Data Manager from Visual Basics Add-In menu (you may be asked if you want to add SYSTEM.MDA to the .INI file answer no.) 2. Select Open Database from the Data Manager File 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 various tables. You can search for particular records. You can apply SQL queries. You can add/delete records. The Data Manager is a DBMS in itself. You might try using the Data Manager to look through the BIBLIO.MDB example database. yTo create a new database, follow these steps: 1. Select Visual Data Manager from 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 Manager File menu. Choose database type (Microsoft Access, Version 7.0), then select a directory and enter a name for your database file. Click OK. 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, then entering a field name, selecting a data type, and specifying the size of the field, if required. Once the field is defined, click the OK button to add it to the field box. Once all fields are defined, click the Build the Table 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 to use it as a database management system (DBMS). Nor, would we expect users of our programs to have the Data Manager available for their use. The next step in our development of our database skills is to use Visual Basic 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 be able 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 be done 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 with the 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 the current record. Delete The current record is deleted from the table. This method must be immediately followed by one of the Move methods because the current record is invalid after a Delete. Update Saves the current contents of all bound tools. 

yTo edit an existing record, you simply display the record and make any requiredchanges. The Lock Type property should be set to adLockPessimistic (locks each record as it is edited). Then, when you move off of that record, either with a navigation button or through some other action, Visual Basic will automatically update the record. If desired, or needed, you may invoke the Update method to force an update (use Lock Type = asLockOptimistic). For a data control named dtaExample, the syntax for this statement is:  dtaExample.Recordset.Update yTo add a record to the database, we invoke the AddNew method. The syntax for our example data control is: dtaExample.Recordset.AddNew This statement will blank out any bound data tools and move the current record to the end of the database. At this point, you enter the new values. When you moveoff of this record, the changes are automatically made to the database. Another way 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 of the data control to insure proper sorting (established by RecordSource SQL statement) of the new entry. The format is: dtaExample.Refresh yTo delete a record from the database, make sure the record to delete is the current 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 record because it no longer exists and an error will occur if we dont move. This gets particularly tricky if deleting the last record (check the EOF property). If EOF is true, you must move to the top of the database (Move First). You then must make sure there is a valid record there (check the BOF property). 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 Visual Basic 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 in the toolbox, select Project from the main menu, then click Components. Select Microsoft DataList Controls 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, and grid 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 eld from a specified data control. Selections from the list box can then be used to update another field from 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 A text 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 Box is nearly identical to the DataList box, hence we wont look at a separate set of properties. The only differences between the two tools is that, with the Data Combo box, the list portion appears as a drop-down box and the user is given the opportunity to change the contents of the returned Text property. yData Grid Tool:

The Data Grid tool is, by far, the most useful of the custom data bound tools. It can display an entire database 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 a separate, highly functional program. The only property well be concerned with is the DataSource property, which, as always, identifies the table associated with the respective data control. Refer to the Visual Basic Programmers Guide and other references for complete details on using the Data Grid control. 

Database Access and Management 8-35


As an example of the power of the DataGrid control, heres what is obtained by simply setting the DataSource property to the dtaExample data control, which is bound to the Titles table in the BIBLIO.MDB database: At this point, we can scroll through the table and edit any values we choose. Any changes are automatically 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 have the 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 is designed within Visual Basic and is used to tell the data report what is in the database. Second, we create the Data Report itself. This, too, is done within Visual Basic. The Data Environment and Data Report files then become part of the Visual Basic project developed as a database management system. yThe Visual Basic 6.0 data report capabilities are vast and using them is a detailed process. The use of these capabilities is best demonstrated by example. We will look at the rudiments of report creation by 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 within a form). With these methods, we can draw lines, boxes, and circles. Before discussing the commands that 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, it stays there. Windows is a multi-tasking environment. If you switch from a Visual Basic application to some other application, your Visual Basic form may become partially obscured. When you return to your Visual Basic application, you would like the form to appear like it did before being covered. All controls 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 proper screen management.  yThe simplest way to maintain graphics is to set the form or picture box's AutoRedraw property to True. In this case, Visual Basic always maintains a copy of graphics output in memory (creates persistent graphics). Another way to maintain drawn graphics is (with AutoRedraw set to False) to put all graphics commands in the form or picture box's Paint event. This event is called whenever an obscured 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 Paint event. yPSet Method: To set a single point in a graphic object (form or picture box) to a particular color, use the PSet method. 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 Color is the point color (discussed in the next section). If the ObjectName is omitted, the current form is assumed to be the object. If Color is omitted, the object's ForeColor property establishes the color. PSet is usually used to initialize some further drawing process. yLine Method:

The Line method is very versatile. We can use it to draw line segments, boxes, and filled boxes. To draw a line, the syntax is: ObjectName.Line (x1, y1) - (x2, y2), Color where Object Name is the object name, (x1, y1) the starting coordinate, (x2, y2) the ending coordinate, and Color the line color. Like PSet, if Object Name is omitted, drawing is done to the current form and, if Color is omitted, the objects Fore Color property 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 is provided, printing is to the current form. Information will print beginning at the object's CurrentX and CurrentY value. The color used is specified by the object's ForeColor property and the font is specified by the object's Font characteristics. 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 the lowest 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 via other object properties. Consult on-line help for further information. Using Colors yNotice that all the graphics methods can use a Color argument. If that argument is omitted, the ForeColor property 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, one way 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 represent some basic colors. Any of these constants can be used as a Color argument. Constant Value Color vbBlack 0x0 Black vbRed 0xFF Red vbGreen 0xFF00 Green vbYellow 0xFFFF Yellow vbBlue 0xFF0000 Blue vbMagenta 0xFF00FF Magenta vbCyan 0xFFFF00 Cyan

vbWhite 0xFFFFFF White yQBColor Function: For Microsoft QBasic, GW-Basic and QuickBasic programmers, Visual Basic replicates the sixteen most used colors with the QBColor function. The color is specified by QBColor (Index), where the colors corresponding to the Index are: Index Color Index Color 0 Black 8 Gray 1 Blue 9 Light blue 2 Green 10 Light green 3 Cyan 11 Light cyan 4 Red 12 Light red 5 Magenta 13 Light magenta 6 Brown 14 Yellow 7 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 using RGB to specify the color property is: RGB (Red, Green, Blue) where Red, Green, and Blue are integer 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 a color value. yColor Examples: frmExample.BackColor = vbGreen picExample.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 performing graphics in Visual Basic. We've already used the mouse to Click and DblClick on objects. Here, we see 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 mouse cursor is over an object. The form of this procedure is: Sub ObjectName_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) . . End Sub The 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 Description vbLeftButton 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 the Shift arguments are: Symbolic Constant Value Description vbShiftMask 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 MouseDown event occurs. yMouseUp Event:

The MouseUp event is the opposite of the MouseDown event. It is triggered whenever a previously pressed mouse button is released. The procedure outline is: Sub ObjectName_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) .. End Sub The 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 was released.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. The procedure outline is: Sub ObjectName_MouseMove(Button As Integer, Shift As Integer, X As Single, 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 keys X, 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 pick up 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 application form.  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 other methods. Examples include dragging a file to another folder or dragging a document to a printer queue. yAny Visual Basic object can be dragged and dropped, but we usually use picture and image boxes. The item being dragged is called the source object. The item being 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 in a bit) must be used. yDragDrop Event:  The Drag Drop event is triggered whenever the source object is dropped on the target object. The procedure 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.

yDrag Over Event: The Drag Over event is triggered when the source object is dragged over another object. Its procedure form is: Private Sub ObjectName_DragOver(Source As Control, X As Single, Y As Single, State As Integer) .. End Sub The first three arguments are the same as those for the Drag Drop event. The State 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 the application is running. yTimer tools work in the background, only being invoked at time intervals you specify. This is multitasking - 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 Enabled property 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 Sub This 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 to 1000. That timer tool's event procedure is then: Sub timExample_Timer () Beep End Sub yIn complicated applications; many timer tools are often used to control numerous simultaneous operations. 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'll look at a few simple animation techniques here. I'm sure you'll come up with other ideas for animating 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 a green 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 the previous 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 are smoothly moving. Control arrays are usually used to achieve this type of animation. 

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

You might also like