Sie sind auf Seite 1von 12

1) Explain status bar control along with properties in detail.

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.

The properties are as follows:


Category Property Description Property value
Appearance Panels Defines a collection of Collection of panels;
panels to display on default is an empty
the control. collection
SizingGrip Determines whether a True
status bar includes a False
sizing grip for the form
on the lower-right
side of the control.
Behaviour ShowPanels Determines whether True
panels defined in the False
panels property value
display.

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.

 Font dialog control


 It prompts the user to choose a font from among those installed on the local
computer and lets the user select the font, font size, and color.
 It returns the Font and Color objects.

3) Explain Arrays and function in VB.Net.


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

Number[0] Number[1] Number[2] Number[3] …..

How to declare an array


 To declare an array in VB.NET, you use the Dim statement.

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:

Dim threeDIntArray(10,10,10) As Integer

 Dynamic Dimensioning of Arrays


 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.
 The ReDim statement is intended only for arrays.
 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 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, a module, or a block.
 SYNTAX
ReDim [Preserve] name (boundlist) [, name (boundlist) [,….]]

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.

To display information to the user in a message box


 Navigate to where you would like to add the code for the message box.
 Add code using the Show method. The Show() method can be used to display a
message with a title bar.
Message box can also receive input. The Show method of the MessageBox class returns
a value that can be used to determine a choice made by the user. You can store this
value in an integer or compare the value returned when you display the message box
using if statement. The style parameter of the Show method can be set to display the
proper buttons to ask a user for information.

To display a message box to request information


 Open the ode Editor for your class and navigate to where you would like to add the
code for the message box.
 Add code that uses the Show method of the MessageBox class to display a message
box.

5) Explain properties of Menu Item.


ANS:
PROPERTIES OF A MENUBAR:
PROPERTY 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.
Defaultitem Determines whether the menu item is the default menu item.
Enabled Determines whether the menu items is available.
RadioCheck Determines whether the menu item is available, if checked, displays an option
button instead of a check mark.
Shortcut Indicates the shortcut key associated with the menu item.
Text Gets or sets the text on the control.

6) Explain all array methods


ANS:

Method Description Example


BinarySearch() Search a one-dimensional sorted array Array.BinarySearch(inchMyArray, 5)
for a value.
Clear() Sets a range of elements in the array to 0, Array.Clear(intMyArray, 0, 4)
false, or null depending on the data type
of the element.
Copy() Copies a section of one array to another. Array.Copy(intMyArray, 0,
inDestinationArray, 0, 1)
CopyTo() Copies all elements of a one-dimensional myArrayZero.CopyTo (myArrayTwo,
array to the specified one-dimensional 3)
array, starting at a specified starting
point.
GetLength() Gets the numberof elements in the inMyArray.GetLength(0)
specified dimension of any array.
GetUpperBound() Gets the upper-bound value of the intMyArray.GetUpperBound(0)
specified dimension of an array.
Reverse() Reverses the order of the elements in a Array.Reverse(inntMyArray)
one-dimensional array of a portion of an
array.
Sort() Sorts the elements in a one-dimensional Array.Sort(intMyArray)
array.

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

In vb.net arguments between the procedures can be passed in two ways:


1. Passing by Value:
 This is the default mechanism for passing parameters to a method.
 In this mechanism, when a method is called, a new storage location is
created for each value parameter.
 The values of the actual parameters are copied into them. So, the changes
made to the parameter inside the method have no effect on the argument.
 In VB.Net, you can declare the value parameter using the ByVal keyword. The
Sub swap(ByVal x As Integer, ByVal y As Integer)
Dim temp As Integer
temp = x ‘ save the value of x
x = y ‘ put temp into y
End Sub
 Calling a sub procedure “swap”
Dim a As Integer=100
Dim b As Integer=200
swap(a,b)

This will generate the following result:


Before swap, value of a: 100
Before swap, value of b: 200
After swap, value of a: 100
After swap, value of b: 200

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)

This will generate the following result:


Before swap, value of a: 100
Before swap, value of b: 200
After swap, value of a: 200
After swap, value of b: 100
8) Differentiate:
i) Main Menu and Context Menu.
ii) Function and Subroutine
iii) Call-By-Value and Call-By-Reference
ANS:
i) Main Menu and Context Menu:
 A Menu is normally found at top of a window i.e. File, Edit, Help etc. menus.
 The MainMenu control works as the top-level container for the menu
structure.
 Each of the items in the menu are MenuItems which may have nested
MenuItems.
 A Context Menu is intended to be menu that pops up when you right-click on
something. The menu can have context to what was clicked hence the name.
 They appear in context of some specific controls, so are called context
menus. For example, Cut, Copy or Paste options.
 Context menu items can also be disabled, hidden or deleted. You can also
show a context menu with the help of the Show method of the Contextmenu
control.

ii) Function and Subroutine:


 Functions and Subroutines are lines of code that you use more then once.
 The purpose of functions and subroutines is to save time and space by just
calling a functions/subroutine.
 There is hardly a difference between the two, except that a function returns
a value, where a subroutine just repeats lines of code.
 A function takes parameters, works locally and does not alter any values or
work with any value outside its scope (high cohesion). It also returns some
value.
 A subroutine works directly with the values of the caller or code segment
which invoked it and does not return values (low cohesion), i.e. branching
some code to some other code in other to do some processing and come
back.

iii) Call-By-value and Call-By-Reference:


1) Passing by Value:
 This is the default mechanism for passing parameters to a method.
 In this mechanism, when a method is called, a new storage location is
created for each value parameter.
 The values of the actual parameters are copied into them. So, the
changes made to the parameter inside the method have no effect on
the argument.
 In VB.Net, you can declare the value parameter using the ByVal
keyword. The Sub swap(ByVal x As Integer, ByVal y As Integer)
Dim temp As Integer
temp = x ‘ save the value of x
x = y ‘ put temp into y
End Sub
 Calling a sub procedure “swap”
Dim a As Integer=100
Dim b As Integer=200
swap(a,b)

This will generate the following result:


Before swap, value of a: 100
Before swap, value of b: 200
After swap, value of a: 100
After swap, value of b: 200

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)

This will generate the following result:


Before swap, value of a: 100
Before swap, value of b: 200
After swap, value of a: 200
After swap, value of b: 100

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

Number[0] Number[1] Number[2] Number[3] …..

 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.

Syntax: ReDim [Preserve] name(boundlist) [, name(boundlist) [, … ]]

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.

10) Explain Menu bar control in VB.Net.


ANS:
Menu bar:
 In a windows application, menu is composed of a collection of several menu
items, including commands, menu separators, and sub-menus.
 The main menu and the context menu controls are the two menu controls used
in VB.Net to add menu to forms.
 The main menu control is used to add a menu bar at the top of a form while
Context menu control is used to add the short cut menus to forms and Controls.
 Each command on a menu is a menu item from the menu Item class.
 A menu items behaves much like a control and has properties and events.
 A shortcut key is one or more assigned keys that cause the event procedure for a
menu Item’s click event to execute.
 A shortcut key differs from an access key.
 While an access key is used to select a menu or command, a shortcut key is used
to execute the command when a user presses the key or keys while the menu
displays during runtime.

The following are the steps to be followed to create a menu:


1. Double-click the MainMenu tool in the Toolbox window to add a new object
named MainMenu1 to the form tray.
2. At the top of the MDI parent form, click the box with Type here in it and type
&File.
3. Press Enter to move to the next menu items and type &Products.
4. Press Enter to move to the next menu items and type a hyphen (-).
5. Press Enter and type E&xit.

Properties of Menu bar:

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.

Passing arguments between procedures:


In VB.Net arguments between the procedure can be passed in two ways:
1) Passing by Value:
 This is the default mechanism for passing parameters to a method.
 In this mechanism, when a method is called, a new storage location is
created for each value parameter.
 The values of the actual parameters are copied into them. So, the changes
made to the parameter inside the method have no effect on the argument.
 In VB.Net, you can declare the value parameter using the ByVal keyword.

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.

Das könnte Ihnen auch gefallen