I like the idea of UBound and LBound in concept, I just haven't gone there
in code because it adds a layer of complexity that my brain hasn't rewired
itself for when writing (and re-reading, tweaking) code
Believe it or not, I find that LBound and UBound add a layer of simplicity,
because it's one less thing I have to think about. When I don't know where
an array comes from, I also use LBound to identify the element I need:
FirstElement = MyArray(LBound(MyArray))
SecondElement = MyArray(LBound(MyArray)+1)
etc.
- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
http://PeltierTech.com
_______
"Keith" wrote in message
...
Thank you also to Tom, Bob, and Chip for your feedback. Chip, I like the
idea of UBound and LBound in concept, I just haven't gone there in code
because it adds a layer of complexity that my brain hasn't rewired itself
for when writing (and re-reading, tweaking) code ;-)
Tom and Bob- I learned a valuable thing today- there was one small code
difference that Chip alluded to in his response, and that I wouldn't have
caught if both of you hadn't tested my code- I always thought that Option
Base 1 only had to be in one Module to work for the whole workbook, like a
public declaration. The code I was using was in a separate module and I
added the OB1 to the top just to provide copy/paste code in my post. I
just tested, and apparently it is a module-specific setting. Wow. I'm
surprised I haven't run into problems before, but that's probably because
I tend to declare arrays whenever possible, and always declare them with a
base of 1 in addition to having Option Base 1 in a module somewhere. Now I
know better.
Now that I know I'd have to have OB1 in every module (and every worksheet
with code) I'm much more inclined to stick with a zero-bound system and/or
the UBound/LBound approach!
Many, many thanks for the help to all of you!
Keith
"Bob Phillips" wrote in message
...
and me in XL2007
--
---
HTH
Bob
(there's no email, no snail mail, but somewhere should be gmail in my
addy)
"Tom Ogilvy" wrote in message
...
Your code returned a 1 for me using xl2003.
--
Regards,
Tom Ogilvy
"Keith" wrote:
Using XL 2003.
I generally set Option Base 1 in my projects, as a personal preference
(MS
gave us the option, so I'd think either way is ok).
However, even in Option Base 1 project, some arrays don't start with 1,
such
as:
Option Base 1
Sub testme
CArray = Array(1,2,3,4)
Msgbox CArray(1) 'returns a value of 2
End Sub
Is there a way to ensure that these 'on the fly' arrays also start with
Base
1, or am I stuck with having mixed array types if I assign these arrays
on
the fly?
Thanks!
Keith