SlideShare una empresa de Scribd logo
1 de 36
Descargar para leer sin conexión
LECTURE 8

ListBoxes
Selecting items
SUMMARY
 ListBoxes and CheckBoxes
 Selecting items from a list
 Also select corresponding information

 Show selected items

ListBoxes with multiple columns
LISTBOX PROPERTIES
Displays a list of items
0
1
2
3
4
5
6
7

Select ONE item

Select MULTI items

Each item has a position in the ListBox
 Count from the 0 position
ADD ITEMS TO A LISTBOX

.RowSource
.List
.AddItem
LISTBOX PROPERTIES: ADD A LIST
Items from a Named Range

If the named range is a column
 ListBox.RowSource = “RangeName”
 Where RangeName is the name of the range in Excel
List_CarBrands.RowSource = “CarBrands”
LISTBOX PROPERTIES: ADD A LIST
Items from a Named Range

If the named range is a row
 ListBox.List = Application.Transpose(Range(“RangeName”))
 Where RangeName is the name of the range in Excel
List_CarBrands.List =Application.Transpose(Range(“CarBrands”))
LISTBOX PROPERTIES: ADD A LIST
Items from an array

ListBox.List = NameOfArray

List_CarBrands.List = carBrands

 Where carBrands() is an array containing the names of the
brands of cars
 carBrands() has been declared and assigned the correct size and
dimension. I have assigned the names from excel to the
corresponding element of the array using a For loop.
LISTBOX PROPERTIES: ADD ITEMS
Items one at a time

ListBox.AddItem ListItem
 Where ListItem is the item you want to add to the list
 There is NO =
 If ListItem is text it needs to be in “ ”
List_CarBrands.AddItem “BMW”

You can use a With statement just like we did for
ComboBoxes.
With List_CarBrands
.AddItem “BMW”
.AddItem “Fiat”
End With

You can use ranges
instead of text
CLEAR THE LIST

.Clear
LISTBOX PROPERTIES: CLEAR LIST
Clear entire list

ListBox.Clear
If you are showing what the user has selected in a
second ListBox, you may need to clear it if they
change their selection
ListBox.RowSource
Add a named range (column)

ListBox.List
Add a named range (row)
Add items from an array

ListBox.AddItem
Add items one by one

ListBox.Clear
Clear all items in the ListBox

QUICK
SUMMARY
L i s t B ox
p ro p e r t i e s fo r
adding and
c l e a r i n g i te m s
f ro m a L i s t B ox
EXERCISE 1. ADD ITEMS TO A LIST
Download Lecture 8 Student Example.xlsm
Open Userform1
Use one of the methods just shown to add the car
brands to List_CarBrands.
GET INFO ABOUT WHAT IS
IN THE LISTBOX
(AND USER SELECTIONS)

.ListCount
.Value
.ListIndex
.List(i)
.Selected(i)
LISTBOX PROPERTIES: COUNT ITEMS
Count number of list items

ListBox.ListCount
 Returns the number of items shown in the ListBox

Dim numCars as Integer
numCars = List_CarBrands.ListCount
 What is the value of numCars?
For i = 1 to List_CarBrands.ListCount
…
Next i
 How many times will this loop run?
LISTBOX PROPERTIES: WHAT’S SELECTED?
What item was selected?

ListBox.Value
 Returns the item that is selected in the list
 ONLY works for Single Select ListBoxes NOT Multi Select

MsgBox (List_CarBrands.Value)
 What will be shown in the message box?

Range(“SelectedCar”).Value = List_CarBrands.Value
 What will be outputted to the above named range?
LISTBOX PROPERTIES: WHAT’S SELECTED?
The position of selected item

ListBox.ListIndex
 Returns the position of the item that is selected in the list
 Will only return a number

 ONLY works for Single Select ListBoxes NOT Multi Select
 Counts from 0.

MsgBox (List_CarBrands.ListIndex)
 What will be shown in the message box?
LISTBOX PROPERTIES: GET ITEMS FROM LIST
What is the ith list item?

ListBox.List(i)
 Returns the i th item from the list
 Works for Single Select and Multi Select
 Counts from 0
 We cannot use it to add items to a list
 E.g., ListBox.List(i) = …

MsgBox (List_CarBrands.List(2))
 What will be shown in the message box?
LISTBOX PROPERTIES: WHAT’S SELECTED?
What item(s) were selected?

