Thursday, December 16, 2010

Array Base Index and Base in Lotusscript (Option Base 0|1)

I happened to stumble upon the base index of arrays when a colleague of mine came up with a doubt in Base command in lotus script

It was interesting to find the following,

Create a couple of buttons and put the following fragments of code in each of them

option base 0
dim myArray[10] as string
msgbox cstr(lbound(myArray)) '--> this would prompt 0

This means now the array can contain 11 string values, where the index varies from 0 to 10

option base 1
dim myArray[10] as string
msgbox cstr(lbound(myArray)) '--> this would prompt 1

And this means the array can contain 10 string values, where the index varies from 1 to 10

Inference :

Option Base 1 in lotus script implies that the arrays will have a lower bound of 1 as is the case with Formula language

Extra Note :
In case of Java, an array of the following sort say,
String[] x= new String[10]

x shall hold 10 values with indices varying from 1 to 10

Hope this helps :)

4 comments:

  1. I would avoid using Option Base 1. If I need an array of strings to go between 1 and 10, I would declare it as
    Dim myArr(1 to 10) as String
    In many case you can also use lists.

    ReplyDelete
  2. Since when do Java arrays start with 1? AFAIK there's not offset. So you either have 0-9 or 0-10 (I would need to check :blush: ). Use BlueJ to test such things.

    ReplyDelete
  3. @TexasSwede - Absolutely. I completely agree with you and I dont intend to use Option Base 1. Its just that I happened to stumble upon it and wanted to share it :)

    ReplyDelete
  4. @NotesSensei - Thanks a lot. I never knew about BlueJ before..

    Have downloaded the same version 3.0.4. I kind of like the interface.. Surely a new place to enjoy for a while :)

    ReplyDelete