Properties, Methods and Events

Figure 1.15. Project Properties dialog box


1.7.8. Create EXE file

After setting up the startup form for the Project, to run a program, we use the Start button of Visual Basic or press the F5 key. However, when the program is completed, we need an executable file, or EXE file. Follow these steps: Step 1. From the File menu, select Make EXE file... The Make Project dialog box appears asking for a file name. Enter the file name (say Clipboard), Visual Basic will automatically add the .EXE extension and generate an executable file named Clipboard.EXE.

Figure 1.16. Make Project dialog box

Step 2. Click the Option button to open the Project Properties dialog box and enter the application name in the Title box. This name will be displayed in the list of applications when the program is executed. It is not necessary to name the application the same as the .EXE file name. Suppose we name the application: First Application.

Figure 1.17. Project Properties dialog box

B3. If you want to change the version of the application, you can change the values ​​in the Major, Minor and Revision boxes. Check Auto Increment and Visual Basic will automatically increase the Revision number each time the EXE file for the project is recreated. In addition, you can add notes for each version in the Version Information section. These notes include: the name of the agency or company, trademark, copyright information, etc. corresponding to the components in the list.

Step 4. Click OK to return to the Make Project dialog box.

Step 5. Click the OK button in the Make Project dialog box to create the EXE file.

Step 6. Run the program from My Computer or Explorer window, find the correct path to the file name and double-click on it.

1.8. Multiple choice questions

1) Choose the correct way to resize a control on a form:

a. Change the width and height attribute values.

b. Click on the 8 control boxes and drag and drop.

c. Hold down the Shift key and use the arrow keys.

d. All three of the above.

2) Choose the correct way to move the position of the control on the form:

a. Use the arrow keys.

b. Hold down the Ctrl key and use the arrow keys.

c. Hold down the Shift key and use the arrow keys.

d. Double-click the object.

3) Choose the correct way to select a control on a form:

a. Click on the object to select.

b. Hold down the Ctrl key and click on the objects you want to select.

c. Hold down the Shift key and click on the objects you want to select.

d. All three of the above.

4) Choose the correct way to place a control on a form:

a. Double-click the control.

b. Click the control and drag the mouse on the form.

c. Click on the same type of control on the form-> copy-> paste.

d. All three of the above.

CHAPTER 2

PROGRAMMING FUNDAMENTALS IN VISUAL BASIC 6.0

2.1. Properties, methods and events

Visual Basic 6.0 supports Object-Oriented Programming. With Object-Oriented Programming, programmers divide problems into objects. In Visual Basic, controls are objects. Each object has characteristics called properties and separate functions called methods. Programmers must provide properties and methods that the object should display.

2.1.1. Subject

An object is a concept that refers to an entity that exists in the real world that we can recognize, as well as distinguish it from other objects. Each object has characteristics that we call its own properties, based on these characteristics we can recognize, distinguish the object from other objects. In addition to properties, each object also has actions, reactions that are specific to each type and to each specific object that we call methods or events. For example: A TV is an object, it has the following properties: Brand, size, color, weight, number of channels, ... and methods: changing channels, scanning channels, adjusting colors, ...

Visual Basic provides many objects, in which controls are also objects, each object has its own set of properties, methods and events.

2.1.2. Properties

Attributes are characteristics of an object that describe the object. Although each object has a different set of attributes, there are some attributes that are common to most objects. For example, attributes define the name, size, location, color, etc. Here are some common attributes:


Properties

Explain

Left

The left edge position of the control relative to its container

Top

The position of the top edge of the control relative to its container

Height

Height of the control

Width

Width of the control

Maybe you are interested!

Gets a string value (name) used to refer to the control.

Enable

Gets a logical value (True or False) that determines whether the user can work with the control or not.

Visible

Gets a logical value (True or False) that determines whether the user

see control or not

Name


2.1.3. Method

It is a piece of program contained in an object that tells the object how to perform a certain task. Each object has its own methods, but there are also methods that are very common to most objects, such as:

Method

Explain

Move

Change the position of an object as required by the program

Drag

Execute user drag and drop operations

SetFocus

Provides sighting of the object specified in the call

method

ZOrder

Specifies the order in which controls appear on the screen.

2.1.4. Event

While properties describe objects and methods indicate how objects behave, events are the reactions of objects. For example, when the user clicks the left mouse button on a command button, the events: MouseDown, MouseUp, Click, and SetFocus occur. Similar to properties and methods, each object has a different set of events, but the following events are common to many objects, especially controls.

Event

Occurs when

Change

The user modifies the character string in the combo box or the

document

Click

The user uses the mouse button to click on the object.

