0% found this document useful (0 votes)
18 views19 pages

Visual Basic ActiveX Control Properties

This document covers the properties and functionalities of various ActiveX controls in Visual Basic, including Command Buttons, Option Buttons, Text Boxes, List Boxes, and Combo Boxes. It provides detailed explanations on how to set properties, handle events, and implement user interactions for each control type. Additionally, it includes example code snippets to demonstrate practical usage and application of these controls in a Visual Basic project.

Uploaded by

pn9smk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views19 pages

Visual Basic ActiveX Control Properties

This document covers the properties and functionalities of various ActiveX controls in Visual Basic, including Command Buttons, Option Buttons, Text Boxes, List Boxes, and Combo Boxes. It provides detailed explanations on how to set properties, handle events, and implement user interactions for each control type. Additionally, it includes example code snippets to demonstrate practical usage and application of these controls in a Visual Basic project.

Uploaded by

pn9smk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Third year (Visual basic )

Unit :4

Basic Active X-controls

1. Command button Control properties


2. Text box control properties
3. List box & combo box control properties
4. Scroll bar control properties
5. Slider control properties
6. Understanding visual data manager.

1. Command Button Controls Properties


Using Command Button controls is trivial. In most cases, you just draw the control on the form's
surface, set its Caption property to a suitable string (adding an & character to associate a hot key
with the control if you so choose), and you're finished, at least with user-interface issues. To
make the button functional, you write code in its Click event procedure, as in this fragment:

Private Sub Command1_Click()


' Save data, then unload the current form.
Call SaveDataToDisk
Unload Me
End Sub

You can use two other properties at design time to modify the behavior of a CommandButton
control. You can set the Default property to True if it's the default push button for the form (the
button that receives a click when the user presses the Enter key—usually the OK or Save button).
Similarly, you can set the Cancel property to True if you want to associate the button with the
Escape key.

The only relevant CommandButton's run-time property is Value, which sets or returns the state
of the control (True if pressed, False otherwise). Value is also the default property for this type
of control. In most cases, you don't need to query this property because if you're inside a button's
Click event you can be sure that the button is being activated. The Value property is useful only
for programmatically clicking a button:

This fires the button's Click event.


[Link] = True

The CommandButton control supports the usual set of keyboard and mouse events (KeyDown,
KeyPress, KeyUp, MouseDown, MouseMove, MouseUp, but not the DblClick event) and also
the GotFocus and LostFocus events, but you'll rarely have to write code in the corresponding
event procedures.

1
Third year (Visual basic )

Properties of a CommandButton control

 To display text on a CommandButton control, set its Caption property.


 An event can be activated by clicking on the CommandButton.
 To set the background colour of the CommandButton, select a colour in the BackColor
property.
 To set the text colour set the Forecolor property.
 Font for the CommandButton control can be selected using the Font property.
 To enable or disable the buttons set the Enabled property to True or False
 To make visible or invisible the buttons at run time, set the Visible property to True or
False.
 Tooltips can be added to a button by setting a text to the Tooltip property of the
CommandButton.
 A button click event is handled whenever a command button is clicked. To add a click event
handler, double click the button at design time, which adds a subroutine like the one given below.

Private Sub Command1_Click ( )


..................
End Sub

OptionButton Controls in VB6


OptionButton controls are also known as radio buttons because of their shape. You always use
OptionButton controls in a group of two or more because their purpose is to offer a number of
mutually exclusive choices. Anytime you click on a button in the group, it switches to a selected
state and all the other controls in the group become unselected.

