Вы находитесь на странице: 1из 11

1) Explain Combo box in detail.

ANS:
 The combo box control is used to display a drop-down list of various items.
 It is a combination of a text box in which the user enters an item and a drop-
down list from which the user selects an item.
 You can populate the list box items either from the properties window or at
runtime.

Understanding ComboBox Indexes


 When you add items to a ComboBox list VB.NET assigns each one an unique
index number.
 The first item is assigned an index of 0; the second item gets an index number of
1, and so on…
 For example : Index number for Auto Loan Program
o A—Excellent Credit Rating = 0
o B—Good Credit Rating =1 etc…
 SelectedIndex is the property that keeps track of what index number currently
being accessed.
 When no item is selected, the SelectedIndex property is set to -1. The following
line of code would clear the ComboBox:
o cmbCreditRating.SelectedIndex = -1

Properties of ComboBox Control 

Property Description
DropDownStyle Gets or sets a value specifying the style of the combo box.
Name Gets or sets the name of the control.
DropDownWidth Gets or sets the width of the drop-down portion of a combo box.
Integral Height Gets or sets the integral height of an item in the combo box.
SelectedIndex Gets or sets the index specifying the currently selected item.
MaxLength Gets or sets the maximum number of characters a user can enter
in the editable area of the combo box.
Items Gets an object representing the collection of the items contained
in this ComboBox.
MaxDropDownItems Gets or sets the maximum number of items to be displayed in the
drop-down part of the combo box.
Sorted Gets or sets a value indicating whether the items in the combo box
are sorted.
Text Gets or sets the text associated with this control.
Methods of the ComboBox Control

Methods Description
Add() Adds the specified items to the combo box.
Remove() Remove method is called to delete items. Remove has one argument that
specifies the item to remove.
RemoveAt() RemoveAt method is called to delete items. RemoveAt removed the item
with the specified index number.
Clear() Clear method id called to remove all items from the collection.
Count() Counts the number of items in the collection.
Contains() Retrieves a value indicating whether the specified control is a child of the
control. (Inherited from Control )
Insert() Insert the string or object at the desired point in the list with the Insert
method.
Copyto() Copies the entire collection into an existing array of objects that a specified
location within the array.

2) Explain different types of loop with proper example.


ANS:
There are four basic types of loops, two of which contain the decision to terminate
the loop at the top of the control structure and two which contain the decision to
terminate the loop at the bottom of the control structure.
Do…while
Do…until
While…endwhile
The for…Next
Nested for…Next
For Each…Next

 Do…while
 A common form of the Do statement is the Do…While.
 This statement repeatedly executes a series of statement in the loop as
long as the condition is true.
 Example:
Dim index As Integer=0
Do Debug.Write(index.ToString &””)
index+=1
Loop While index<=10
Debug.WriteLine(“”)

Output: 0 1 2 3 4 5 6 7 8 9 10

 Do….until
 Another common form of the Do statement is the Do…until.
 This statement loops until the condition becomes true.
 Example:
Dim index As Integer=0
Do
Debug.Write(index.ToString &””)
Index+=1
Loop Until index>10

 Whie…endwhile
 It runs a series of statements as long as a given condition is true.
 Use a while…end while structure when you want to repeat a set of
statements an indefinite number of times, as long as a condition remains
true.
 The while statement always checks the condition before it starts the loop.
 You can nest while loops by placing one loop within another.
 Example:
Dim index As Integer=0
While index <=10
Debug.Write(index.ToString &””)
index+=1
End While
Debug.WriteLine(“”)

Output: 0 1 2 3 4 5 6 7 8 9 10

 The For…Next
 You use a For…Next structure when you want to repeat a set of statements a
set number of times.
 For…Next loops are different from the Do..until loop in that it has an
automatic counter and condition built in.
 This makes them perfect for counter-controlled loops-these are loops where
you set up the variable before the loop starts, then increment the variable
within the loop, and then test to see if it has reached the maximum count
that you’re aiming for.
 Benefits of For…Next loops:
 More efficient than a Do while loop
 Easier to read
 Uses less memory
 Faster execution
 Example:
For index As Integer=1 To 5
Debug.Write(index.ToString & ” ”)
Next
Debug.WriteLine(“”)

Output: 1 2 3 4 5

 Nested For…Next
 You can nest For loops by putting one loop within another.
 The outer loop creates a string for every iteration of the loop.
 The inner loop decrements a loop counter variable for every iteration of the
loop.
 When nesting loops, each loop must have a unique counter variable.
 Example:
For X=1 To 4
MessageBox.Show(“Outer loop – X = ” & X)
For Y=1 To 3
MessageBox.Show(“Inner loop –X = ” & X & ”And Y = ” & Y)
Next X
Next Y

3) Explain String Manipulation with its Methods with example.


ANS:
 The String class of the .NET framework provides many built-in methods to
facilitate the comparison and manipulation of strings.
 It is now a trivial matter to get data about a string, or to create new strings by
manipulating current strings.
 The VB.NET language also has inherent methods that duplicate many of these
functionalities.
 The SubString Method allows you to retrieve part of a string (from a larger
string) based on a start position and the number of characters to retrieve.
 For example:
strExample = “Christy Garrett”

Manipulating Strings
strLastName = strExample.SubString( _____ , _____ )

 Some Common String Class Methods are as follows-

Methods Description Example Result


Chars() Gets a character at the strExmaple = “McKenna” strResult = “e”
specified position in a strResult = strExample.Char(3)
string.
EndsWith() Determines whether strExmaple = “McKenna” strResult =True
the end of a string strResult =
matches a pass-in strExample.EndsWith(“na”)
target.
Insert() Inserts a passed-in strExmaple = “Mcna” strResult =
string into the string at strResult = strExample.Insert(2, “McKenna”
the index position “Ken”)
specified.
Length() Gets the number of strExmaple = “McKenna” strResult = 7
characters in a string. strResult = strExample.Length()
PadLeft() Right-aligns the strExmaple = “Warning” strResult =
characters in this strResult = “!!!!Warning”
instance, padding on strExample.PadLeft(12, “!!!”)
the left with spaces or
a specified character
for a specified total
length.
PadRight() Left-aligns the strExmaple = “Warning” strResult =
characters in this strResult = “Warning!!!!!”
instance, padding on strExample.PadRight(12, “!!”)
the right with spaces or
a specified character
for a specified total
length.
Remove() Deletes a specified strExmaple = “McKenna” strResult =
number of characters strResult = “Mcna”
from this instance strExample.Remove(2,3)
beginning at a specified
position.
Replace() Replaces all strExmaple = “McKenna” strResult =
occurrences of a strResult = “McKel”
specified character or strExample.Replace(“nna”, “l”)
string in this instance,
with another specified
character or string.
StartsWith() Determines whether strExmaple = “McKenna” strResult = False
the start of a string strResult =
matches a pass-in strExample.StartsWith(“na”)
target.
SubString() Retrieves a substring strExmaple = “McKenna” strResult =”en”
from the string. strResult =
strExample.SubString(3,2)
ToLower() Returns a copy of the strExmaple = “McKenna” strResult =
string in lowercase. strResult = “mckenna”
strExample.ToLower()
ToUpper() Returns a copy of the strExmaple = “McKenna” strResult =
string in uppercase. strResult = “MCKENNA”
strExample.ToUpper()
Trim() Removes all strExmaple = “ McKenna ” strResult =
occurrences of a set of strResult = strExample.Trim() ”McKenna”
specified characters
from the beginning and
end of the string;
default character to
remove is the space
character.

4) Explain properties of checkbox Control in brief.


ANS:

Properties of CheckBox Control

