0% found this document useful (0 votes)
6 views9 pages

Chapter Two-VISUAL

This document is a lecture on Visual Basic 6, focusing on forms, tools, and their properties. It explains the types of tools available, such as internal tools and Active X Control Tools, and provides examples of how to manipulate properties and handle user input through various controls. Additionally, it covers conditional statements and event handling for user interactions.
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)
6 views9 pages

Chapter Two-VISUAL

This document is a lecture on Visual Basic 6, focusing on forms, tools, and their properties. It explains the types of tools available, such as internal tools and Active X Control Tools, and provides examples of how to manipulate properties and handle user input through various controls. Additionally, it covers conditional statements and event handling for user interactions.
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
You are on page 1/ 9

ALKUNOOZE UNIVERSITY COLLEGE

DEPARTMENT OF MEDICAL INSTRUMENTS


TECHNOLOTGE ENGINEERING

VISUAL BASIC

ACADEMIC RESPONSIBLE: DOAA ABDUL MOHSEN


2023/2024
Chapter Two Visual Basic 6

Lecturer: Duaa Abdul-Muhsin Second Class

Chapter Two: Forms and tools


A Forms is a Visual Basic term that is synonymous with a window in the Windows
operating system.
It is a window that you design and appears at execution time like all other
application program windows. As for tools, they are objects that are placed inside
models and embraced within them.

It is important to draw attention to the existence of two types of tools:


1- Internal tools: These are the twenty tools that are in the toolbox when you
create a Standard EXE project.
2- Active X Control Tools: These are external tools with the OCX extension that
can be added by choosing the Components command from the Project menu
or by right-clicking on the toolbox and choosing the Components command.
All Forms and tools are considered objects, so there are three elements that control
these objects:
Properties, Forms, Events, and each of these objects has its own elements, but we
draw attention to the fact that there are many common elements between models and
the tools that are placed on them.

Common Properties:
A property is a value that affects either the appearance of the external object, such
as the BackColor property or the Font property, or its behavior, such as the Enabled
property.
The Properties window is the place where you can change the value of a property at
design time. At execution time, the properties are changed by writing the necessary
code for that, such as the following:

PictureBob1.BackColor=0
Label1.Caption="Welcome"
Or use the reserved word "With" to change a group of properties for a specific object
at once without repeatedly typing the object's name:

With text1
.text="Welcome"
.Font.Bold=True

pg. 1
Chapter Two Visual Basic 6

Lecturer: Duaa Abdul-Muhsin Second Class

.BackColor=VBBlack
.ForColor=VBWhite
EndWith

Some internal tools feature a default property that eliminates the need to write this
property after the object name. For example, the Caption property is the default
property for the Label tool, so we can write the following:

Label1="welcome"
Text1="First test"

As for the form window, you can access its properties without typing the form name
using the reserved word “Me” or even without typing it at all. All of the following
statements are true:

As for the form window, you can access its properties without typing the form name
using the reserved word Me or even without typing it at all. All of the following
statements are correct:

Form1.caption="XXXX"
Me.Caption="XXXX"
.Caption="XXXX"

checkbox tool:

This tool gives the user an opportunity to specify a specific option, either by
activating it or not. Therefore, this tool is easy to learn and important at the same
time. We will explain how to use it with an example, knowing that the activation
value is stored in the Value property, which takes one of the following values:
0- Unchecked
1- Checked
2- Grayed
Ex:
Private Sub Chcek1_Click

pg. 2
Chapter Two Visual Basic 6

Lecturer: Duaa Abdul-Muhsin Second Class

If Check1.Value=1 then
Image1.visible=True
End If
End Sub

OptionButton tool:
This tool is called Radio Button in some books, and its function is similar to the
checkbox tool, except that the value of the Value property here is True or False,
and you will not be able to make the Value equal to True for more than one radio
button only, so it is preferable to place these buttons in the Frame tool.

ListBox tool:
This widget displays a group of texts inside a box containing scrollBars. The
Sorted property sorts the widget's contents in ascending order based on its
alphabetical letters. You can fill the widget's contents at design time via the List
property or at runtime using the AddItem method.

List1.AddItem "Frist"
List1.AddItem "Second"

Note:
If you are going to add hundreds or thousands of elements at the time of execution,
it is recommended to hide the tool temporarily and after adding it, re-show the tool
again, because the tool automatically redraws itself when any element is added to it,
which causes the device to slow down and the tool itself to jitter.

List1.visible=False
For x=0 to 10000
List1.AddItem x
Next
Iist1.Visible=True
New items are added to the end of the series of items if the value of the Sorted
property is False. You can also delete an item from the list using the RemoveItem
property or delete all items using the Clear method.

List1.RemoveItem 0

pg. 3
Chapter Two Visual Basic 6

