VB Unit3 Assignment
VB Unit3 Assignment
ANS:
It represents a control that displays items and information in a horizontal bar in an
application window.
Status bar is an ItemsControl, which means it can contain a collection of objects of
any type (such as string, image, or panel).
A status bar is a bar that typically displays a horizontal row of images and status
information. You can divide the items in a StatusBar into groups that contain related
items, by using Separator controls. The items in a StatusBar can display text,
graphics, or other complex content. Items in a StatusBar are defined as
StatusBarItem objects.
Events that are defined on a StatusBarItem are raised when the user clicks the item
in the StatusBar.
The StatusBar does not receive keyboard focus.
2) What are the common dialog control available in vb.net? Explain OpenFileDialog
and FontDialog control.
ANS:
There are many built-in dialog boxes to be used in windows forms for various tasks like
opening and saving files, printing a page, providing choices for colors, fonts, page setup, etc.,
to the user of an application.
These built-in dialog boxes reduce the developer’s time and workload.
All of these dialog box control classes inherit from the CommonDialog class and override the
RunDialog() function of the base class to create specific dialog box.
The following diagram shows the common dialog class inheritance.
CommonDialog
FontDialog PrintDialog
FileDialog
PageSetupDialo
ColorDialog
g
OpenFileDialog
SaveFileDialog
OpenFileDialog control
The OpenFileDialog control prompts the user to open a file and allows the user to
select a file to open.
The user can check if the file exists and then open it.
The OpenFileDialog control class inherits from the abstract class FileDialog.
If the ShowReadOnly property is set to True, then a read-only check box appears in
the dialog box.
You can also set the ReadOnlyChecked property to True, so that the read-only check
box appears checked.
SYNTAX
Dim Array_Name (Upperlimit) as Data_type
Dim Array_Name() as Data_type
Where Array_Name is the array and upperlimit is the upper bound of the array.
For Example
Dim intData(30) ‘an array of 31 elements
Dim strData(20) As String ‘ an array of 21 strings
Multi-Dimensinal Array
VB.NET allows multi-dimensional arrays. Multidimensional arrays are also
called rectangular arrays.
You can declare a 2-dimensional array of string as:
Dim twoDStringArray(10,20) As String
Or, a 3-dimensional array of integer variables:
Term Definition
Preserve Optional. Modifier used to preserve the data in the existing array
when you change the size of only the last dimension.
Name Required. Name of the array variable.
Boundlist Required. List of bounds of each dimension of the redefined array.
FUNCTION PROCEDURES
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 returns control to the calling
code. When it returns control, it also returns a value to the calling code.
Each time the procedure 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.
You can define a Function procedure in a module, class, or structure.
It is Public by default, which means you can call It from anywhere in your
application that has access to the module, class, or structure in which you
define it.
A function procedure can take arguments, such as constants, variables, or
expressions, which are passes to it by the calling code.
The syntax for the function statement is:
[Modifiers] function functionname[(parameterList)] As
ReturnType
[Statements]
End function
Where,
Modifiers: specify the access level of the function;
possible values are public, private, protected, friend,
protected friend and information regarding overloading,
overriding, sharing and shadowing.
FunctionName: indicates the name of the function.
ParameterList: specifies the list of the parameters.
ReturnType: specifies the data type of the variable the
function reurns.
4) Explain messagebox button, messagebox icon and return values of message box
show method.
ANS:
Sometimes it becomes important to communicate with the person running your
program.
A MessageBox is a predefined dialog box that displays application–related
information to the user.
Message boxes are also used to request information from the user.
7) How can we create and call sub procedure? Explain with types and example.
ANS:
Sub procedure:
A sub procedure is a series of Visual Basic statement enclosed by the Sub and
End Sub statements.
The Sub procedure performs a task and then returns control to the calling code,
but it does not return a value to the calling code.
Each time the procedure is called, its statements are executed, starting with the
first executable statement after the Sub statement and ending with the first End
Function, Exit Function, or Return statement encountered.
You can define a Sub procedure in modules, classes, and structures. By default, it
is Public, which means you can call it from anywhere in your application that has
access to the module, class, or structure in which you defined it. The term,
method, describes a Sub or Function procedure that is accessed from outside its
defining module, class, or structure.
A sub procedure can take arguments such as constants, variables, or expressions,
which are passed to it by the calling code.
The syntax for the Sub statement is:
[Modifiers] Sub SubName [(ParameterList)]
[Statements]
End Sub
Where,
Modifiers: specify the access level of the procedure; possible values are:
Public, Private, Protected, Friend, Protected friend and information
regarding overloading, overriding, sharing, and shadowing.
SubName: indicates the name of the Sub.
ParameterList: specifies the list of the parameters.
Example
Sub CalculatePay(ByVal hours As Double, ByVal wage As Decimal)
‘local variable declaration
Dim pay As Double
pay = hours * wage
Console.WriteLine(“Total Pay: {0:C}”, pay)
End Sub
2. Passing by Reference:
A reference parameter is a reference to a memory location of a variable.
When you pass parameters by reference, unlike value parameters, a new
storage location is not created for these parameters.
The reference parameters represent the same memory location as the actual
parameters that are supplied to the method.
In VB.Net, you can declare the reference parameters using the ByRef
keyword. The Sub swap(ByRef x As Integer, ByRef y As Integer)
Dim a As Integer = 100;
Dim b As Integer = 200;
Swap(a,b)
2) Passing by Reference:
A reference parameter is a reference to a memory location of a
variable.
When you pass parameters by reference, unlike value parameters, a
new storage location is not created for these parameters.
The reference parameters represent the same memory location as
the actual parameters that are supplied to the method.
In VB.Net, you can declare the reference parameters using the ByRef
keyword. The Sub swap(ByRef x As Integer, ByRef y As Integer)
Dim a As Integer = 100;
Dim b As Integer = 200;
Swap(a,b)
9) What is an Array? Explain Redim and Preserve methods. Also explain rank,
GetLength method of array.
ANS:
ARRAYS:
An array stores a fixed-size sequential collection of elements of the same
type.
An array is used to store a collection of data, but it is often more useful to
think of an array as a collection of variables of the same type.
All arrays consist of contiguous memory locations.
The lowest address corresponds to the first element and the highest address
to the last element.
First Element Last Element
You can use the ReDim statement to change the size of one or more
dimensions of an array that has already been declared.
If you have a large array and you no longer need some of its elements, ReDim
can free up memory by reducing the array size. On the other hand, if your
array needs more elements, ReDim can add them.
It’s not valid on scalars (variables that contain only a single value), collections,
or structures.
Note that if you declare a variable to be of type Array, the ReDim statement
doesn’t have sufficient type information to create the new array.
You can use ReDim only at procedure level. Therefore, the declaration
context for the variable must be a procedure; it can’t be a source file, a
namespace, an interface, a class, a structure, or a block.
Term Definition
Preserve Optional. Modifier used to preserve the data in the existing array when
you change the size of only last dimension.
Name Required. Name of the array variable. See Declared Element Name
(Visual Basic).
Boundlist Required. List of bounds of each dimension of the redefined array.
Properties Description
Name Gets or sets the name of the control.
Checked It determines whether a check mark should appear next to the
text of the menu item.
Default Item Determines whether the menu item is the default menu item.
Enable Determines whether the menu item is available.
Radiocheck Determines whether the menu item is available, if checked,
displays an option button instead of a check box.
Shortcut Indicates the shortcut key associated with the menu items.
Text Gets or sets the text on the control.
11) Explain Function and Procedure. Also differentiate between ByVal and ByRef.
ANS:
Function Procedures:
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 returns a value to the calling code.
Each time the procedure is called, its statements run, starting with the first
executable statement after Function statement and ending with the first End
Function, Exit Function, or Return statement encountered.
Sub Procedures:
A sub procedure is a series of Visual Basic statement enclosed by the Sub and
End Sub statements.
The Sub procedure performs a task and then returns control to the calling
code, but it does not return a value to the calling code.
Each time the procedure is called, its statements are executed, starting with
the first executable statement after the Sub statement and ending with the
first End Function, Exit Function, or Return statement encountered.
2) Passing by Reference:
A reference parameter is a reference to a memory location of a variable.
When you pass parameters by reference, unlike value parameters, a new
storage location is not created for these parameters.
The reference parameters represent the same memory location as the actual
parameters that are supplied to the method.
In VB.Net, you can declare the reference parameters using the ByRef
keyword.