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

Properties of Some Controls

The document discusses various properties and controls in Visual Basic including listboxes, comboboxes, option buttons, common controls, image list controls, functions, parameters and arguments. It provides details on what each of these properties and controls are used for and how to work with them in Visual Basic.

Uploaded by

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

Properties of Some Controls

The document discusses various properties and controls in Visual Basic including listboxes, comboboxes, option buttons, common controls, image list controls, functions, parameters and arguments. It provides details on what each of these properties and controls are used for and how to work with them in Visual Basic.

Uploaded by

M S S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

PROPERTIES OF LISTBOX CONTROL

1.ITEMDATA-Returns/Sets a specific number for each item in a list box


2.List-Returns/sets the items contained in a control's list portion.
3.Multiselect-0-none
1-simple
2-extended
Returns/sets a value that determines whether a user can make multiple selections in a control.
4.Style-0-standard
1-checkbox
Returns/sets a value that determines whether checkboxes are displayed inside a ListBox control.
5.Index-Returns/sets the number identifying a control in a control array.

COMBOBOX PROPERTIES IN VISUAL BASIC


1.Index-Returns/sets the number identifying a control in a control array.
2.ITEMDATA-Returns/Sets a specific number for each item in a comboBox.
3.List-Returns/sets the items contained in a control's list portion.
4.style-Returns/sets a value that determines the type of control and the behaviour of its
listbox portion.
0-DropDown combo
1-Simple combo
2-DropDownList
5.Text-Returns/sets the text contained in the control.

OPTION BUTTON PROPERTIES IN VISUAL BASIC


1.Style-Returns the appearance of the control,whether standard(standard window style)
or graphical(with custom picture)
0-standard
1-graphical
2.index-Returns the number identifying a control in a control array.
3.appearance-returns whether or not an object is painted at run time with 3D effects.
0-flat
1-3D
4.caption-Returns the text displayed in an objects title bar or below an objects icon.
5.value-Returns the value of an object.
6.visible-Returns a value that determines whether an object is visible or hidden.

COMMON CONTROLS IN VB6.0


Common controls in VB 6.0
1.Image List Control
2.List View Control
3.Progress Bar Control
4.Slider Control
5.Status Bar Control
6.Tab Strip control
7.Tool Bar control
8.Tree view Control
IMAGE LIST CONTROL IN VB6.0
Image List control:

 An ImageList Control contains a collection of images that can be used by other


Windows Common Control
 It does not appeare on the form at run time.
 It serve as a container for icon that are accessed by other control such as
ListView,TreeView,TabStrip and ToolBar controls.

To add Image list control in the tool box:


1.Click on “Start” . Then select “All Programs, Microsoft Visual Studio 6.0 and
Microsoft Visual Basic 6.0.” .

2. Select “Standard EXE” from the list in the New Project dialog box and click on
“Open.” Click on “Project” on the menu bar, then select “Components” from the drop-
down menu.

3. Scroll down the list in the box until Microsoft Windows Common Controls 6.0 (SP4) is
visible. Click on the checkbox to select the component and then click on “OK.” All
components show in the Toolbox.

To add Image List control in the form:

 Choose the “ListView1” control from the list of controls in the toolbox. Place the control
on the form in Visual Basic.

To add images to the image list control:

 Right click on Image control a popup menu is open choose properties option.A
Properties Page is open .
 Click on Images Tab and insert the image as you want.
 To insert more than one picture then click on Insert Picture Button

FUNCTIONS IN VISUAL BASIC 6.0


Definition:

 A Function procedure is a series of Visual Basic statements enclosed by the Function


and End Function statements.
 The Function procedure performs a task and then returns control to the calling code.
 When it returns control, it also returns a value to the calling code.

Function Creation:

 To create a function,use the Function keyword followed by a name and parentheses.


 Because a function returns a value, we must specify the type of value the function will
produce.
 To give this information, on the right side of the closing parentheses, type the As
keyword, followed by a data type.
 To indicates where a function stops, type End Function.
 the syntax used to create a function is:

