to.. ELA Web Portal to.. ELA Notes

ELA NOTES on Visual Basic

ACRONYMS: ADO - ActiveX Data Objects; RDO - Remote Data Objects

CONTENTS
Application Development | Application Structure |
DataEnvironment Object Design |
Properties - Setting |
Recordset |

Access-Microsoft
Parameter Object & Collection Example


Oracle & SQL Server
SQL Editor |


Designing a DataEnvironment Object
At design time, you can use the Data Environment designer to create a DataEnvironment 
object. The DataEnvironment object can include Connection and Command objects, hierarchies 
(relationships between Command objects), groupings, and aggregates. Before designing your 
DataEnvironment object, you should determine what information you want to present, identify 
the databases that contain the information, and determine your run-time objective (for 
example, creating a Data Report or Hierarchical FlexGrid control).

Before you can access the Data Environment designer, you must reference it in Visual Basic.

To reference the Data Environment designer 

On the Project menu, click References.

From the References dialog box, select Data Environment 1.0, and then click OK. 
To add a Data Environment designer object to a new Visual Basic project 

From the New tab of the New Project dialog box, choose Standard EXE project, and 
then click Open.

From the Project menu, choose Add Data Environment.

The Data Environment designer window appears, and a Connection object is added to your 
Data Environment.

With this Data Environment designer added to your project, you can create a Connection; 
see the procedure in Connection Objects. Once a Connection is created, you can add Commands 
to it; see the procedure in Command Objects.
Developing an Application
Three main steps: 

1. Create the interface.
2. Set properties.
3. Write code.

Forms are the foundation for creating the interface.  They are used to add windows and 
dialog boxes or used as containers for items that are not visible through the interface. 
For example, a form in your might serve as a container for graphics that you plan to 
display in other forms.

To draw a control using the Toolbox, click the tool for the control you choose to draw — 
such as the text box. Move the pointer onto your form. The pointer becomes a cross hair. 
Place the cross hair where you want the upper-left corner of the control, drag the cross 
hair until the control is the size you want and release the mouse button. The control 
appears on the form.

Double-clicking the control in the Toolbox also creates a default-size control located in 
the center of the form, that can then be moved and resized.

To move a control use the mouse to drag the control, use the Properties window to change 
the Top and Left properties, use CTRL with the arrow keys to move one grid unit at a time. 
If the grid is turned off, the control moves one pixel at a time.
Parameter Object, Parameters Collection Example (Microsoft Access)
The following example creates a new parameter query and supplies values for the parameters:

Sub NewParameterQuery()
	Dim dbs As Database, qdf As QueryDef, rst As Recordset
	Dim prm As Parameter, strSQL As String

	' Return reference to current database.
	Set dbs = CurrentDb
	' Construct SQL string.
	strSQL = "PARAMETERS [Beginning OrderDate] DateTime, " _
		& "[Ending OrderDate] DateTime; SELECT * FROM Orders " & _
		"WHERE (OrderDate Between[Beginning OrderDate] " _
		& "And [Ending OrderDate]);"
	' Create new QueryDef object.
	Set qdf = dbs.CreateQueryDef("ParameterQuery", strSQL)

' Supply values for parameters.
	qdf.Parameters![Beginning OrderDate] = #4/1/95#
	qdf.Parameters![Ending OrderDate] = #4/30/95#
	' Open recordset on QueryDef object.
	Set rst = qdf.OpenRecordset
	rst.MoveLast
	MsgBox "Query returned " & rst.RecordCount & " records."
	rst.Close
	Set dbs = Nothing
End Sub
Recordset
Any of the following syntax forms may be used to refer to a Recordset object within a 
collection, by ordinal number or Name property:

Recordsets(0)

Recordsets("name")

Recordsets![name]
Setting Properties
To open the Properties window, choose View menu -> Properties Window, or on the toolbar 
click the Properties Window button, or use the control's context menu by right clicking it.
The SQL Editor
The SQL Editor allows you to create and edit stored procedures and triggers in both SQL 
Server and Oracle from within the Visual Basic development environment. The topics listed 
below give you an overview of using the SQL Editor.

Stored Procedures

Triggers in the SQL Editor

The T-SQL Debugger
The Structure of a Visual Basic Application
For each form , there is a related form module (file extension .frm) that contains its 
code. Each form module contains event procedures — sections of code that respond to events.  
Forms also contain controls, each with a set of event procedures. Form modules can also contain 
general procedures executed in response to a call from an event procedure.

A standard module (.BAS) contains code unrelated to a specific form or control. Its 
procedures can be used in response to events in several different objects, rather than 
duplicating the code for each object. A standard module contains only code, as opposed to..

A class module (.CLS) contains both code and data, and is used to create objects that 
can be called from procedures. It is a control without a physical representation.

By default, your project contains a single form module. You can add additional form, class, 
and standard modules, as needed. Class modules are discussed in "Programming with Objects."