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.

Hello I am just getting started with MapBasic and I have run in to some trouble trying to count the items in a custom type i have tried accomplishing this by running a loop until an error occur. Problem is that the error trapping does not seem to happen i just keep getting a dialog with an out of range error message what am I missing here? My code is as follows:

Type KeyValuePair
Pos As Integer
Key As Integer
StringVal As String
End Type

Type PopupMenu_Items
ControlId As Integer
Values() As KeyValuePair
End Type

Sub CountPopupMenu_Items (countResult As Integer, arrayToCount() As PopupMenu_Items)
Dim i As Integer 
Dim controlId As Integer
i = 1
Do While i = i
    controlId = arrayToCount(i).ControlId
    OnError Goto endOfArray
    i = i + 1
Loop
last_exit:
    exit sub
endOfArray:
    countResult = i - 1
    resume last_exit
End Sub
share|improve this question
    
"Do While i = i"? –  sys49152 May 9 '14 at 17:56
    
well i just wanted the loop to run until the out of range error was reached and then see how far my counter got that way I would know how many items my array contained. i is always equal to i hence the loop keeps running until it is broken by the error. If you have a better suggestion I am all ears. :) –  Kriya Oceans May 9 '14 at 18:26
    
My problem now is that the error is thrown the error handling I made is not working. –  Kriya Oceans May 9 '14 at 18:29
    
I have also tried Ubound() which does not work with custom types. And I was looking for a foreach loop which does not seem to exist in MapBasic. I dont really like the idea of catching an error in order to count items in an array. –  Kriya Oceans May 9 '14 at 19:20
    
Did you try Ubound(arrayToCount) to find the size of the array? –  Peter Horsbøll Møller May 12 '14 at 12:15

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.