Your code would presumably error since the MAKE OBJECT CUBE command is expecting an Object INDEX from 1 to (However many objects are allowed). In your example, DBpro is pulling the value out of the Buildings() array at position of counter, which will be ZERO, so it'll fail. This zero will be passed back into the Make OBJECT Cube command as the Object ID..
The DIM statement is also not being used appropriately. DIM is a declaration. Generally, we'd declare our ARRAY at the top of the program, then proceed to fill it up with stuff, numbers in this case. Bellow I've put the dim at the start of the program. So the Buildings array is being declared and upon execution it'll be sized to hold 30 (31 actually) separate integer values in it.
If we want to store Object Numbers in the buildings array, then create our object using the Object Number stored within our array which is what I think your after. Then we need to assign each cell in the array with a valid Object Number. Once that's done, we can be use the buildings() array like so..
rem declare the array with space for 30 values
dim buildings(30)
rem create building
for counter=2 to 29
rem Store the Object ID in our builds array
buildings(counter) = Counter
rem the object using the value stored in the buildings array at position counter for the Objects ID/Number
make object cube buildings(counter),rnd(25)
next counter
Most people tend to roll themselves a '
get free object' function. Which is just a routine that searches for Object Numbers that are not currently in use. If you search, you'll find lots of solutions on the forums already.