Dblclick

The user uses the mouse button to double-click (click) on the object.

statue

DragDrop

The user drags an object to another location.

DragOver

The user drags an object across a control.

other

GotFocus

Bring an object into the user's view (focus)

KeyDown

The user presses a button on the keyboard while an object

statue in sight

The user presses and releases a button on the keyboard while an object is in view.

KeyUp

The user releases a key on the keyboard while an object

statue in sight

LostFocus

Take an object out of sight

MouseDown

The user presses any mouse button while the mouse pointer is

is lying on an object

MouseMove

The user moves the mouse pointer across an object.

MouseUp

The user releases the mouse button while the mouse pointer is

on an object

KeyPress


2.2. Introduce some common controls


2.2.1. Label Control

The Label control has an icon in the toolbox , the purpose of the Label is to display a paragraph of text on the Form. Some properties of the Label control:

Properties

Explain

Name

Used to name the Label control.

Alignment

Used to align the text content displayed on the Label: 0 : Left alignment

1 : Right Align

2: Center

Autosize

If the value is True, the size will automatically adjust to fit the content. If the value is False, the size will not be automatically adjusted.

ruler

BackColor

Set the background color of the Label

Caption

Defines the text content displayed on the Label

Font

Specifies the font style of the text displayed on the Label

ForeColor

Specifies the color of the text displayed on the Label

2.2.2. TextBox Control

The TextBox control has an icon in the toolbox called . The TextBox control is used to enter a paragraph of text, or to display a paragraph of text. Some properties of the TextBox:

Properties

Explain

Name

Used to name the TextBox control.



Alignment

Used to align the text content displayed on the TextBox: 0 : Left alignment

1 : Right Align

2: Center

Appearance

Specifies the display of TextBox: 0 – Flat : flat

1 – 3D : floating

BackColor

Specifies the background color of the TextBox

Font

Specifies the font style of the text displayed on the TextBox

ForeColor

Specifies the color of the text displayed on the TextBox

MaxLength

Specifies the maximum number of characters that can be entered into the TextBox.

MultiLine

If the value is True, the text on the Textbox can be displayed on multiple rows. If the value is False, the text will only be displayed on one row.

row.

ScrollBars

Determines whether the TextBox has scroll bars or not.

SelLength

Returns the length of the selected (highlighted) text in

Textbox

SelStart

Returns the position of the first character in the selected text.

in Textbox

SelText

Returns the selected text in the Textbox

Text

Defines the text content displayed on the TextBox

Visible

Specifies whether the TextBox control is visible or not. True: Visible

False: Not visible

Some Events of TextBox control.

KeyPress Event

This event is fired when the user clicks on the TextBox. We can use the KeyPress event to control the data entered into the TextBox. The KeyPress event handler uses a parameter called KeyAscii, which is an integer representing the ASCII code of the character typed.

For example: We want the user to only enter numbers into the TextBox, then we use the following method: if the entered character is not in the number range, then assign the KeyAscii parameter to 0.

Private Sub Text1_KeyPress (KeyAscii As Integer)

If KeyAscii < Asc(“0”) Or KeyAscii > Asc(“9”) then KeyAscii = 0 „ cancel the key entered

Beep „ play error beep sound

End If End Sub

KeyDown, KeyUp Events

Each KeyPress event gives us a KeyDown/KeyUp event pair. The KeyDown/KeyUp event has 2 parameters: KeyCode and Shift. This event allows us to recognize special keys on the keyboard. In the example below, we display the names of the function keys that the user of the program presses:

Private Sub Text3_KeyDown(KeyCode As Integer, Shift As Integer) If (KeyCode >= 112) And (KeyCode <= 123) Then

MsgBox "You just entered the function key: F" & _ Trim(Str(KeyCode - 111))

EndIf End Sub

2.2.3. CommandButton Control

The CommandButton control has an icon in the toolbox . CommandButton is a command button that we can click on, when it will perform a certain action. Some common properties of CommandButton:

Properties

Explain

Name

Used to name the CommandButton control.

Caption

Defines the title of the command button

Font

Specifies the font style of the title displayed on the command button.

Visible

Specifies whether the command button is displayed on the Form or not. If True: the command button is visible. If False: it is hidden.

go button


Note: Before a character of the title, if we put the "&" sign, when executing the program, the user only needs to press the Alt + character key combination, the computer will execute the event of pressing this command button.

2.2.4. Form

Application programs communicate with users through forms.

(also called a window, derived from the word Form or Windows); the controls placed on top help the form do its job. A form is a window programmed to display data and receive information from the user.

Comment


Agree Privacy Policy *