List box :
The ListBox and combobox controls present lists of choices for the user to select. The listbox control occupies a user specified amount of space on the form. The items must be inserted in the ListBox control through the code or by the List property. Each new item in the List property must be entered on the separate line.
Basic properties.
• 1) MultiSelect :-
this property determines how the user can select the list’s items and must be set at design time. The MultSelect property’s value determine whether the user can select multiple items and which method will be used for multiple selection.
If its value 0 then multiple selection not allowed.
If its value 1 then simple multiple selection.
If its value 2 extended multiple selection.(use shift and click the mouse to span the selection)
• 2) Sorted :-
if you want the items to be always sorted , set this property to True. This property must be set at design time. The ListBox control easily sort text items but not numbers. To perform sorting of numbers you must format them with leading zeros. For example the number 10 as 010 and 5 as 005
• 3) Style : -
This property determines the appearance of the control. Value 0 means standard and value 1 means Checkbox.
The ListBox Control’s method :
1) AddItem :-
To add items to the list, use the AddItem method. Its syntax is as follows:-
List1.AddItem item , index
The item parameter is the string to be added to the list, and index is its order.
The index argument is optional. If you omit it the string is appended to the bottom of the list.
2) Removeitem: -
This method remove an item by using index value of the item. Its syntax is :
List1.RemoveItem index
Example : List1.RemoveItem 0
3) Clear:-
The clear method removes all the items from the control. Its syntax is :
List1.clear
4) List count :-
This give the number of items in the list.
5) List() :-
This is an array that holds the list’s items. The elements List(0) holds the first element of the list, List(1) holds the second item and so on upto List(listcount-1) which is last item.
For example:
For tm = List1.ListCount -1 to 0 Step -1
If List1.List(tm) = ” ” then
List1.RemoveItem tm
End if
Next
This loop scans the elements backward.
3) ListIndex :
This give us the index of the selected item in the List. If multiple items are selected, then ListIndex is the index of the most recently selected item. We can use this property to access specific elements in the list or delete specific items.
For example:
If List1.ListIndex >=0 Then
List1.RemoveItem List.List Index
End If
4) Selected :
This property is an array , similar to the List property with elements that have a True or a False value, depending on the status. The value is True if the element is selected otherwise, it’s False.
5) Selcount :
this property reports the number of selected items in a ListBox control with its MultiSelect property set to 1 (simple) or 2(Extended). It is commonly used in conjuction with the selected arry in processing the selected items the control.
6) New index :
This property returns the index of the item most recently added to a ListBox control. This property is used commonly with the ItemData property
Example :
Coding for project
Private Sub Command1_Click()
If List1.ListIndex >= 0 Then
List2.AddItem List1.Text
List1.RemoveItem List1.ListIndex
End If
End Sub
Private Sub Command10_Click()
List2.Sorted = True
End Sub
Private Sub Command1_Click()
If List1.ListIndex >= 0 Then
List2.AddItem List1.Text
List1.RemoveItem List1.ListIndex
End If
End Sub
Private Sub Command10_Click()
List2.Sorted = True
End Sub
Private Sub Command2_Click()
Dim i As Integer
If List2.SelCount = 1 Then
List1.AddItem List2.Text
List2.RemoveItem List2.ListIndex
ElseIf List2.SelCount > 1 Then
For i = List2.ListCount - 1 To 0 Step -1
If List2.Selected(i) Then
List1.AddItem List2.List(i)
List2.RemoveItem i
End If
Next
End If
End Sub
Private Sub Command3_Click()
If List1.ListIndex > 0 Then
List1.RemoveItem List1.ListIndex
End If
End Sub
Private Sub Command4_Click()
Dim i As Integer
If List2.SelCount = 1 Then
List2.RemoveItem List2.ListIndex
ElseIf List2.ListCount > 1 Then
For i = List2.ListCount - 1 To 0 Step -1
If List2.Selected(i) Then
List2.RemoveItem i
End If
Next
End If
End Sub
Private Sub Command5_Click()
Dim listItem As String
listItem = InputBox("Enter item to add to the list")
If Trim(listItem) <> "" Then
List1.AddItem listItem
End If
End Sub
Private Sub Command6_Click()
Dim listItem As String
listItem = InputBox("Enter item to add to the list")
If Trim(listItem) <> "" Then
List2.AddItem listItem
End If
End Sub
Private Sub Command7_Click()
List1.Clear
End Sub
Private Sub Command8_Click()
List2.Clear
End Sub
Private Sub Command9_Click()
List1.Sorted = True
End Sub
Also Set these Properties at design time
ListBox1 ListBox2
multiselect = 0 Multiselect = 2
sorted = false Sorted = true
ComboBox
A ComboBox combines the features of a TextBox and a ListBox.It also contain multiple items of which the user may select one , but it takes less space on scree. the actual difference is that the comboBox control allows the user to specify items that don’t exist in the list.
Three types of ComboBox controls are available in Visual Basic.
1)The Simple Combo box displays an edit area with an attached list box always visible immediately below the edit area. A simple combo box displays the contents of its list all the time. The user can select an item from the list or type an item in the edit box portion of the combo box. A scroll bar is displayed beside the list if there are too many items to be displayed in the list box area.
2)The Dropdown Combo box first appears as only an edit area with a down arrow button at the right. The list portion stays hidden until the user clicks the down-arrow button to drop down the list portion. The user can either select a value from the list or type a value in the edit area.
3) The Dropdown list combo box turns the combo box into a Dropdown list box. At run time , the control looks like the Dropdown combo box. The user could click the down arrow to view the list. The difference between Dropdown combo & Dropdown list combo is that the edit area in the Dropdown list combo is disabled. The user can only select an item and cannot type anything in the edit area. Anyway this area displays the selected item.
Basic properties
1) Sorted :-
if you want the items to be always sorted , set this property to True. This property must be set at design time. The ListBox control easily sort text items but not numbers. To perform sorting of numbers you must format them with leading zeros. For example the number 10 as 010 and 5 as 005
2) Style : -
This property determines the appearance of the control. Set value 0 for The Simple Combo box , set 1 for The Dropdown Combo box, and set value 2 for Dropdown list combo box
The ComboBox Control’s method :
1) AddItem :-
To add items to the list, use the AddItem method. Its syntax is as follows:-
combo.AddItem item , index
The item parameter is the string to be added to the list, and index is its order.
The index argument is optional. If you omit it the string is appended to the bottom of the list.
2) Removeitem: -
This method remove an item by using index value of the item. Its syntax is :
List1.RemoveItem index
Example : List1.RemoveItem 0
3) Clear:-
The clear method removes all the items from the control. Its syntax is :
List1.clear
4) Listcount :-
This give the number of items in the list.
5) List() :-
This is an array that holds the list’s items. The elements List(0) holds the first element of the list, List(1) holds the second item and so on upto List(listcount-1) which is last item.
For example:
For tm = List1.ListCount -1 to 0 Step -1
If List1.List(tm) = ” ” then
List1.RemoveItem tm
End if
Next
This loop scans the elements backward.
6) ListIndex :
This give us the index of the selected item in the List. If multiple items are selected, then ListIndex is the index of the most recently selected item. We can use this property to access specific elements in the list or delete specific items.
For example:
If List1.ListIndex >=0 Then
List1.RemoveItem List.List Index
End If
7) Selcount :
this property reports the number of selected items in a ListBox control with its MultiSelect property set to 1 (simple) or 2(Extended). It is commonly used in conjuction with the selected arry in processing the selected items the control.
8) New index :
This property returns the index of the item most recently added to a ListBox control. This property is used commonly with the ItemData property
note:in Combobox Multiple selections cannot be made. Only one item may be selected from the list.
SCROLL BAR
The ScrollBar is a commonly used control, which let the user select a value between two ends of the control. It has two versions: horizontal and vertical. The HScrollBar and the VScrollBar controls are perfectly identical only directions are different. It represents a set of values. The Min and Max property represents the minimum and maximum value.
The basic property of the scrollbar is:
• Min: - the control’s minimum value.
• Max: - the control’s maximum value.
• Value:- the control’s current value , specified by the indicator’s positions.
The range of values for a scrollbar control is 0 to 32655.
There are two events for scrollbar controls:
1) Change event : - this event occurs every time the user change the indicator’s position and released the muse button. The change event occurs only when the mouse button is released.
Show the current scroll bar's value.
Private VScroll1_Change()
Label1.Caption = VScroll1.Value
End Sub
2) Scroll event :- this event occurs continuously while the indicator is moving .after the mouse button is released this event stop and triggers a single change event .
For example:
' Show the current scroll bar's value.
Private VScroll1_Scroll()
label1.Caption = VScroll1.Value
End Sub
Example
The following figure uses three HScrollBar controls as sliders to control the individual RGB (red, green, blue) components of a color. The three scroll bars have their Min property set to 0 and their Max property set to 255, while their SmallChange is 1 and LargeChange is 16.
USE THE FOLLOWING CODE TO MAKE THIS PROJECT
Private Sub Command1_Click()
HScroll1.Value = 128
HScroll2.Value = 128
HScroll3.Value = 128
End Sub
Private Sub Form_Load()
Picture1.BackColor = RGB(128, 128, 128)
Label4.Caption = HScroll1.Value
Label5.Caption = HScroll2.Value
Label6.Caption = HScroll3.Value
End Sub
Private Sub HScroll1_Change()
Picture1.BackColor = RGB(HScroll1.Value, HScroll2.Value, HScroll3.Value)
End Sub
Private Sub HScroll1_Scroll()
Picture1.BackColor = RGB(HScroll1.Value, HScroll2.Value, HScroll3.Value)
Label4.Caption = HScroll1.Value
End Sub
Private Sub HScroll2_Change()
Picture1.BackColor = RGB(HScroll1.Value, HScroll2.Value, HScroll3.Value)
End Sub
Private Sub HScroll2_Scroll()
Picture1.BackColor = RGB(HScroll1.Value, HScroll2.Value, HScroll3.Value)
Label5.Caption = HScroll2.Value
End Sub
Private Sub HScroll3_Change()
Picture1.BackColor = RGB(HScroll1.Value, HScroll2.Value, HScroll3.Value)
End Sub
Private Sub HScroll3_Scroll()
Picture1.BackColor = RGB(HScroll1.Value, HScroll2.Value, HScroll3.Value)
Label6.Caption = HScroll3.Value
End Sub
The ListBox and combobox controls present lists of choices for the user to select. The listbox control occupies a user specified amount of space on the form. The items must be inserted in the ListBox control through the code or by the List property. Each new item in the List property must be entered on the separate line.
Basic properties.
• 1) MultiSelect :-
this property determines how the user can select the list’s items and must be set at design time. The MultSelect property’s value determine whether the user can select multiple items and which method will be used for multiple selection.
If its value 0 then multiple selection not allowed.
If its value 1 then simple multiple selection.
If its value 2 extended multiple selection.(use shift and click the mouse to span the selection)
• 2) Sorted :-
if you want the items to be always sorted , set this property to True. This property must be set at design time. The ListBox control easily sort text items but not numbers. To perform sorting of numbers you must format them with leading zeros. For example the number 10 as 010 and 5 as 005
• 3) Style : -
This property determines the appearance of the control. Value 0 means standard and value 1 means Checkbox.
The ListBox Control’s method :
1) AddItem :-
To add items to the list, use the AddItem method. Its syntax is as follows:-
List1.AddItem item , index
The item parameter is the string to be added to the list, and index is its order.
The index argument is optional. If you omit it the string is appended to the bottom of the list.
2) Removeitem: -
This method remove an item by using index value of the item. Its syntax is :
List1.RemoveItem index
Example : List1.RemoveItem 0
3) Clear:-
The clear method removes all the items from the control. Its syntax is :
List1.clear
4) List count :-
This give the number of items in the list.
5) List() :-
This is an array that holds the list’s items. The elements List(0) holds the first element of the list, List(1) holds the second item and so on upto List(listcount-1) which is last item.
For example:
For tm = List1.ListCount -1 to 0 Step -1
If List1.List(tm) = ” ” then
List1.RemoveItem tm
End if
Next
This loop scans the elements backward.
3) ListIndex :
This give us the index of the selected item in the List. If multiple items are selected, then ListIndex is the index of the most recently selected item. We can use this property to access specific elements in the list or delete specific items.
For example:
If List1.ListIndex >=0 Then
List1.RemoveItem List.List Index
End If
4) Selected :
This property is an array , similar to the List property with elements that have a True or a False value, depending on the status. The value is True if the element is selected otherwise, it’s False.
5) Selcount :
this property reports the number of selected items in a ListBox control with its MultiSelect property set to 1 (simple) or 2(Extended). It is commonly used in conjuction with the selected arry in processing the selected items the control.
6) New index :
This property returns the index of the item most recently added to a ListBox control. This property is used commonly with the ItemData property
Example :
Coding for project
Private Sub Command1_Click()
If List1.ListIndex >= 0 Then
List2.AddItem List1.Text
List1.RemoveItem List1.ListIndex
End If
End Sub
Private Sub Command10_Click()
List2.Sorted = True
End Sub
Private Sub Command1_Click()
If List1.ListIndex >= 0 Then
List2.AddItem List1.Text
List1.RemoveItem List1.ListIndex
End If
End Sub
Private Sub Command10_Click()
List2.Sorted = True
End Sub
Private Sub Command2_Click()
Dim i As Integer
If List2.SelCount = 1 Then
List1.AddItem List2.Text
List2.RemoveItem List2.ListIndex
ElseIf List2.SelCount > 1 Then
For i = List2.ListCount - 1 To 0 Step -1
If List2.Selected(i) Then
List1.AddItem List2.List(i)
List2.RemoveItem i
End If
Next
End If
End Sub
Private Sub Command3_Click()
If List1.ListIndex > 0 Then
List1.RemoveItem List1.ListIndex
End If
End Sub
Private Sub Command4_Click()
Dim i As Integer
If List2.SelCount = 1 Then
List2.RemoveItem List2.ListIndex
ElseIf List2.ListCount > 1 Then
For i = List2.ListCount - 1 To 0 Step -1
If List2.Selected(i) Then
List2.RemoveItem i
End If
Next
End If
End Sub
Private Sub Command5_Click()
Dim listItem As String
listItem = InputBox("Enter item to add to the list")
If Trim(listItem) <> "" Then
List1.AddItem listItem
End If
End Sub
Private Sub Command6_Click()
Dim listItem As String
listItem = InputBox("Enter item to add to the list")
If Trim(listItem) <> "" Then
List2.AddItem listItem
End If
End Sub
Private Sub Command7_Click()
List1.Clear
End Sub
Private Sub Command8_Click()
List2.Clear
End Sub
Private Sub Command9_Click()
List1.Sorted = True
End Sub
Also Set these Properties at design time
ListBox1 ListBox2
multiselect = 0 Multiselect = 2
sorted = false Sorted = true
ComboBox
A ComboBox combines the features of a TextBox and a ListBox.It also contain multiple items of which the user may select one , but it takes less space on scree. the actual difference is that the comboBox control allows the user to specify items that don’t exist in the list.
Three types of ComboBox controls are available in Visual Basic.
1)The Simple Combo box displays an edit area with an attached list box always visible immediately below the edit area. A simple combo box displays the contents of its list all the time. The user can select an item from the list or type an item in the edit box portion of the combo box. A scroll bar is displayed beside the list if there are too many items to be displayed in the list box area.
2)The Dropdown Combo box first appears as only an edit area with a down arrow button at the right. The list portion stays hidden until the user clicks the down-arrow button to drop down the list portion. The user can either select a value from the list or type a value in the edit area.
3) The Dropdown list combo box turns the combo box into a Dropdown list box. At run time , the control looks like the Dropdown combo box. The user could click the down arrow to view the list. The difference between Dropdown combo & Dropdown list combo is that the edit area in the Dropdown list combo is disabled. The user can only select an item and cannot type anything in the edit area. Anyway this area displays the selected item.
Basic properties
1) Sorted :-
if you want the items to be always sorted , set this property to True. This property must be set at design time. The ListBox control easily sort text items but not numbers. To perform sorting of numbers you must format them with leading zeros. For example the number 10 as 010 and 5 as 005
2) Style : -
This property determines the appearance of the control. Set value 0 for The Simple Combo box , set 1 for The Dropdown Combo box, and set value 2 for Dropdown list combo box
The ComboBox Control’s method :
1) AddItem :-
To add items to the list, use the AddItem method. Its syntax is as follows:-
combo.AddItem item , index
The item parameter is the string to be added to the list, and index is its order.
The index argument is optional. If you omit it the string is appended to the bottom of the list.
2) Removeitem: -
This method remove an item by using index value of the item. Its syntax is :
List1.RemoveItem index
Example : List1.RemoveItem 0
3) Clear:-
The clear method removes all the items from the control. Its syntax is :
List1.clear
4) Listcount :-
This give the number of items in the list.
5) List() :-
This is an array that holds the list’s items. The elements List(0) holds the first element of the list, List(1) holds the second item and so on upto List(listcount-1) which is last item.
For example:
For tm = List1.ListCount -1 to 0 Step -1
If List1.List(tm) = ” ” then
List1.RemoveItem tm
End if
Next
This loop scans the elements backward.
6) ListIndex :
This give us the index of the selected item in the List. If multiple items are selected, then ListIndex is the index of the most recently selected item. We can use this property to access specific elements in the list or delete specific items.
For example:
If List1.ListIndex >=0 Then
List1.RemoveItem List.List Index
End If
7) Selcount :
this property reports the number of selected items in a ListBox control with its MultiSelect property set to 1 (simple) or 2(Extended). It is commonly used in conjuction with the selected arry in processing the selected items the control.
8) New index :
This property returns the index of the item most recently added to a ListBox control. This property is used commonly with the ItemData property
note:in Combobox Multiple selections cannot be made. Only one item may be selected from the list.
SCROLL BAR
The ScrollBar is a commonly used control, which let the user select a value between two ends of the control. It has two versions: horizontal and vertical. The HScrollBar and the VScrollBar controls are perfectly identical only directions are different. It represents a set of values. The Min and Max property represents the minimum and maximum value.
The basic property of the scrollbar is:
• Min: - the control’s minimum value.
• Max: - the control’s maximum value.
• Value:- the control’s current value , specified by the indicator’s positions.
The range of values for a scrollbar control is 0 to 32655.
There are two events for scrollbar controls:
1) Change event : - this event occurs every time the user change the indicator’s position and released the muse button. The change event occurs only when the mouse button is released.
Show the current scroll bar's value.
Private VScroll1_Change()
Label1.Caption = VScroll1.Value
End Sub
2) Scroll event :- this event occurs continuously while the indicator is moving .after the mouse button is released this event stop and triggers a single change event .
For example:
' Show the current scroll bar's value.
Private VScroll1_Scroll()
label1.Caption = VScroll1.Value
End Sub
Example
The following figure uses three HScrollBar controls as sliders to control the individual RGB (red, green, blue) components of a color. The three scroll bars have their Min property set to 0 and their Max property set to 255, while their SmallChange is 1 and LargeChange is 16.
USE THE FOLLOWING CODE TO MAKE THIS PROJECT
Private Sub Command1_Click()
HScroll1.Value = 128
HScroll2.Value = 128
HScroll3.Value = 128
End Sub
Private Sub Form_Load()
Picture1.BackColor = RGB(128, 128, 128)
Label4.Caption = HScroll1.Value
Label5.Caption = HScroll2.Value
Label6.Caption = HScroll3.Value
End Sub
Private Sub HScroll1_Change()
Picture1.BackColor = RGB(HScroll1.Value, HScroll2.Value, HScroll3.Value)
End Sub
Private Sub HScroll1_Scroll()
Picture1.BackColor = RGB(HScroll1.Value, HScroll2.Value, HScroll3.Value)
Label4.Caption = HScroll1.Value
End Sub
Private Sub HScroll2_Change()
Picture1.BackColor = RGB(HScroll1.Value, HScroll2.Value, HScroll3.Value)
End Sub
Private Sub HScroll2_Scroll()
Picture1.BackColor = RGB(HScroll1.Value, HScroll2.Value, HScroll3.Value)
Label5.Caption = HScroll2.Value
End Sub
Private Sub HScroll3_Change()
Picture1.BackColor = RGB(HScroll1.Value, HScroll2.Value, HScroll3.Value)
End Sub
Private Sub HScroll3_Scroll()
Picture1.BackColor = RGB(HScroll1.Value, HScroll2.Value, HScroll3.Value)
Label6.Caption = HScroll3.Value
End Sub