Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retreiving data from a listbox to an array.

Status
Not open for further replies.

cookeg

IS-IT--Management
Jun 18, 2001
2
AU
I have a multi column listbox that reads values from a table. I want to select multiple values from the listbox and write them to an array. I have the InterActiveChange;
FOR I = 1 to THIS.ListCount
IF THIS.Selected(I)
list_count = list_count + 1
* add new row to existing array
DIMENSION selected_list[list_count]
selected_list[list_count] = THIS.value
ENDIF
ENDFOR
I bomb out with a source not found error when I go back to the listbox, and the above dosn't work . I have never used a list box before. All the help Ive found is about filling but none on retreiving. Where am I going wrong?
 
Try before your code
list_count = 0
public array selected_list(THIS.ListCount)
 
There's nothing inherent in the code you show which would cause an error. (I assume that somewhere else you're resetting the dimension of selected_list so that it doesn't just keep growing.)

Exactly what error message are you getting?

Jim
 
Obviously!!! Many things are wrong in that.. Sorry to say that....

1. I would suggest set the multiselect option of the list box to .T.

2. I would put the array building code to the LOSTFOCUS event of the ListBox

MyListBox.LostFocusEvent
------------------------
FOR I = 1 to THIS.ListCount
IF THIS.Selected(I)
m.list_count = m.list_count + 1
* add new row to existing array
DIMENSION selected_list[m.list_count]
selected_list[m.list_count] = THIS.value
ENDIF
ENDFOR

The idea is to do the array building only once when the selection is completed.

3. Remember to define the array suitably to have the value available at the form level. May be by defining the array at Form level. Otherwise, this could remain a local array and not available at the place where you want it. The redimensioning of the array is ok if done here above. ramani :-9
(Subramanian.G)
FoxAcc
ramani_g@yahoo.com
LET KNOW IF THIS HELPED. ENOUGH EXPERTS ARE HERE TO HELP YOU OUT! BEST OF LUCK :)
 
uffffffff ... i just left the cut & paste with the error.. sorry... the correct reading in above for...

MyListBox.LostFocusEvent
------------------------
FOR I = 1 to THIS.ListCount
IF THIS.Selected(I)
m.lcount = m.lcount + 1
* add new row to existing array
DIMENSION selected_list[m.lcount]
selected_list[m.lcount] = THIS.List(m.lcount)
ENDIF
ENDFOR

SOrry for the error... ramani :-9
(Subramanian.G)
FoxAcc
ramani_g@yahoo.com
LET KNOW IF THIS HELPED. ENOUGH EXPERTS ARE HERE TO HELP YOU OUT! BEST OF LUCK :)
 
Thank you for your responses. I had originally had the code in the LostFocusEvent but could not get it to work because I was using THIS.Value. Always ended up with the same value in the array. The THIS.list was what I needed and solved my problem.

Many Thanks,
Garry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top