Properties of Some Controls
Properties of Some Controls
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.
Choose the “ListView1” control from the list of controls in the toolbox. Place the control
on the form in Visual Basic.
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
Function Creation:
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
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.
Example:
Function hypotenuse(side1 As integer, side2 As integer) As integer
Return Sqr((side1 ^ 2) + (side2 ^ 2))
End Function
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
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
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:
dblHours = txtHours
dblSalary = txtSalary
dblHours = txtHours
dblSalary = txtSalary
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:
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:
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:
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.
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:
Example:
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:
EXAMPLE:
Public Enum Days
Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
End Enum
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
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.
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.
An example for a user defined data type to hold the product details is as given below.
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.
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
Text1.Text = ElectronicGoods(i).ProdName
For example:
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:
NESTED UDT:
udtEmpRec.udtEmpName.FirstName
udtEmpRec.udtEmpName.LastName
There can be only one MDI parent form in a project with one or more MDI child forms (or
simply child forms).
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.
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.
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).
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.