Preliminary operations for an OptionButton control are similar to those already described for
CheckBox controls. You set an OptionButton control's Caption property to a meaningful string,
and if you want you can change its Alignment property to make the control right aligned. If the
control is the one in its group that's in the selected state, you also set its Valueproperty to True.
(The OptionButton's Value property is a Boolean value because only two states are possible.)
Value is the default property for this control.

At run time, you typically query the control's Value property to learn which button in its group
has been selected. Let's say you have three OptionButton controls, named optWeekly,
optMonthly, and optYearly. You can test which one has been selected by the user as follows:

If [Link] Then
' User prefers weekly frequency.
ElseIf [Link] Then
' User prefers monthly frequency.
ElseIf [Link] Then
' User prefers yearly frequency.
End If

2
Third year (Visual basic )

Strictly speaking, you can avoid the test for the last OptionButton control in its group because all
choices are supposed to be mutually exclusive. But the approach I just showed you increases the
code's readability.

A group of OptionButton controls is often hosted in a Frame control. This is necessary when
there are other groups of OptionButton controls on the form. As far as Visual Basic is concerned,
all the OptionButton controls on a form's surface belong to the same group of mutually exclusive
selections, even if the controls are placed at the opposite corners of the window. The only way to
tell Visual Basic which controls belong to which group is by gathering them inside a Frame
control. Actually, you can group your controls within any control that can work as a container—
PictureBox, for example—but Frame controls are often the most reasonable choice.

Example

Open a new Standard EXE project and the save the Form as [Link] and save the project as
[Link].

Design the Form as per the following specifications table.

Object Property Settings

Caption Enter a Number


Label
Name Label1
Text (empty)
TextBox
Name Text1
Caption &Close
CommandButton
Name Command1
Caption &Octal
OptionButton
Name optOct
Caption &Hexadecimal
OptionButton
Name optHex
Caption &Decimal
OptionButton
Name optDec

The application responds to the following events

 The change event of the TextBox reads the value and stores it in a form-level numeric
variable.
3
Third year (Visual basic )

 The click event of optOct button returns curretval in octal.


 The click event of the optHex button curerntval in hexadecimal
 The click event of the optDec button returns the decimal equivalent of the value held
currentval.

The following code is entered in the general declarations section of the Form.

Dim currentval as variant

The variable is initialized to 0 by default. The change event procedure checks to ascertain the
number system (Octal, Hexadecimal) that is in effect and then reads in the number.

Private Sub Text1_Change()


If [Link] = True Then
currentval = Val ("&O" & LTrim ([Link]) & "&")
Elseif [Link] = True Then
currentval = Val (LTrim ([Link]) & "&")
Else
currentval = Val ("&H" & LTrim ([Link]) & "&")
End if
End Sub

The Val function is used to translate string to a number and can recognize Octal and
Hexadecimal strings. The LTrim function trims the leading blanks in the text. The following
code is entered in the click events of the OptionButton controls.

Private Sub optOct_Click()


[Link] = Oct(currentval)
End Sub

Private Sub optHex_Click()


[Link] = Hex(currentval)
End Sub

Private Sub optDec_Click()


[Link] = Format(currentval)
End Sub

The follwoing code is entered in the click event of teh Close button.

Private Sub cmdClose_Click()


Unlod Me
End Sub

The Application is run by pressing F5 or clicking on the Run icon in the tool bar. By pressing the
Exit button the program is terminated.

4
Third year (Visual basic )

2. Text box control properties


TextBox controls offer a natural way for users to enter a value in your program. For this reason,
they tend to be the most frequently used controls in the majority of Windows applications.
TextBox controls, which have a great many properties and events, are also among the most
complex intrinsic controls. In this section, I guide you through the most useful properties of
TextBox controls and show how to solve some of the problems that you're likely to encounter.

Setting properties to a Textbox


 Text can be entered into the text box by assigning the necessary string to the text property
of the control
 If the user needs to display multiple lines of text in a TextBox, set the MultiLine property
to True
 To customize the scroll bar combination on a TextBox, set the ScrollBars property.
 Scroll bars will always appear on the TextBox when it's MultiLine property is set to True
and its ScrollBars property is set to anything except None(0)
 If you set the MultilIne property to True, you can set the alignment using the Alignment
property. The test is left-justified by default. If the MultiLine property is et to False, then setting
the Alignment property has no effect.

Run-Time Properties of a TextBox control


The Text property is the one you'll reference most often in code, and conveniently it's the default
property for the TextBox control. Three other frequently used properties are these:

 The SelStart property sets or returns the position of the blinking caret (the insertion
point where the text you type appears). Note that the blinking cursor inside TextBox and other
controls is named caret, to distinguish it from the cursor (which is implicitly the mouse cursor).
When the caret is at the beginning of the contents of the TextBox control, SelStart returns 0;
when it's at the end of the string typed by the user, SelStart returns the value Len(Text). You can
modify the SelStart property to programmatically move the caret.
 The SelLength property returns the number of characters in the portion of text that has
been highlighted by the user, or it returns 0 if there's no highlighted text. You can assign a
nonzero value to this property to programmatically select text from code. Interestingly, you can
assign to this property a value larger than the current text's length without raising a run-time
error.
 The SelText property sets or returns the portion of the text that's currently selected, or it
returns an empty string if no text is highlighted. Use it to directly retrieve the highlighted text
without having to query Text, SelStart, and SelLength properties. What's even more interesting is
that you can assign a new value to this property, thus replacing the current selection with your
own. If no text is currently selected, your string is simply inserted at the current caret position.

5
Third year (Visual basic )

When you want to append text to a TextBox control, you should use the following code (instead
of using the concatenation operator) to reduce flickering and improve performance:

[Link] = Len([Link])
[Link] = StringToBeAdded

One of the typical operations you could find yourself performing with these properties is
selecting the entire contents of a TextBox control. You often do it when the caret enters the field
so that the user can quickly override the existing value with a new one, or start editing it by
pressing any arrow key:

Private Sub Text1_GotFocus()


[Link] = 0
' A very high value always does the trick.
[Link] = 9999
End Sub

Always set the SelStart property first and then the SelLength or SelText properties. When you
assign a new value to the SelStart property, the other two are automatically reset to 0 and an
empty string respectively, thus overriding your previous settings.

The selected text can be copied to the Clipboard by using SelText:

[Link] text, [format]

In the above syntax, text is the text that has to be placed into the Clipboard, and format has three
possible values.

1. VbCFLink - conversation information


2. VbCFRTF - Rich Text Format
3. VbCFText - Text

We can get text from the clipboard using the GetText() function this way:

[Link] ([format])

The following Figure summarizes the common TextBox control's properties and methods.

Property/ Method Description


Properties
Enabled specifies whether user can interact with this control or not
Index Specifies the control array index
If this control is set to True user can use it else if this control is set to
Locked
false the control cannot be used

6
Third year (Visual basic )

Specifies the maximum number of characters to be input. Default


MaxLength
value is set to 0 that means user can input any number of characters
Using this we can set the shape of the mouse pointer when over a
MousePointer
TextBox
By setting this property to True user can have more than one line in
Multiline
the TextBox
PasswordChar This is to specify mask character to be displayed in the TextBox
ScrollBars This to set either the vertical scrollbars or horizontal scrollbars to
make appear in the TextBox. User can also set it to both vertical and
horizontal. This property is used with the Multiline property.
Text Specifies the text to be displayed in the TextBox at runtime
ToolTipIndex This is used to display what text is displayed or in the control
By setting this user can make the Textbox control visible or invisible
Visible
at runtime
Method
SetFocus Transfers focus to the TextBox
Event procedures
Change Action happens when the TextBox changes
Click Action happens when the TextBox is clicked
GotFocus Action happens when the TextBox receives the active focus
LostFocus Action happens when the TextBox loses it focus
KeyDown Called when a key is pressed while the TextBox has the focus
KeyUp Called when a key is released while the TextBox has the focus

3. List box & combo box control properties


ListBox and ComboBox controls present a set of choices that are displayed vertically in a
column. If the number of items exceed the value that be displayed, scroll bars will automatically
appear on the control. These scroll bars can be scrolled up and down or left to right through the
list.

The following Fig lists some of the common ComboBox properties and methods.

Property/Method Description
Properties
By setting this property to True or False user can decide whether user can
Enabled
interact with this control or not

7
Third year (Visual basic )

Index Specifies the Control array index


String array. Contains the strings displayed in the drop-down list. Starting
List
array index is 0.
ListCount Integer. Contains the number of drop-down list items
Integer. Contains the index of the selected ComboBox item. If an item is
ListIndex
not selected, ListIndex is -1
Locked Boolean. Specifies whether user can type or not in the ComboBox
Integer. Specifies the shape of the mouse pointer when over the area of
MousePointer
the ComboBox
Integer. Index of the last item added to the ComboBox. If the ComboBox
NewIndex
does not contain any items , NewIndex is -1
Sorted Boolean. Specifies whether the ComboBox's items are sorted or not.
Style Integer. Specifies the style of the ComboBox's appearance
TabStop Boolean. Specifies whether ComboBox receives the focus or not.
Text String. Specifies the selected item in the ComboBox
ToolTipIndex String. Specifies what text is displayed as the ComboBox's tool tip
Visible Boolean. Specifies whether ComboBox is visible or not at run time
Methods
AddItem Add an item to the ComboBox
Clear Removes all items from the ComboBox
RemoveItem Removes the specified item from the ComboBox
SetFocus Transfers focus to the ComboBox
Event Procedures
Change Called when text in ComboBox is changed
DropDown Called when the ComboBox drop-down list is displayed
GotFocus Called when ComboBox receives the focus
LostFocus Called when ComboBox loses it focus

Adding items to a List


It is possible to populate the list at design time or run time

Design Time : To add items to a list at design time, click on List property in the property box
and then add the items. Press CTRL+ENTER after adding each item as shown below.

8
Third year (Visual basic )

Run Time : The AddItem method is used to add items to a list at run time. The AddItem method
uses the following syntax.

[Link], Index

The item argument is a string that represents the text to add to the list

The index argument is an integer that indicates where in the list to add the new item. Not giving
the index is not a problem, because by default the index is assigned.

Following is an example to add item to a combo box. The code is typed in the Form_Load event

Private Sub Form_Load()

[Link] 1
[Link] 2
[Link] 3
[Link] 4
[Link] 5
[Link] 6

End Sub

Removing Items from a List


The RemoveItem method is used to remove an item from a list. The syntax for this is given
below.

[Link] index

The following code verifies that an item is selected in the list and then removes the selected item
from the list.

Private Sub cmdRemove_Click()


If [Link] > -1 Then
[Link] List1. ListIndex
End If
End Sub

9
Third year (Visual basic )

Sorting the List


The Sorted property is set to True to enable a list to appear in alphanumeric order and False to
display the list items in the order which they are added to the list.

Using the ComboBox


A ComboBox combines the features of a TextBox and a ListBox. This enables the user to select
either by typing text into the ComboBox or by selecting an item from the list. There are three
types of ComboBox styles that are represented as shown below.

Dropdown Simple combo


Dropdown list
combo

 Dropdown Combo (style 0)


 Simple Combo (style 1)
 Dropdown List (style 2)

The Simple Combo box displays an edit area with an attached list box always visible
immediately below the edit area. A simple combo box displays the contents of its list all the
time. The user can select an item from the list or type an item in the edit box portion of the
combo box. A scroll bar is displayed beside the list if there are too many items to be displayed in
the list box area.

The Dropdown Combo box first appears as only an edit area with a down arrow button at the
right. The list portion stays hidden until the user clicks the down-arrow button to drop down the
list portion. The user can either select a value from the list or type a value in the edit area.

The Dropdown list combo box turns the combo box into a Dropdown list box. At run time , the
control looks like the Dropdown combo box. The user could click the down arrow to view the
list. The difference between Dropdown combo & Dropdown list combo is that the edit area in the
Dropdown list combo is disabled. The user can only select an item and cannot type anything in
the edit area. Anyway this area displays the selected item.

Example

This example is to Add , Remove, Clear the list of items and finally close the application.

10
Third year (Visual basic )

 Open a new Standard EXE project is opened an named the Form as [Link] and save
the project as [Link]
 Design the application as shown below.

Object Property Settings


Caption ListBox
Form
Name frmListBox
Text (empty)
TextBox
Name txtName
Caption Enter a name
Label
Name lblName
ListBox Name lstName
Caption Amount Entered
Label
Name lblAmount
Caption (empty)

Label Name lblDisplay

Border Style 1 Fixed Single


Caption Add
CommandButton
Name cmdAdd
Caption Remove
CommandButton
Name cmdRemove
Caption Clear
CommandButton
Name cmdClear
Caption Exit
CommandButton
Name cmdExit

11
Third year (Visual basic )

The following event procedures are entered for the TextBox and CommandButton controls.

Private Sub txtName_Change()


If (Len([Link]) > 0) Then 'Enabling the Add button
'if atleast one character
'is entered
[Link] = True
End If
End Sub

Private Sub cmdAdd_Click()


[Link] [Link] 'Add the entered the characters to the list box

[Link] = "" 'Clearing the text box

[Link] 'Get the focus back to the


'text box

[Link] = [Link] 'Display the number of items in the list box

[Link] = False ' Disabling the Add button

End Sub

The click event of the Add button adds the text to the list box that was typed in the Text box.
Then the text box is cleared and the focus is got to the text box. The number of entered values
will is increased according to the number of items added to the listbox.

Private Sub cmdClear_Click()


[Link]
[Link] = [Link]
End Sub

12
Third year (Visual basic )

Private Sub cmdExit_Click()


Unload Me
End Sub

Private Sub cmdRemove_Click()


Dim remove As Integer

remove = [Link] 'Getting the index

If remove >= 0 Then 'make sure an item is selected


'in the list box

[Link] remove 'Remove item from the list box

[Link] = [Link] 'Display the number of items


'in the listbox

End If

End Sub

Remove button removes the selected item from the list as soon as you pressed the Remove
button. The number of items is decreased in the listbox and the value is displayed in the label.

The code for the clear button clears the listbox when you press it. And the number of items
shown in the label becomes 0.

4. Scroll bar control properties


The ScrollBar is a commonly used control, which enables the user to select a value by positioning it at the
desired location. It represents a set of values. The Min and Max property represents the minimum and
maximum value. The value property of the ScrollBar represents its current value, that may be any integer
between minimum and maximum values assigned.

The HScrollBar and the VScrollBar controls are perfectly identical, apart from their different orientation.
After you place an instance of such a control on a form, you have to worry about only a few properties:
Min and Max represent the valid range of values, SmallChange is the variation in value you get when
clicking on the scroll bar's arrows, and LargeChange is the variation you get when you click on either side
of the scroll bar indicator. The default initial value for those two properties is 1, but you'll probably have
to change LargeChange to a higher value. For example, if you have a scroll bar that lets you browse a
portion of text, SmallChange should be 1 (you scroll one line at a time) and LargeChange should be set to
match the number of visible text lines in the window.

13
Third year (Visual basic )

The most important run-time property is Value, which always returns the relative position of the indicator
on the scroll bar. By default, the Min value corresponds to the leftmost or upper end of the control:

' Move the indicator near the top (or left) arrow.
[Link] = [Link]
' Move the indicator near the bottom (or right) arrow.
[Link] = [Link]

While this setting is almost always OK for horizontal scroll bars, you might sometimes need to reverse
the behavior of vertical scroll bars so that the zero is near the bottom of your form. This arrangement is
often desirable if you want to use a vertical scroll bar as a sort of slider. You obtain this behavior by
simply inverting the values in the Min and Max properties. (In other words, it's perfectly legal for Min to
be greater than Max.)

There are two key events for scrollbar controls: the Change event fires when you click on the scroll bar
arrows or when you drag the indicator; the Scroll event fires while you drag the indicator. The reason for
these two distinct possibilities is mostly historical. First versions of Visual Basic supported only the
Change event, and when developers realized that it wasn't possible to have continuous feedback when
users dragged the indicator, Microsoft engineers added a new event instead of extending the Change
event. In this way, old applications could be recompiled without unexpected changes in their behavior. At
any rate, this means that you must often trap two distinct events:

' Show the current scroll bar's value.


Private VScroll1_Change()
[Link] = [Link]
End Sub
Private VScroll1_Scroll()
[Link] = [Link]
End Sub

The example shown in the following figure uses three VScrollBar controls as sliders to control the
individual RGB (red, green, blue) components of a color. The three scroll bars have their Min property set
to 255 and their Max property set to 0, while their SmallChange is 1 and LargeChange is 16. This
example is also a moderately useful program in itself because you can select a color and then copy its
numeric value to the clipboard and paste it in your application's code as a decimal value, a hexadecimal
value, or an RGB function.

14
Third year (Visual basic )

Use scrollbar controls to visually create colors.

Scrollbar controls can receive the input focus, and in fact they support both the TabIndex and TabStop
properties. If you don't want the user to accidentally move the input focus on a scrollbar control when he
or she presses the Tab key, you must explicitly set its TabStop property to False. When a scrollbar control
has the focus, you can move the indicator using the Left, Right, Up, Down, PgUp, PgDn, Home, and End
keys. For example, you can take advantage of this behavior to create a read-only TextBox control with a
numeric value that can be edited only through a tiny companion scroll bar. This scroll bar appears to the
user as a sort of spin button, as you can see in the figure below. To make the trick work, you need to write
just a few lines of code:

Private Sub Text1_GotFocus()


' Pass the focus to the scroll bar.
[Link]
End Sub
Private Sub VScroll1_Change()
' Scroll bar controls the text box value.
[Link] = [Link]
End Sub

You don't need external ActiveX controls to create functional spin buttons

Scrollbar controls are even more useful for building scrolling forms, like the one displayed in Figure 3-15.
To be certain, scrolling forms aren't the most ergonomic type of user interface you can offer to your
customers: If you have that many fields in a form, you should consider using a Tab control, child forms,
or some other custom interface. Sometimes, however, you badly need scrollable forms, and in this
situation you are on your own because Visual Basic forms don't support scrolling.

15
Third year (Visual basic )

Fortunately, it doesn't take long to convert a regular form into a scrollable one. You need a couple of
scrollbar controls, plus a PictureBox control that you use as the container for all the controls on the form,
and a filler control—a CommandButton, for example—that you place in the bottom-right corner of the
form when it displays the two scroll bars. The secret to creating scrollable forms is that you don't move all
the child controls one by one. Instead, you place all the controls in the PictureBox control (named
picCanvas in the following code), and you move it when the user acts on the scroll bar:

Sub MoveCanvas()
[Link] -[Link], -[Link]
End Sub

In other words, to uncover the portion of the form near the right border, you assign a negative value to the
PictureBox's Left property, and to display the portion near the form's bottom border you set its Top
property to a negative value. It's really that simple. You do this by calling the MoveCanvas procedure
from within the scroll bars' Change and Scroll events. Of course, it's critical that you write code in the
Form_Resize event, which makes a scroll bar appear and disappear as the form is resized, and that you
assign consistent values to Max properties of the scrollbar controls:

' size of scrollbars in twips


Const SB_WIDTH = 300 ' width of vertical scrollbars
Const SB_HEIGHT = 300 ' height of horizontal scrollbars

Private Sub Form_Resize()


' Resize the scroll bars along the form.
[Link] 0, ScaleHeight - SB_HEIGHT, ScaleWidth - SB_WIDTH
[Link] ScaleWidth - SB_WIDTH, 0, SB_WIDTH, _
ScaleHeight - SB_HEIGHT
[Link] ScaleWidth - SB_WIDTH, ScaleHeight - SB_HEIGHT, _
SB_WIDTH, SB_HEIGHT

' Put these controls on top.


[Link]
[Link]
[Link]
[Link] = 0

' A click on the arrow moves one pixel.


[Link] = ScaleX(1, vbPixels, vbTwips)
[Link] = ScaleY(1, vbPixels, vbTwips)
' A click on the scroll bar moves 16 pixels.
[Link] = [Link] * 16
[Link] = [Link] * 16

' If the form is larger than the picCanvas picture box,


' we don't need to show the corresponding scroll bar.
If ScaleWidth < [Link] + SB_WIDTH Then
[Link] = True
[Link] = [Link] + SB_WIDTH - ScaleWidth
Else
[Link] = 0

16
Third year (Visual basic )

[Link] = False
End If
If ScaleHeight < [Link] + SB_HEIGHT Then
[Link] = True
[Link] = [Link] + SB_HEIGHT - ScaleHeight
Else
[Link] = 0
[Link] = False
End If
' Make the filler control visible only if necessary.
[Link] = ([Link] Or [Link])
MoveCanvas
End Sub

Working with scrollable forms at design time isn't comfortable. I suggest that you work with a maximized
form and with the PictureBox control sized as large as possible. When you're finished with the form
interface, resize the PictureBox control to the smallest area that contains all the controls, and then reset
the form's WindowState property to 0-Normal.

5. Slider control properties

17
Third year (Visual basic )

6. Understanding visual data manager

At 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).

• We don’t want to change the example database, [Link]. Let’s 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.

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

1. Select Visual Data Manager from Visual Basic’s Add-In menu (you may be asked
if you want to add [Link] 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.

18
Third year (Visual basic )

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 [Link] example database.

• To create a new database, follow these steps:

1. Select Visual Data Manager from Visual Basic’s Add-In menu (you may be
asked if you want to add [Link] 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 table’s 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.

19

You might also like