ListBox.Selected(i) is True or False
 = True if item is selected
 = False if item is not selected
 Where i is a number or variable
 i represents a position in the ListBox
 Counts from 0

i=0
i=1
i=2
i=3
i=4
i=5
i=6
i=7

Use .Selected(i) to:
 Test whether an item in the list has been selected from
Multi-select ListBox (use .ListIndex or .Value for single select)
 Test whether ListBox.Selected(i) is TRUE or FALSE using an Ifstatement or Select Case (you’ll need a For-loop too)
EXERCISE 2. TEST WHAT IS SELECTED
Open UserForm1
When the command button is clicked
 Loop through each item in the ListBox (use .ListCount)
 Inside the loop, test if the i th item has been selected
 If it has been selected, then show the selection in a
message box.

i=1

i=4

i=5

i=7
ListBox.ListCount
Count the number of list items

ListBox.Value
Return the selected item

ListBox.ListIndex
Return the position of selected item

ListBox.List(i)
Return the i th list item

ListBox.Selected(i)
TRUE if the i th item is selected
FALSE if the i th item is not selected

QUICK
SUMMARY
L i s t B ox
p ro p e r t i e s fo r
g ett i n g i nfo
a b o u t l i s t i te m s
and user
selections
SELECT LIST ITEMS
WITHIN YOUR CODE

.Selected(i)
LISTBOX PROPERTIES: MAKE SELECTIONS
Select or unselect list items

ListBox.Selected(i) is True or False
 = True if item is selected
 = False if item is not selected
 Where i is a number or variable
 i represents a position in the ListBox
 Counts from 0

Use .Selected(i) to:
 Select an item in the list from within the code
 Deselect an item in the list from within the code

i=0
i=1
i=2
i=3
i=4
i=5
i=6
i=7
EXAMPLE. SELECT ITEMS IN A LIST
 Write code to select Mercedes from the listbox:
 Mercedes is 4 th , but counting from 0 it is 3 rd .

List_CarBrands.Selected(3) = True
EXAMPLE. SELECT ITEMS IN A LIST
Write code to select Fiat, Mercedes and Porche:

List_CarBrands.Selected(1) = True
List_CarBrands.Selected(3) = True
List_CarBrands.Selected(5) = True

Make sure List_CarBrands
is MultiSelect
EXERCISE 3. SELECT ITEMS IN A LIST
Open Userform2. Add car brands to the ListBox.
A checkbox can have a value of TRUE or FALSE
 checkbox1.value = True (means it’s checked)
 checkbox1.value = False (means it’s not checked)

In the procedure for clicking the check box:
 Write code to check if the value of the checkbox is true
 If it is true (so it’s checked) then select all items in the ListBox

Make sure List_CarBrands
is MultiSelect
EXERCISE 4. UNSELECT ITEMS IN A LIST
Open Userform2
Amend your code from Exercise 2
 If the checkbox is de-selected (i.e., the value is not true)
then unselect every item in the list.
LISTBOX PROPERTIES
What’s the difference between…
 ListBox.Value,
 ListBox.List(),
 ListBox.ListIndex and
 ListBox.Selected()?

These 2 only work for
single select ListBoxes

ListBox.Selected() is equal to TRUE or FALSE only.
ListBox.ListIndex is equal to the numbered
position of the selected item.
ListBox.Value is equal to the value of the selected
item.
ListBox.List() is equal to the value of the i th item.
That item may or may not have been selected.
LISTBOXES

Multi-column
MULTI-COLUMN LISTBOXES

Change the ColumnCount property to the number
of columns you want
Use .RowSource to add a named range
MULTI-COLUMN LISTBOXES

The number of columns
MULTI-COLUMN LISTBOXES

Do you want column
headings?
True = Yes, False = No
COLUMNHEADINGS = TRUE

Takes the row ABOVE your range as the headings
MULTI-COLUMN LISTBOXES

Adjust width of columns
Separate with ;
EXERCISE 5. MULTI-COLUMN LISTBOX
Insert a new userform.
Insert a large ListBox big enough to show all car
brands and prices.
 Make the ListBox multi-column.
 Name a range containing all prices as wells as row labels.
 Show this named range in your ListBox.
LEARNING OUTCOMES
You are ready to move on when…
 LO32: You can add items one by one or as a list to a
ListBox.
 LO33: You can determine which ListBox property should be
used to get information about the ListBox and user
selections.
 LO34: You can create a multi-column ListBox using a named