Property Description
Name Gets or sets the name of the control.
Appearances Gets or sets a value determining the appearances of the check box.
Checkalign Gets or sets the horizontal and vertical alignment of the check mark on
the check box.
Checked Gets or sets a value indicating whether the check box is selected.
Checkstate Gets or sets the state of the check box.
Flatstyle Gets or sets the flatstyle appearances of the control.
Image Gets or sets the image to be displayed on the control.
Imagealign Gets or sets the alignment of the image that is displayed on the control.
Text Gets or sets the caption of a check box.
Autocheck Gets or sets a value indicating whether the
Checked or CheckState value and the appearance of the control
automatically change when the check box is selected.
Threestate Gets or sets a value indicating whether or not a check box should allow
three check states rather than two.

5) Write a note on Logical operator.


ANS:

There are following types of logical operators-

Operator Description Example


And It is the logical as well as bitwise AND operator. If (A And B) is false.
both the operands are true, then condition
becomes true. This operator does not perform
short-circuiting, i.e., it evaluates both the
expressions.
Or It is the logical as well as bitwise OR operator. (A Or B ) is True.
Id=f any of the operands is true, then condition
becomes true. This operator does not perform
short-circuiting, i.e., it evaluates both the
expressions.
Not It is the logical as well as bitwise operator. Used Not (A And B) is true.
to reverse the logical state of its operand. If a
condition is true, then Logical NOT operator will
make false.
Xor It is the logical as well as bitwise Logical Exclusive A Xor B is true.
OR operator. It returns True if both expressions
are true or both expressions are false; otherwise
it returns false. This operator does not perform
short circuiting, it always evaluates both
expressions and there is no short-circuiting
counterpart of this operator.
AndAlso It is the logical AND operator. It works only on (A AndAlso B) is false.
Boolean data. It performs short-circuiting.
OrElse It is the logical OR operator. It works only on (A OrElse B) is true.
Boolean data. It performs short-circuiting.
IsFalse It determines whether an expression is false.
IsTrue It determines whether an expression is True.

 Complex expressions can contain many different operators. The following


example illustrates this-
X = ( 45 * ( y + z ) ) ^ ( 2 / 85 ) * 5 + z
 When several operations occur in an expression, each part is evaluated and
resolved in a predetermined order called operator precedence.
 Unless parenthesis dictate otherwise, .NET reads from left to right and evaluates
conditions in this order:
 Arithmetic operators
 Relational operators
 Not operators
 And/AndAlso operators
 Or/OrElse operators

6) Differentiate:
i) Combo Box and List Box
ii) Modal Form and Modeless Form
Ans:

Sr. Combo Box List Box


1. ComboBox shows only one option to ListBox shows many options to the user
the user. simultaneously.
2. This control occupies less space. This control occupies more space.
3. Multiple selections are not possible. Multiple selections are possible.
4. We can’t use check boxes within the We can use check boxes within the list box
list box.
5. We can add new items in combo box. We cannot add new items in list box.

Sr. Modal Form Modeless Form


1. Modal Form gains the exclusive It allows the user to shift between forms
attention of the user. A user cannot within an application without closing the
access other forms within an current form.
application until the current form is
closed
2. Messagebox and Inputbox are the MDI Form is the example of modeless
examples of Modal Form. form.

7) Explain List Box control with properties and methods.


Ans:
A user can select an item from the list. It allows the programmer to add items at design
time by using the properties window or at the runtime.

To add items in a ListBox, select the ListBox control and get to the properties windows,
for the properties of this control. Click the ellipses (…) button next to the Items property.
This opens the String Collection Editor dialog box which is shown in figure, where you
can enter the values one at a line.

Properties of List box control:


S. Property Description
N
1 AllowSelection Gets a value indicating whether the ListBox currently
enables selection of list items.
2 BorderStyle Gets or sets the type of border drawn around the list
box.
3 ColumnWidth Gets of sets the width of columns in a multicolumn
list box.
4 HorizontalExtent Gets or sets the horizontal scrolling area of a list
box.
5 HorizontalScrollBar Gets or sets the value indicating whether a
horizontal scrollbar is displayed in the list box.
6 ItemHeight Gets or sets the height of an item in the list box.
7 Items Gets the items of the list box.
8 MultiColumn Gets or sets a value indicating whether the list box
supports multiple columns.
9 ScrollAlwaysVisible Gets or sets a value indicating whether the vertical
scroll bar is shown at all times.
10 SelectedIndex Gets or sets the zero-based index of the currently
selected item in a list box.
11 SelectedIndices Gets a collection that contains the zero-based
indexes of all currently selected items in the list box.
12 SelectedItem Gets or sets the currently selected item in the list
box.
13 SelectedItems Gets a collection containing the currently selected
items in the list box.
14 SelectedValue Gets or sets the value of the member property
specified by the ValueMember property.
15 SelectionMode Gets or sets the method in which items are selected
in the list box. This property has values:
• None
• One
• MultiSimple
• MultiExtended
16 Sorted Gets or sets a value indicating whether the items in
the list box are sorted alphabetically.
17 Text Gets or searches for the text of the currently
selected item in the list box.
18 TopIndex Gets or sets the index of the first visible item of a list
box.
19 Name Gets or sets the name of the control.

Methods of List Box Control:


S. Method Name & Description
N
1 BeginUpdate
Prevents the control from drawing until the EndUpdate method is called, while items
are added to the ListBox one at a time.
2 ClearSelected
Unselects all items in the ListBox.
3 EndUpdate
Resumes drawing of a list box after it was turned off by the BeginUpdate method.
4 FindString
Finds the first item in the ListBox that starts with the string specified as an argument.
5 FindStringExact
Finds the first item in the ListBox that exactly matches the specified string.
6 GetSelected
Returns a value indicating whether the specified item is selected.
7 SetSelected
Selects or clears the selection for the specified item in a ListBox.
8 OnSelectedIndexChanged
Raises the SelectedIndexChanged event.
8 OnSelectedValueChanged
Raises the SelectedValueChanged event.

8) Explain following properties:


i) ThreeState (CheckBox)
ii) Selection mode (ListBox)
iii) DropDownStyle (ComboBox)
iv) Locked (Textbox)
v) TabStop (Textbox)
vi) PasswordChar (Textbox)
Ans:

i) ThreeState (CheckBox):

This property helps to get or set a values indicating whether or not a check box should
allow three check states rather than two. To enable the indeterminate state, the
ThreeState property of the check box is set to be True.

ii) SelectionMode (ListBox):


This property helps to get or sets the method in which items are selected in the list box.
This property has values:
 None
 One
 MultiSimple
 MultiExtended

iii) DropDownStyle (CombBox):


This property is used to change the appearance of the list and the method used to select
an item. The values can be:
a) Simple: List always displays; scroll bar added if list is longer than the ComboBox
height.
b) DropDown: List drops down when you click on the box. You can type directly into the
box. (Default)
c) DropDownList: List drops down when you click on the box; you CANNOT type directly
into the box.

iv) Locked (Textbox):


There is no such property for textbox control. But we can lock textbox and fix it on a
particular location of the form. To do this we need to do right click and then select Lock
controls.

v) TabStop (Textbox):
This property Gets or sets a value indicating whether the user can tab to the Textbox.

vi) PasswordChar:
This property Gets or sets the character used to mask characters of a password in a
single-line Textbox control.

9) Write a note on keyboard events with example.


Ans:
The Keyboard class provides keyboard-related events, methods, and properties that
provide information regarding the state of the keyboard.
Control.KeyPress Event
 It occurs when a key is pressed while the control has focus.

Key events occur in the following order:


1) KeyDown
2) KeyPress
3) keyUp

 The KeyPress event is not raised by noncharacter keys; however, the


noncharacter keys do raise the KeyDown and KeyUp events.
 Use the KeyChar property to sample keystrokes at run time and to consume or
modify a subset of common keystrokes.
 To handle keyboard events only at the form level and not enable other controls
to receive keyboard events, set the KeyPressEventArgs.Handled property in your
form’s KeyPress event handling method to true.

Вам также может понравиться