Function FunctionName() As DataType

End Function

 The name of a function follows the same rules as we follow while framing a variable.
 The DataType factor indicates the type of value that the function will return.
 If the function will produce a word or a group of words, we can create it as String.
 If the function will check something and determine whether it produce a true or a false
value, we can create it as Boolean.

Example:
Function yesterday() As Date
End Function

Function findSqrt(radicand As integer) As integer


End Function

Execution of function:

 Each time the function is called, its statements run, starting with the first executable
statement after the Function statement and ending with the first End Function, Exit
Function, or Return statement encountered.
 Every Function procedure has a data type, is specified by the As clause in the Function
statement, and it determines the data type of the value the function returns to the
calling code.
 The value a Function procedure sends back to the calling code is called its return value.
 The procedure returns this value in one of two ways:
 It uses the Return statement to specify the return value, and returns control
immediately to the calling program.

Example:
Function FunctionName [(ParameterList)] As ReturnType
' The following statement immediately transfers control back
' to the calling code and returns the value of Expression.
Return Expression
End Function

 It assigns a value to its own function name in one or more statements of the procedure.
Control does not return to the calling program until an Exit Function or End Function
statement is executed.

Example:
Function FunctionName [(ParameterList)] As ReturnType
‘ The following statement does not transfer control back to the calling code.
FunctionName = Expression
' When control returns to the calling code, Expression is the return value.
End Function

Calling a function:

 invoke a Function procedure by including its name and arguments either on the right
side of an assignment statement or in an expression.
 we must provide values for all arguments that are not optional, and we must enclose the
argument list in parentheses.
 If no arguments are supplied, we can omit the parentheses.

The syntax for a call to a Function procedure is as follows:


lvalue = functionname[(argumentlist)]

Example:
Function hypotenuse(side1 As integer, side2 As integer) As integer
Return Sqr((side1 ^ 2) + (side2 ^ 2))
End Function

Dim testLength, testHypotenuse As integer


testHypotenuse = hypotenuse(testLength, 10.7)

Creating a function using procedure dialog box:


1.To create a function click Tools--->Add procedure-->procedure dialog box opens.
2. Give the name of the function in the textbox.
3.In Type check the option button for function
4.In scope select public option button
5.Press ok button.

PARAMETERS AND ARGUMENTS IN USER DEFINED


FUNCTIONS OF VB 6.0

 When creating a procedure that will use an external value, declare the argument that
represents that value between the parentheses of the procedure.
 For a sub routine, the syntax would be:

Sub ProcedureName(Argument)
End Sub

 For a function, the syntax would be:

Function ProcedureName(Argument)
EndSub
Function Sub

 The argument must be declared as a normal variable, omitting only the Dim keyword.
 example that creates a function that takes a string as argument:
Function CalculatePayroll(strName As String) As Double

 A certain procedure can take more than one argument.


 In this case, in the parentheses of the procedure, separate the arguments with a
comma.
 example of a sub routine that takes two arguments:

Sub EvaluateInvoice(strEmplName As String, dblHourlySalary As Currency)


End Sub

Passing Arguments By value:

 To call a procedure that takes an argument, type its name and a space, followed by
value for each argument.
 The value provided for an argument is also called a parameter.
 If there is more than one argument, separate them with a comma.
 example:

Private Sub txtResult_GotFocus()


Dim dblHours As Double
Dim dblSalary As Double

dblHours = txtHours
dblSalary = txtSalary

CalcAndShowSalary dblHours, dblSalary


End Sub

Sub CalcAndShowSalary(Hours As Double, Salary As Double)


Dim dblResult As Double

dblResult = Hours * Salary


txtResult = dblResult
End Sub

 we can use the Call keyword to call a sub routine.


 In this case, when calling a procedure using Call, we must include the argument(s)
between the parentheses.
 using Call, the above GotFocus event could call the CalcAndShowSalary as follows:

Private Sub txtResult_GotFocus()


Dim dblHours As Double
Dim dblSalary As Double