range in Excel.
THE END

Más contenido relacionado

Similar a MA3696 Lecture 8

In this homework- you will write a program modify program you wrote in.pdf
In this homework- you will write a program modify program you wrote in.pdfIn this homework- you will write a program modify program you wrote in.pdf
In this homework- you will write a program modify program you wrote in.pdfEvanpZjSandersony
 
Implementation The starter code includes List.java. You should not c.pdf
Implementation The starter code includes List.java. You should not c.pdfImplementation The starter code includes List.java. You should not c.pdf
Implementation The starter code includes List.java. You should not c.pdfmaheshkumar12354
 
Vb6 ch.7-3 cci
Vb6 ch.7-3 cciVb6 ch.7-3 cci
Vb6 ch.7-3 cciFahim Khan
 
Lecture 18Dynamic Data Structures and Generics (II).docx
Lecture 18Dynamic Data Structures and Generics (II).docxLecture 18Dynamic Data Structures and Generics (II).docx
Lecture 18Dynamic Data Structures and Generics (II).docxSHIVA101531
 
This application is used to keep track of inventory information. A c.pdf
This application is used to keep track of inventory information. A c.pdfThis application is used to keep track of inventory information. A c.pdf
This application is used to keep track of inventory information. A c.pdfambikacomputer4301
 
For this lab you will complete the class MyArrayList by implementing.pdf
For this lab you will complete the class MyArrayList by implementing.pdfFor this lab you will complete the class MyArrayList by implementing.pdf
For this lab you will complete the class MyArrayList by implementing.pdffashiongallery1
 
Eo gaddis java_chapter_12_5e
Eo gaddis java_chapter_12_5eEo gaddis java_chapter_12_5e
Eo gaddis java_chapter_12_5eGina Bullock
 
Eo gaddis java_chapter_12_5e
Eo gaddis java_chapter_12_5eEo gaddis java_chapter_12_5e
Eo gaddis java_chapter_12_5eGina Bullock
 
Question 1A Python list is ��.. set of items.an unorderedan or.pdf
Question 1A Python list is ��.. set of items.an unorderedan or.pdfQuestion 1A Python list is ��.. set of items.an unorderedan or.pdf
Question 1A Python list is ��.. set of items.an unorderedan or.pdfclimatecontrolsv
 
Question 1A Python list isset of items.an unorderedan ordere.pdf
Question 1A Python list isset of items.an unorderedan ordere.pdfQuestion 1A Python list isset of items.an unorderedan ordere.pdf
Question 1A Python list isset of items.an unorderedan ordere.pdfclimatecontrolsv
 
How to Create Drop Down Lists in Excel, step by step
How to Create Drop Down Lists in Excel, step by stepHow to Create Drop Down Lists in Excel, step by step
How to Create Drop Down Lists in Excel, step by stepSelect Distinct Limited
 
Data Structures- Part3 arrays and searching algorithms
Data Structures- Part3 arrays and searching algorithmsData Structures- Part3 arrays and searching algorithms
Data Structures- Part3 arrays and searching algorithmsAbdullah Al-hazmy
 
Basic controls in asp
Basic controls in aspBasic controls in asp
Basic controls in aspSireesh K
 

Similar a MA3696 Lecture 8 (20)

Array list(1)
Array list(1)Array list(1)
Array list(1)
 
In this homework- you will write a program modify program you wrote in.pdf
In this homework- you will write a program modify program you wrote in.pdfIn this homework- you will write a program modify program you wrote in.pdf
In this homework- you will write a program modify program you wrote in.pdf
 
Lists
ListsLists
Lists
 
Implementation The starter code includes List.java. You should not c.pdf
Implementation The starter code includes List.java. You should not c.pdfImplementation The starter code includes List.java. You should not c.pdf
Implementation The starter code includes List.java. You should not c.pdf
 
Vb6 ch.7-3 cci
Vb6 ch.7-3 cciVb6 ch.7-3 cci
Vb6 ch.7-3 cci
 
Lecture 18Dynamic Data Structures and Generics (II).docx
Lecture 18Dynamic Data Structures and Generics (II).docxLecture 18Dynamic Data Structures and Generics (II).docx
Lecture 18Dynamic Data Structures and Generics (II).docx
 
This application is used to keep track of inventory information. A c.pdf
This application is used to keep track of inventory information. A c.pdfThis application is used to keep track of inventory information. A c.pdf
This application is used to keep track of inventory information. A c.pdf
 
