709-218-7927

The Landfall Garden House

60 Canon Bayley Road

Bonavista, Newfoundland

CANADA A0C 1B0

CPRGreaves@gmail.com

Home

Christopher Greaves

Using List Boxes

In the previous lesson we learned how to initialize our list box with data; in this lesson we will learn how to detect and use the list box entry that has been selected by the user.

In VBE double-click on the list box. You will be rewarded with a skeletal event:

Private Sub lbProvinces_Click()
End Sub

We will perform a very simple task, when the user clicks on an item in the list box – we will use the selected provincial code to prime the text box! This is not a very useful thing to do, but it will show you how to capture data that you can then use elsewhere in your application:

Private Sub lbProvinces_Click()
Dim strProv As String
strProv = Me.lbProvinces.List(Me.lbProvinces.ListIndex)
Me.tbInput = strProv
End Sub

Note that we have manipulated the string in two stages, first loading it into a string variable “strProv”, and then moving it to the text box. Remember that “Me” represents the current host – in this case the GUI form in which we find ourselves.

709-218-7927 CPRGreaves@gmail.com

Bonavista, Sunday, December 08, 2024 9:31 AM

Copyright © 1990-2024 Chris Greaves. All Rights Reserved.