Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have created a MultiListBox control which is populated with a list of all currently loaded TAB file names in MapInfo. The user selections are then read from the MultiListBox and added to another array (so I can use these in an INSERT command later on).

However the problem I am getting is when I select records from my MultiListBox. As an example I have selected 3 TAB files (3 records) from my MultiListBox but my array size is only 2. If I select 5 records from my list my array size is only 4 and so on. When I select just the 1 record from my list my array size is saying 0.

If someone could help I would be very grateful.

Cheers

Rob O'Brien

Here are some code snippets to help.

Dim i as integer
Dim j as integer

i = NumTables()

ReDim TableArray(i)

For j = 1 to i
TableArray(j) = TableInfo(j, TAB_INFO_NAME)
Next

Print "Table Array no. of records: " + UBound(TableArray)

' code to read the values selected in the MultiListBox
Dim iSel, j As Integer

j = 0
iSel = ReadControlValue(1)

Do Until iSel = 0
j = j + 1               
Redim SelectionArray(j) ' re-size our array. Now = 1
SelectionArray(j) = iSel    
iSel = ReadControlValue(1)      

Print "Selection Array items selected: " + SelectionArray(j)        

Loop

Print "MultiListBox no. of selected records: " + UBound(SelectionArray)
share|improve this question
add comment

1 Answer

Rob, One mistake I have done is that I had a handler on my MultiListBox and this was causing issues because I read one value thru the handler and so when reading the values in the handler of my OKButton, this one value was not read.

You could try to run thru the selected items once without "reading" them and then once you reach item 0, start again. In that way you can be sure to read all the selected elements.

Could look like this:

Dim iSel, j As Integer

 '**This is just for resetting the selected items to the first    
iSel = ReadControlValue(1)
Do Until iSel = 0
   iSel = ReadControlValue(1)      
Loop

j = 0
iSel = ReadControlValue(1)

Do Until iSel = 0
   j = j + 1               
   Redim SelectionArray(j) ' re-size our array. Now = 1
   SelectionArray(j) = iSel    
   iSel = ReadControlValue(1)      

   Print "Selection Array items selected: " + SelectionArray(j)        
Loop

Print "MultiListBox no. of selected records: " + UBound(SelectionArray)
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.