Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top


 Dim name_array() As String
 Redim name_array(10)

How to add value to the array? I know we can add value by specifying index like name_array(i) = "some_value"

But I don't want to specify any index i. Instead is it possible to Add a value to array to last index used.

eg. If i have added to i=5 Will I be able to add to 6th index without specifying index?

share|improve this question
up vote 3 down vote accepted

Shouldn't be that hard to write your own procedure for doing that:

Sub ARRAddItem(arrValues() As String, ByVal sNewValue As String)

Dim nItem As Integer

    nItem = Ubound(arrValues) + 1
    Redim arrValues(nItem)

    arrValues(nItem) = sNewValue

End Sub

Note that it will resize the array with one and insert the value at this index

share|improve this answer
Why not use function ? – kinkajou Aug 29 '11 at 10:10
If you want to use a procedure or a function would depend on the "feedback" from the function you would like. If you would like to know at what index the value was added, you could use a function. Or you could use a function that just gives you a "true" back if the value was added. A function in MapBasic can not return an array, if that was what you were looking for – Peter Horsbøll Møller Aug 29 '11 at 18:04
+1 Thank you for answer – kinkajou Aug 30 '11 at 2:37

It isn't possible unless you write your own function, which keeps track of the index internally. MapBasic simply doesn't offer any modern container classes. Or any classes for that matter.

share|improve this answer
+1 Thanks for answer – kinkajou Aug 29 '11 at 9:23

Your Answer


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.