dblHours = txtHours
dblSalary = txtSalary

Call CalcAndShowSalary(dblHours, dblSalary)


End Sub
 If we use the above technique to call a procedure that takes more than one argument,
 we must provide the values of the arguments in the exact order they are listed inside of
the parentheses of the function.
 If we know the name of the arguments, we can type them in any order and provide a
value for each.
 To do that, on the right side of each argument, type the := operator followed by the
desired value for the argument.
 example:

Function DisplayName(FirstName As String, LastName As String) As String


Dim FullName As String

FullName = FirstName & " " & LastName


DisplayName = FullName
End Function

Private Sub Form_Load()


Caption = DisplayName(LastName:="BASIC", FirstName:="VISUAL")
End Sub

Passing Arguments By Reference:

 When calling a procedure that took an argument, we were supplying a value for that
argument.
 the procedure that is called makes a copy of the value of the argument and make that
copy available to calling procedure.
 That way, the argument itself is not accessed.
 This is referred to as passing an argument by value.
 This can be reinforced by typing the ByVal keyword on the left side of the argument.
 example:

Sub GetFullName(ByVal FullName As String)


FullName = "Basic, Visual"
End Sub

 If you create a procedure that takes an argument by value and you have used the ByVal
keyword on the argument, when calling the procedure,
 we don't need to use the ByVal keyword; just the name of the argument is enough.
 example:

Private Sub Form_Load()


Dim FName As String
FName = ""
GetFullName FName
Caption = FName
End Sub

 An alternative to this technique is to pass the address of the argument to the called
procedure.
 When this is done, the called procedure doesn't receive a simple copy of the value of the
argument: the argument is accessed at its root.
 That is, at its memory address.
 With this technique, any action carried on the argument will be kept.
 if the value of the argument is modified, the argument would now have the new value,
dismissing or losing the original value it had.
 This technique is referred to as passing an argument by reference.
 To pass an argument by reference, on its left, type the ByRef keyword.
 This is done only when creating the function.
 When the called procedure finishes with the argument, the argument would keep
whatever modification was made on its value.
 consider the following:

Private Sub Form_Load()


Dim FName As String
FName = "VISUAL BASIC"
GetFullName FName
Caption = FName
End Sub

Sub GetFullName(ByRef FullName As String)


FullName = "BASIC, VISUAL"
End Sub

 Using this technique, we can pass as many arguments by reference as many arguments
by value as we want.
 this technique is also used to make a sub routine return a value, which a regular sub
routine cannot do.
 passing arguments by reference allows a procedure to return as many values as
possible while a regular function can return only one value.

USER DEFINED DATA TYPE-ENUM IN VB6.0


ENUM:

 vB6 lets us to create enumerations, which are programmer-defined data types that can
take on a set of constant values.
 The use of enumerations can simplify certain programming tasks and make our program
code easier to read.

SYNTAX:

 We create an enumeration with the Enum...End Enum statement:

Public Enum EnumName


ConstantName1
ConstantName2
...
ContantNameN
End Enum
 EnumName is the name of the enumeration following VB's usual variable naming rules.
 Each constant name becomes a member of the enumeration.
 By default, the constants are automatically assigned numerical values in order, starting
with 0.

Example:

Public Enum Flavor


flVanilla
flChocolate
flCoffee
flStrawberry
End Enum

 This results in the constant flVanilla being equal to 0, flClocolate being equal to 1, and
so on.
 Usually, the actual numerical values of the constants in an enumeration do not matter,
but if you want to assign specific values we can:

Public Enum Flavor


flVanilla = 2
flChocolate = 4
flCoffee = 8
flStrawberry = 16
End Enum

EXAMPLE:
Public Enum Days
Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
End Enum

 Once we define an enumeration, it becomes available in our program as a data type


along with VB's built-in data types.
we can declare variables of this type as :
Dim MyFavoriteFlavor As Flavor
Dim weekdays as days

We can use the type for procedure arguments:

Public Sub MakeCone(f As Flavor)


...
End Sub

we can use the type as a return value of a function:


Public Function Taste() As Flavor
...
End Function

 When we are typing code, the VB editor will display a drop-down list of enumeration
members to choose from, which is a real convenience.
 If we try to use an incorrect value (i.e., one that's not in the enumeration), we'll receive
an error message.

Example:
Enum daysoftheweek
sunday = 1
monday
tuesday
wednesday
thursday
friday
saturday
End Enum

Dim x As daysoftheweek
Dim bonus As Integer

Private Sub Form_click()


x = InputBox("Enter the day you worked 1-7")
Select Case x
Case sunday, saturday
bonus = 1500
Case Else
bonus = 500
End Select
Label1.Caption = bonus
End Sub

USER DEFINED DATA TYPES-RECORDS IN VB6.0

 Variables of different data types when combined as a single variable to hold several
related informations is called a User-Defined data type.
 A Type statement is used to define a user-defined type in the General declaration
section of a form or module.
 User-defined data types can only be private in form while in standard modules can be
public or private.

The following rules apply to UDTs:

 UDTs may be declared only at the module-level (Cannot declare a UDT in an individual
Sub or Function)
 UDTs may have Public (project-level) or Private (module-level) scope. If the keyword
Public or Private is omitted, the default is Public.
 UDTs with Public scope may only be defined in standard modules, not forms.

The syntax for defining a UDT is:


[Public | Private] Type TypeName
Variable1 As datatype
...
Variablen As datatype
End Type

An example for a user defined data type to hold the product details is as given below.

Private Type ProductDetails


ProdID as String
ProdName as String
Price as Currency
End Type

 The user defined data type can be declared with a variable using the Dim statement as
in any other variable declaration statement.
 An array of these user-defined data types can also be declared.

An example to consolidate these two features is:

Dim ElectronicGoods as ProductDetails ' One Record


Dim ElectronicGoods(10) as ProductDetails ' An array of 11 records

 A User-Defined data type can be referenced in an application by using the variable name
in the procedure along with the item name in the Type block.
 for example if the text property of a TextBox namely text1 is to be assigned the name
of the electronic good, the statement can be written as

Text1.Text = ElectronicGoods.ProdName

 If the same is implemented as an array, then the statement becomes

Text1.Text = ElectronicGoods(i).ProdName

Example, to define a UDT for an employee record is:


Public Type EmployeeRecord
strEmpName As String
HireDate As Date
salary As Single
End Type

 However, the definition alone is not enough.


 The Type definition is basically a "template" on which other variables are defined; the
template itself does not store any data.
 To use a UDT, we must define a variable "As" the name following the keyword "Type" (in
this case, "EmployeeRecord").

For example:

Dim udtEmpRec As EmployeeRecord

 The above defines a variable called "udtEmpRec" which has the attributes defined by
the structure "EmployeeRecord".
 Thus, it is "udtEmpRec" which we refer to in our procedural statements, NOT
"EmployeeRecord".
 To reference an individual element of the structure,we must qualify that element with
the "udt" variable that we defined.

For example, the following code places data in the individual elements of udtEmpRec:

udtEmpRec.strEmpName = "sai vignesh"


udtEmpRec.HireDate = #1/15/2016#
udtEmpRec.salary = 33000

NESTED UDT:

Public Type EmployeeName


FirstName As String
LastName As String
End Type

Public Type EmployeeRecord


udtEmpName As EmployeeName
HireDate As Date
Salary As Single
dblQuarterlyEarnings(1 To 4) As Double
End Type

Dim udtEmpRec As EmployeeRecord

We would reference the EmployeeName fields as follows:

udtEmpRec.udtEmpName.FirstName
udtEmpRec.udtEmpName.LastName

MDI FORMS IN VB6.0

 MDI stands for Multiple Document Interface.


 When we want to handle multiple documents, MDI forms are useful in a Windows
program.

How to add an MDI form to the current project:


Project -> Add MDI form.
Click Project from the menu bar, and click Add MDI form.

Restrictions of the MDI form

 we can have only one MDI form per project.


 We can't place most controls on an MDI form.
 The only controls that can be placed on the surface of the MDI form are Menus, Timer,
CommonDialog, PictureBox, ToolBar, and StatusBar.
 These restrictions are there because MDI forms are the special type of forms, especially
used to handle multiple child forms.

How does the MDI form work:

 There can be only one MDI parent form in a project with one or more MDI child forms (or
simply child forms).

MDI child form:

 To add a child form, add a regular form, and set the MDIchild property to True.
 Can have many child forms and can show an MDI child form using the Show method.

AutoShowChildren property of an MDI form:

 The default value of the AutoShowChildren property is True.


 When it is True, the MDI child forms are displayed once they are loaded.
 When the value is False only then we can keep it hidden after loading, otherwise not.

Restrictions of the MDI child forms:


1. can't display an MDI child form outside its parent.
2. can't display a menu bar on the MDI child form.

MDI FORMS IN VB 6.0


MDI FORMS:

 MDI stands for Multiple Document Interface.


 The Multiple Document Interface (MDI) was designed to simplify the exchange of
information among documents.
 Each document is displayed in its own window, and all document windows have the
same behavior.
 The main Form, or MDI Form, isn't duplicated, but it acts as a container for all the
windows, and it is called the parent window.
 The windows in which the individual documents are displayed are called Child windows.
 An MDI application must have at least two Form, the parent Form and one or more child
Forms. Each of these Forms has certain properties.
 There can be many child forms contained within the parent Form, but there can be only
one parent Form.
 The parent Form may not contain any controls.
 While the parent Form is open in design mode, the icons on the ToolBox are not
displayed, but can't place any controls on the Form.
 The parent Form usually has its own menu.

To create an MDI application:

 Start a new project and then choose Project >>> Add MDI Form to add the parent Form.
 Set the Form's caption to MDI Window
 Choose Project >>> Add Form to add a SDI Form.
 Make this Form as child of MDI Form by setting the MDI Child property of the SDI Form
to True. Set the caption property to MDI Child window.
 Can have many child forms and can show an MDI child form using the Show method.

Restrictions of the MDI form

 can have only one MDI form per project.


 can't place most controls on an MDI form.
 The only controls that can be placed on the surface of the MDI form are Menus, Timer,
CommonDialog, PictureBox, ToolBar, and StatusBar.
 These restrictions are there because MDI forms are the special type of forms, especially
used to handle multiple child forms.

Restrictions of the MDI child forms:


1. can't display an MDI child form outside its parent.
2. can't display a menu bar on the MDI child form.

How does the MDI form work:

 There can be only one MDI parent form in a project with one or more MDI child forms (or
simply child forms).
 The parent form contains a menu bar on top of it.
 From there, the user opens or creates a new document.
 In this way, the user accomplishes his/her work in one or multiple documents, then
saves and closes the document (form).

AutoShowChildren property of an MDI form:


The default value of the AutoShowChildren property is True.
When it is True, the MDI child forms are displayed once they are loaded.
When the value is False only then you can keep it hidden after loading, otherwise not.

Example:
1.Insert a mdiform into the project,set the caption as mdiparent,set name of the form as
mdiform
2.create a menu mdimenu
---mdiopen
---mdiexit
3. add the code given below to the mdiopen
Private Sub mnumdiopen_Click()
childform.Show
End Sub
4.add the code given below to mdiexit
Private Sub mnumdiexit_Click()
End
End Sub
5.Now add a form to the project and set the mdichildproperty of the form to true.

6.create a menu in the child form as childmenu


---childcircle
---childrectangle
---childexit
7.add the code to childcirle
Private Sub mnuchildcircle_Click()
Circle (5000, 5000), 500, vbRed
End Sub
9.add the code to childrectangle
Private Sub mnuchildrectangle_Click()
Line (0, 0)-(5000, 5000), vbBlue, BF
End Sub
10.add the code to childexit
Private Sub mnuchildexit_Click()
Unload Me
End Sub
11.Save the project,execute it to see the result.

You might also like