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?


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

  • Why not use function ? – kinkajou Aug 29 '11 at 10:10
  • 1
    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

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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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