For this lab you will complete the class MyArrayList by implementing.pdf
For this lab you will complete the class MyArrayList by implementing.pdfFor this lab you will complete the class MyArrayList by implementing.pdf
For this lab you will complete the class MyArrayList by implementing.pdf
 
Eo gaddis java_chapter_12_5e
Eo gaddis java_chapter_12_5eEo gaddis java_chapter_12_5e
Eo gaddis java_chapter_12_5e
 
Eo gaddis java_chapter_12_5e
Eo gaddis java_chapter_12_5eEo gaddis java_chapter_12_5e
Eo gaddis java_chapter_12_5e
 
Question 1A Python list is ��.. set of items.an unorderedan or.pdf
Question 1A Python list is ��.. set of items.an unorderedan or.pdfQuestion 1A Python list is ��.. set of items.an unorderedan or.pdf
Question 1A Python list is ��.. set of items.an unorderedan or.pdf
 
javacollections.pdf
javacollections.pdfjavacollections.pdf
javacollections.pdf
 
Question 1A Python list isset of items.an unorderedan ordere.pdf
Question 1A Python list isset of items.an unorderedan ordere.pdfQuestion 1A Python list isset of items.an unorderedan ordere.pdf
Question 1A Python list isset of items.an unorderedan ordere.pdf
 
How to Create Drop Down Lists in Excel, step by step
How to Create Drop Down Lists in Excel, step by stepHow to Create Drop Down Lists in Excel, step by step
How to Create Drop Down Lists in Excel, step by step
 
C# Collection classes
C# Collection classesC# Collection classes
C# Collection classes
 
Ms excel
Ms excelMs excel
Ms excel
 
Csharp_List
Csharp_ListCsharp_List
Csharp_List
 
Data Structures- Part3 arrays and searching algorithms
Data Structures- Part3 arrays and searching algorithmsData Structures- Part3 arrays and searching algorithms
Data Structures- Part3 arrays and searching algorithms
 
Python list
Python listPython list
Python list
 
Basic controls in asp
Basic controls in aspBasic controls in asp
Basic controls in asp
 

Más de Brunel University (9)

MA3696 Lecture 9
MA3696 Lecture 9MA3696 Lecture 9
MA3696 Lecture 9
 
MA3696 Lecture 7
MA3696 Lecture 7MA3696 Lecture 7
MA3696 Lecture 7
 
MA3696 Lecture 6
MA3696 Lecture 6MA3696 Lecture 6
MA3696 Lecture 6
 
MA3696 Lecture 5
MA3696 Lecture 5MA3696 Lecture 5
MA3696 Lecture 5
 
Ma3696 lecture 4
Ma3696 lecture 4Ma3696 lecture 4
Ma3696 lecture 4
 
Ma3696 Lecture 3
Ma3696 Lecture 3Ma3696 Lecture 3
Ma3696 Lecture 3
 
Ma3696 Lecture 2
Ma3696 Lecture 2Ma3696 Lecture 2
Ma3696 Lecture 2
 
Ma3696 Lecture 0
Ma3696 Lecture 0Ma3696 Lecture 0
Ma3696 Lecture 0
 
Ma3696 Lecture 1
Ma3696 Lecture 1Ma3696 Lecture 1
Ma3696 Lecture 1
 

Último

ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Projectjordimapav
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17Celine George
 
Multi Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP ModuleMulti Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP ModuleCeline George
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research DiscourseAnita GoswamiGiri
 
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQ-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQuiz Club NITW
 
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxBIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxSayali Powar
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...Nguyen Thanh Tu Collection
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
MS4 level being good citizen -imperative- (1) (1).pdf
MS4 level   being good citizen -imperative- (1) (1).pdfMS4 level   being good citizen -imperative- (1) (1).pdf
MS4 level being good citizen -imperative- (1) (1).pdfMr Bounab Samir
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
Unraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptxUnraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptx
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptxDhatriParmar
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvRicaMaeCastro1
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationdeepaannamalai16
 

Último (20)

ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Project
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17
 
Multi Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP ModuleMulti Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP Module
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research Discourse
 
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQ-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
 
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxBIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
 
