VB Unit3 Assignment
VB Unit3 Assignment
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.
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.
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
Manipulating Strings
strLastName = strExample.SubString( _____ , _____ )
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.
6) Differentiate:
i) Combo Box and List Box
ii) Modal Form and Modeless Form
Ans:
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.
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.
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.