Lecturer: Duaa Abdul-Muhsin Second Class

List1.Clear

listIndex property:
It returns the value of the selected element in the tool and returns the value (-1) if
there is no selected element. As for the Text property, it returns the text of the
selected element.

list1.ListIndex=0
Print List1.text

listCount property:
This property returns the number of all existing items and is frequently used with the
List property, which enables you to access the item.

For x=0 to list1.listCout


Print list1.list(0)
Next
As for the MultiSelect property, the user can select several consecutive items in the
tool if its value is 1-Simple, or several non-consecutive items if its value is 2-
Extended.

ComboBox menu widget:


Most of the properties and methods of the previous listBox tool are present in the
ComboBox tool, because the ComboBox tool is the standard listBox tool, but it has
a text box above it. You can control the width of the text box in several ways using
the Style property.

1- If the value of the Style property is equal to 0-dropdown, the text tool will
appear with an arrow, and clicking on it will cause the second part of the tool
to appear.
2- If the value of the Style property is equal to 1-Simple, both parts will appear
to the user
3- If the value of the property is equal to 2-dropDown list, it is the same as the
first property or value, except that the user will not be able to write in the text
box.

pg. 4
Chapter Two Visual Basic 6

Lecturer: Duaa Abdul-Muhsin Second Class

Ex:
Private Sub Form1_Load()
Combo1.AddItem "Duaa"
Combo1.AddItem "Alrubaye"
End Sub

After placing the items in the list, one can be selected and a set of instructions can
be executed as a result of this selection

Private Sub Combo1_Click()


Select Case Combo1.ListIndex
Case 0
Instruction set
Case 1
Another set of instructions
End Select
End Sub

IF statement:

In Visual Basic 6, the If...Then...Else statement is used for conditional execution.


Here's a basic explanation of how it works:

If condition Then
' Code to be executed if the condition is True.
Else
' Code to be executed if the condition is False.
End If

• condition: This is the expression that evaluates to either True or False.


• If the condition is True, the code block immediately following the Then keyword
is executed.
• If the condition is False, the code block immediately following the Else keyword
(if present) is executed.

pg. 5
Chapter Two Visual Basic 6

Lecturer: Duaa Abdul-Muhsin Second Class

• The Else part is optional. If you don't need to execute any code when the
condition is False, you can omit it.
EX:
Dim num As Integer
num = 10

If num > 5 Then


MsgBox "The number is greater than 5"
Else
MsgBox "The number is not greater than 5"
End If

In this example, if the value of num is greater than 5, a message box saying "The
number is greater than 5" will be displayed. Otherwise, the message box saying "The
number is not greater than 5" will be displayed.
You can also have multiple conditions using ElseIf:

If condition1 Then
' Code to be executed if condition1 is True
ElseIf condition2 Then
' Code to be executed if condition2 is True
Else
' Code to be executed if none of the conditions are True
End If

In Visual Basic 6, there are various methods to handle user input. Here's a brief
overview of some common methods:

1. **InputBox Function:**
- The `InputBox` function displays a prompt in a dialog box and waits for the user
to enter text or click a button.
- Example:

```vb
Dim userInput As String

pg. 6
Chapter Two Visual Basic 6

Lecturer: Duaa Abdul-Muhsin Second Class

userInput = InputBox("Enter your name:", "User Input")


MsgBox "You entered: " & userInput
```

- In this example, an input box will prompt the user to enter their name, and the
entered value will be stored in the `userInput` variable.

2. **TextBox Control:**
- You can use the `TextBox` control on a form to allow users to input text.
- Example:

```vb
' Assume you have a TextBox named txtUserInput on your form
Dim userInput As String
userInput = txtUserInput.Text
MsgBox "You entered: " & userInput
```

- This code retrieves the text entered by the user in a TextBox named
`txtUserInput` and displays it in a message box.

3. **Combo Box Control:**


- If you want the user to choose from a predefined list, you can use a `ComboBox`
control.
- Example:

```vb
' Assume you have a ComboBox named cboChoices on your form
Dim selectedChoice As String
selectedChoice = cboChoices.Text
MsgBox "You selected: " & selectedChoice
```

- This code retrieves the selected item from a ComboBox named `cboChoices` and
displays it in a message box.

pg. 7
Chapter Two Visual Basic 6

Lecturer: Duaa Abdul-Muhsin Second Class

4. **Mouse and Keyboard Events:**


- You can capture user input through events like `KeyPress`, `KeyDown`, or `Click`
on various controls.
- Example:

```vb
Private Sub txtUserInput_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then ' Check if Enter key is pressed
MsgBox "Enter key pressed!"
End If
End Sub
```

- In this example, the `KeyPress` event of a TextBox (`txtUserInput`) is used to


detect when the Enter key is pressed.

pg. 8

You might also like