473,387 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Referencing a listbox in an array

18
I am trying to change a value in an array when the user selects a name a from a list or combo box. Also, I want the highlighted item to be displayed in a Label for the current selection. After all the names are selected from the boxes than I going to write those to a file or table. It sounds real simple and it probably is, but I am having a brain fart.

lblName - label
lstName - name of listbox
arrName (1, lstName) - array to hold item for list box

Thank you.
Sep 19 '07 #1
7 1366
I would suggest uding a combo box with its style property set to "Simple Combo giving you a combo box with a listbox look and in the coding of the combo box on its click event use the following

Label1.Caption = combobox(index).text

Index Refering to the array number of the Combo box
Sep 19 '07 #2
kadghar
1,295 Expert 1GB
I am trying to change a value in an array when the user selects a name a from a list or combo box. Also, I want the highlighted item to be displayed in a Label for the current selection. After all the names are selected from the boxes than I going to write those to a file or table. It sounds real simple and it probably is, but I am having a brain fart.

lblName - label
lstName - name of listbox
arrName (1, lstName) - array to hold item for list box

Thank you.
Declare an integer (dim i as integer) and an array of strings (dim Arr1() as string) in the general declarations.

In the Change event of the listbox there should be something like this:

Expand|Select|Wrap|Line Numbers
  1. i=i+1 
  2. redim preserve arr1(1 to i)
  3. arr1(i) = listbox1.list(listbox1.listindex)
  4. label1.caption = listbox1.list(listbox1.listindex)
now you have all the selected items in the array
HTH
Sep 19 '07 #3
jesse07
18
lblCurrentPlayer.Caption = cmbPlayer(Index).Text

I still get an error. I have tried that syntax before, but I still don't think I am referencing the right part of the combo box. Does the cmbPlayer(Index).Text refer to the selected item from the combo box?
Sep 19 '07 #4
kadghar
1,295 Expert 1GB
lblCurrentPlayer.Caption = cmbPlayer(Index).Text

I still get an error. I have tried that syntax before, but I still don't think I am referencing the right part of the combo box. Does the cmbPlayer(Index).Text refer to the selected item from the combo box?
indexes are from 0 to the elements in the list box - 1

listbox1.listindex will return the hightlighted index, so if you use

lblcurrentplayer.caption = cmbplayer.list(cmbplayer.listindex)

will do
also works for combo boxes
Sep 19 '07 #5
jesse07
18
I've walked away from this, and I am trying this again. I still can only display the number from the combobox of the listindex.

Ex. Combo box has (mike, jim, alex, and pete). When I select Alex it is displayed by the listindex of 2. I want to show the name alex, and then store this in an array.


I cannot refereence cmbbox.list.(cmbbox.listindex) because my version of VBA doesn't have a .list property. Access 2000
Sep 21 '07 #6
kadghar
1,295 Expert 1GB
I've walked away from this, and I am trying this again. I still can only display the number from the combobox of the listindex.

Ex. Combo box has (mike, jim, alex, and pete). When I select Alex it is displayed by the listindex of 2. I want to show the name alex, and then store this in an array.


I cannot refereence cmbbox.list.(cmbbox.listindex) because my version of VBA doesn't have a .list property. Access 2000
I dont know why is this, i dont have access here to check it out, but in the while:

Since you're using a combobox, when you select something its showed as the combobox text. so you can store that by writing in the change procedure something like:

Expand|Select|Wrap|Line Numbers
  1. i=i+1
  2. redim preserve myArry(1 to i)
  3. myarr(i) = combobox1.text
  4. msgbox combobox1.text
Just make sure that the combobox matchrequired property is true.
HTH
Sep 21 '07 #7
jesse07
18
Thanks everyone for your input. I figured it out. I went to the control source feature in Access and put in this code to reference it to a text box. As soon as I had the value linked to the textbox everything else is easy.

=[cmbPlayer].[column](1)

I haven't done much programming the last 5 years, it is amazing how you forget little steps. Thanks again.
Sep 21 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Allan Horwitz | last post by:
When I try to reference the lstproducts.selecteditem.value using autopostback from the lstproducts listbox I get an error? How can I fix my code to get the selected value from the lstproducts...
7
by: 00_ChInkPoIntD12 | last post by:
Can anyone confirm there isn't a Sort() method for WebControl Listbox in Asp.net? It is rather simple to write a method to do the sorting, but just wondering I shouldn't invent the wheel if...
3
by: George | last post by:
Sub ExcelToListBox() Dim xRange As Object Dim ary Dim xValue As String xRange = oXL.Range("A1:A9") 'has letters A-H ary = xRange.value xValue = ary(3, 1) 'xValue = C...
11
by: Zorpiedoman | last post by:
The problem is this: I have a list box. I set an array list as the datasource. I remove an item from the array list. I set the listbox datasource to nothing. I set the listbox datasource to...
14
by: Paul_Madden via DotNetMonster.com | last post by:
Basically I have a listbox to which I add simple STRING items- I have a progress bar which I increment whenever I populate another portion of the complete set of items I wish to add. What I observe...
6
by: Paul | last post by:
Hi All, Framework 1.1 listbox control unable to DataBind I've been googling for an answer to this query that appears quite a lot, but none, it seem, answers my problem directly. I am...
0
by: crespo | last post by:
hi,everyone. I have a question about using listbox in a customized user control.I use a listbox directly in a asp.net page and it works very well,but when I use the same code in a user...
1
by: Sunray | last post by:
I have a form called the sales form and i have 2 sets of listboxes So what happens is. i add items form the bottom set of list boxes which are bound to a data base to the top set of list boxes which...
3
by: Sweetiecakes | last post by:
Hi I have an string array containing file paths. I have added them to a ListBox with AddRange(); When I delete an item from the ListBox, how can I delete the same item from the original...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.