views:

154

answers:

1

Hi, any tips on creating a global array to use in a realBASIC project using 'add property'? Pictured below is my attempt.

http://i17.photobucket.com/albums/b52/orubap/basic.jpg

Using camModel(1) compiles and runs but it doesn't return anything. Using camModel(4) throws an out of bounds error so I'm guessing I'm half way there.

Suggestions?

+2  A: 

Even though the code compiles, that isn't a valid way of initializing an array. At the very least doing so isn't mentioned anywhere in the manuals. I would say that the compiler is quietly failing on that one, as opposed to flagging it as an error. You'll have to place the values via an init method, say in App.Open. Also, don't forget that array indexes are 0-based, even during initialization. So, going by the code you've given declare the array property for three values:

camModel(2) as String

and then in the App.Open event:

camModel(0) = "Nikon"
camModel(1) = "Sony"
camModel(2) = "Philips"

However, if it were me doing it, I would declare the property thus:

camModel(-1) as String

and then populate with the Array function:

camModel = Array("Nikon", "Sony", "Philips")

That way you can add more models later and not have to futz with the bounds of the array each time.

Philip Regan