prashanth updated resume 2024 for Teaching Profession
prashanth updated resume 2024 for Teaching Professionprashanth updated resume 2024 for Teaching Profession
prashanth updated resume 2024 for Teaching Profession
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
MS4 level being good citizen -imperative- (1) (1).pdf
MS4 level   being good citizen -imperative- (1) (1).pdfMS4 level   being good citizen -imperative- (1) (1).pdf
MS4 level being good citizen -imperative- (1) (1).pdf
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
Unraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptxUnraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptx
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
 
Paradigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTAParadigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTA
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentation
 

MA3696 Lecture 8

  • 2. SUMMARY  ListBoxes and CheckBoxes  Selecting items from a list  Also select corresponding information  Show selected items ListBoxes with multiple columns
  • 3. LISTBOX PROPERTIES Displays a list of items 0 1 2 3 4 5 6 7 Select ONE item Select MULTI items Each item has a position in the ListBox  Count from the 0 position
  • 4. ADD ITEMS TO A LISTBOX .RowSource .List .AddItem
  • 5. LISTBOX PROPERTIES: ADD A LIST Items from a Named Range If the named range is a column  ListBox.RowSource = “RangeName”  Where RangeName is the name of the range in Excel List_CarBrands.RowSource = “CarBrands”
  • 6. LISTBOX PROPERTIES: ADD A LIST Items from a Named Range If the named range is a row  ListBox.List = Application.Transpose(Range(“RangeName”))  Where RangeName is the name of the range in Excel List_CarBrands.List =Application.Transpose(Range(“CarBrands”))
  • 7. LISTBOX PROPERTIES: ADD A LIST Items from an array ListBox.List = NameOfArray List_CarBrands.List = carBrands  Where carBrands() is an array containing the names of the brands of cars  carBrands() has been declared and assigned the correct size and dimension. I have assigned the names from excel to the corresponding element of the array using a For loop.
  • 8. LISTBOX PROPERTIES: ADD ITEMS Items one at a time ListBox.AddItem ListItem  Where ListItem is the item you want to add to the list  There is NO =  If ListItem is text it needs to be in “ ” List_CarBrands.AddItem “BMW” You can use a With statement just like we did for ComboBoxes. With List_CarBrands .AddItem “BMW” .AddItem “Fiat” End With You can use ranges instead of text
  • 10. LISTBOX PROPERTIES: CLEAR LIST Clear entire list ListBox.Clear If you are showing what the user has selected in a second ListBox, you may need to clear it if they change their selection
  • 11. ListBox.RowSource Add a named range (column) ListBox.List Add a named range (row) Add items from an array ListBox.AddItem Add items one by one ListBox.Clear Clear all items in the ListBox QUICK SUMMARY L i s t B ox p ro p e r t i e s fo r adding and c l e a r i n g i te m s f ro m a L i s t B ox
  • 12. EXERCISE 1. ADD ITEMS TO A LIST Download Lecture 8 Student Example.xlsm Open Userform1 Use one of the methods just shown to add the car brands to List_CarBrands.
  • 13. GET INFO ABOUT WHAT IS IN THE LISTBOX (AND USER SELECTIONS) .ListCount .Value .ListIndex .List(i) .Selected(i)
  • 14. LISTBOX PROPERTIES: COUNT ITEMS Count number of list items ListBox.ListCount  Returns the number of items shown in the ListBox Dim numCars as Integer numCars = List_CarBrands.ListCount  What is the value of numCars? For i = 1 to List_CarBrands.ListCount … Next i  How many times will this loop run?
  • 15. LISTBOX PROPERTIES: WHAT’S SELECTED? What item was selected? ListBox.Value  Returns the item that is selected in the list  ONLY works for Single Select ListBoxes NOT Multi Select MsgBox (List_CarBrands.Value)  What will be shown in the message box? Range(“SelectedCar”).Value = List_CarBrands.Value  What will be outputted to the above named range?
  • 16. LISTBOX PROPERTIES: WHAT’S SELECTED? The position of selected item ListBox.ListIndex  Returns the position of the item that is selected in the list  Will only return a number  ONLY works for Single Select ListBoxes NOT Multi Select  Counts from 0. MsgBox (List_CarBrands.ListIndex)  What will be shown in the message box?
  • 17. LISTBOX PROPERTIES: GET ITEMS FROM LIST What is the ith list item? ListBox.List(i)  Returns the i th item from the list  Works for Single Select and Multi Select  Counts from 0  We cannot use it to add items to a list  E.g., ListBox.List(i) = … MsgBox (List_CarBrands.List(2))  What will be shown in the message box?
  • 18. LISTBOX PROPERTIES: WHAT’S SELECTED? What item(s) were selected? ListBox.Selected(i) is True or False  = True if item is selected  = False if item is not selected  Where i is a number or variable  i represents a position in the ListBox  Counts from 0 i=0 i=1 i=2 i=3 i=4 i=5 i=6 i=7 Use .Selected(i) to:  Test whether an item in the list has been selected from Multi-select ListBox (use .ListIndex or .Value for single select)  Test whether ListBox.Selected(i) is TRUE or FALSE using an Ifstatement or Select Case (you’ll need a For-loop too)
  • 19. EXERCISE 2. TEST WHAT IS SELECTED Open UserForm1 When the command button is clicked  Loop through each item in the ListBox (use .ListCount)  Inside the loop, test if the i th item has been selected  If it has been selected, then show the selection in a message box. i=1 i=4 i=5 i=7
  • 20. ListBox.ListCount Count the number of list items ListBox.Value Return the selected item ListBox.ListIndex Return the position of selected item ListBox.List(i) Return the i th list item ListBox.Selected(i) TRUE if the i th item is selected FALSE if the i th item is not selected QUICK SUMMARY L i s t B ox p ro p e r t i e s fo r g ett i n g i nfo a b o u t l i s t i te m s and user selections
  • 21. SELECT LIST ITEMS WITHIN YOUR CODE .Selected(i)
  • 22. LISTBOX PROPERTIES: MAKE SELECTIONS Select or unselect list items ListBox.Selected(i) is True or False  = True if item is selected  = False if item is not selected  Where i is a number or variable  i represents a position in the ListBox  Counts from 0 Use .Selected(i) to:  Select an item in the list from within the code  Deselect an item in the list from within the code i=0 i=1 i=2 i=3 i=4 i=5 i=6 i=7
  • 23. EXAMPLE. SELECT ITEMS IN A LIST  Write code to select Mercedes from the listbox:  Mercedes is 4 th , but counting from 0 it is 3 rd . List_CarBrands.Selected(3) = True
  • 24. EXAMPLE. SELECT ITEMS IN A LIST Write code to select Fiat, Mercedes and Porche: List_CarBrands.Selected(1) = True List_CarBrands.Selected(3) = True List_CarBrands.Selected(5) = True Make sure List_CarBrands is MultiSelect
  • 25. EXERCISE 3. SELECT ITEMS IN A LIST Open Userform2. Add car brands to the ListBox. A checkbox can have a value of TRUE or FALSE  checkbox1.value = True (means it’s checked)  checkbox1.value = False (means it’s not checked) In the procedure for clicking the check box:  Write code to check if the value of the checkbox is true  If it is true (so it’s checked) then select all items in the ListBox Make sure List_CarBrands is MultiSelect
  • 26. EXERCISE 4. UNSELECT ITEMS IN A LIST Open Userform2 Amend your code from Exercise 2  If the checkbox is de-selected (i.e., the value is not true) then unselect every item in the list.
  • 27. LISTBOX PROPERTIES What’s the difference between…  ListBox.Value,  ListBox.List(),  ListBox.ListIndex and  ListBox.Selected()? These 2 only work for single select ListBoxes ListBox.Selected() is equal to TRUE or FALSE only. ListBox.ListIndex is equal to the numbered position of the selected item. ListBox.Value is equal to the value of the selected item. ListBox.List() is equal to the value of the i th item. That item may or may not have been selected.
  • 29. MULTI-COLUMN LISTBOXES Change the ColumnCount property to the number of columns you want Use .RowSource to add a named range
  • 31. MULTI-COLUMN LISTBOXES Do you want column headings? True = Yes, False = No
  • 32. COLUMNHEADINGS = TRUE Takes the row ABOVE your range as the headings
  • 33. MULTI-COLUMN LISTBOXES Adjust width of columns Separate with ;
  • 34. EXERCISE 5. MULTI-COLUMN LISTBOX Insert a new userform. Insert a large ListBox big enough to show all car brands and prices.  Make the ListBox multi-column.  Name a range containing all prices as wells as row labels.  Show this named range in your ListBox.
  • 35. LEARNING OUTCOMES You are ready to move on when…  LO32: You can add items one by one or as a list to a ListBox.  LO33: You can determine which ListBox property should be used to get information about the ListBox and user selections.  LO34: You can create a multi-column ListBox using a named range in Excel.