Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default Option Base 1; how to also make auto-arrays set to base 1?

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 772
Default Option Base 1; how to also make auto-arrays set to base 1?

I know it is a pain as I was a big option base 1 guy, but the best thing to
do is just bite the bullet and go 0. it took a couple months to get down but
now its second nature. Having mixed is bad news, especially if someone else
has to mess with your code.
--
-John Northwest11
Please rate when your question is answered to help us and others know what
is helpful.


"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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Option Base 1; how to also make auto-arrays set to base 1?

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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default Option Base 1; how to also make auto-arrays set to base 1?

John- thanks for the reply. I guess it just seems strange to me that MS
wouldn't have those 'on the fly' arrays also default to base 1 when Option
Base1 is on, and I wasn't sure if there was some other setting I needed to
change. It's too late to change my current projects, but I guess I'll need
to noodle on switching for any new projects.
Thanks,
Keith

"John Bundy" (remove) wrote in message
...
I know it is a pain as I was a big option base 1 guy, but the best thing to
do is just bite the bullet and go 0. it took a couple months to get down
but
now its second nature. Having mixed is bad news, especially if someone
else
has to mess with your code.
--
-John Northwest11
Please rate when your question is answered to help us and others know what
is helpful.


"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





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,726
Default Option Base 1; how to also make auto-arrays set to base 1?

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







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Option Base 1; how to also make auto-arrays set to base 1?

Keith,

You should always make your code agnostic to the Option Base setting. ALWAYS
use LBound and UBound to get the bounds of the array. Relying on the Option
Base statement is an invitation to bugs when copy/pasting code between
modules and projects that may have no Option Base statement or an Option
Base statement different from that of the source module.

Dim Arr As Variant
Dim N As Long
Arr = Array("A", "B", "C", "D")
Debug.Print "LBound: " & CStr(LBound(Arr)), _
"UBound: " & CStr(UBound(Arr)), "Arr(1): " & CStr(Arr(1))
Debug.Print "First element: " & Arr(LBound(Arr))
Debug.Print "Last element: " & Arr(UBound(Arr))
'''''''''''''''''''''''''''''''
' List all elements
'''''''''''''''''''''''''''''''
For N = LBound(Arr) To UBound(Arr)
Debug.Print CStr(N), CStr(Arr(N))
Next N


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)



"Keith" wrote in message
...
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




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default Option Base 1; how to also make auto-arrays set to base 1?

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







  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Option Base 1; how to also make auto-arrays set to base 1?

Just an additional piece of advice. NEVER declare an array with only the
upper bound. E.g.,

Dim V(10) As Long

This is dependent on the Option Base setting (which as you have found out
applies only to the module in which it occurs). In some circumstances, V
will have 10 elements, and in other circumstances it will have 11, depending
on Option Base. This will cause bugs if you copy code from one module to
another. Always declare your arrays with both the lower and upper bounds.

Dim V(1 To 10) As Long
' or
Dim V(0 To 9) As Long


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)





"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









  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,582
Default Option Base 1; how to also make auto-arrays set to base 1?

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









  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Option Base 1; how to also make auto-arrays set to base 1?

Keith,
Whilst your example was not correct as to VBA's behaviour and others have
pointed out better way of dealing with arrays, you should be aware that
there are statements that do ignore the Option base setting. e.g.

Option Base 1
Private Sub CommandButton1_Click()
Dim carray
carray = Split("1,2,3,4", ",")
MsgBox carray(1) 'returns a value of 2
End Sub

NickHK

"Keith" wrote in message
...
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






  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Option Base 1; how to also make auto-arrays set to base 1?

Dim v as Variant
v = Range("A1:B9").Value

v is always 1 based in both dimensions.

--
Regards,
Tom Ogilvy



"NickHK" wrote:

Keith,
Whilst your example was not correct as to VBA's behaviour and others have
pointed out better way of dealing with arrays, you should be aware that
there are statements that do ignore the Option base setting. e.g.

Option Base 1
Private Sub CommandButton1_Click()
Dim carray
carray = Split("1,2,3,4", ",")
MsgBox carray(1) 'returns a value of 2
End Sub

NickHK

"Keith" wrote in message
...
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





  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 200
Default Option Base 1; how to also make auto-arrays set to base 1?

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


If you use the following function you can code

CArray=ConvertBase(Array(1,2,3,4),1) or, in Nick HK's example

CArray = ConvertBase(Split("1,2,3,4", ","),1),

for 1-D, 2-D and 3-D arrays

Function ConvertBase(ByRef InputArray, _
ByVal ResultingBase1 As Long, _
Optional ByVal ResultingBase2, _
Optional ByVal ResultingBase3)
'This function converts the base(s) of an
'input array to the integer(s) that is/are
'input as the ResultingBase argument(s).
'It accepts arrays with base(s) equal to
'the number(s) of the ResultingBase argument(s),
'simply leaving them as is. It returns the
'converted array for use in other functions.

Dim ina, outa, Msg As String
Dim i As Long, j As Long, p As Integer
Dim rb1 As Long, rb2 As Long, rb3 As Long
Dim lb1 As Long, lb2 As Long, ub1 As Long, ub2 As Long


'Insure that InputArray is an array
If Not IsArray(InputArray) Or IsObject(InputArray) Then
Msg = "The first argument to this function must be an array."
If TypeOf Application.Caller Is Range Then
ConvertBase = Msg: Exit Function
Else
MsgBox Msg, 16: Exit Function
End If
End If

'Determine the number of dimensions of InputArray
On Error Resume Next
i = 1
Do
z = UBound(InputArray, i)
i = i + 1
Loop While Err = 0
Err = 0
On Error GoTo 0

'Assign dimensions of InputArray to a variable
p = i - 2

'Insure that InputArray is not greater than 3-Dimensional
Msg = "Function does not accept arrays with more than 3 dimensions"
If p 3 Then
If TypeOf Application.Caller Is Range Then
ConvertBase = Msg: Exit Function
Else
MsgBox Msg, 16: Exit Function
End If
End If

'For convenience in referring to ResultingBase
rb1 = ResultingBase1
If Not IsMissing(ResultingBase2) Then
If Not TypeName(ResultingBase2) = "Integer" _
And Not TypeName(ResultingBase2) = "Long" Then
Msg = "The optional second argument must be an integer"
If TypeOf Application.Caller Is Range Then
ConvertBase = Msg: Exit Function
Else
MsgBox Msg, 16: Exit Function
End If
End If
rb2 = ResultingBase2
ElseIf p 1 Then
rb2 = LBound(InputArray, 2)
End If
If Not IsMissing(ResultingBase3) Then
If Not TypeName(ResultingBase3) = "Integer" _
And Not TypeName(ResultingBase3) = "Long" Then
Msg = "The optional third argument must be an integer"
If TypeOf Application.Caller Is Range Then
ConvertBase = Msg: Exit Function
Else
MsgBox Msg, 16: Exit Function
End If
End If
rb3 = ResultingBase3
ElseIf p = 3 Then
rb3 = LBound(InputArray, 3)
End If

'For convenience in referring to InputArray
ina = InputArray
lb1 = LBound(ina, 1)
ub1 = UBound(ina, 1)

If p = 1 Then

'Redimension and load the 1-D output array
Select Case TypeName(ina)
Case "Object()"
ReDim outa(rb1 To ub1 - lb1 + rb1) As Object
For i = rb1 To ub1 - lb1 + rb1
Set outa(i) = ina(i + lb1 - rb1)
Next
Case "Boolean()"
ReDim outa(rb1 To ub1 - lb1 + rb1) As Boolean
Case "Byte()"
ReDim outa(rb1 To ub1 - lb1 + rb1) As Byte
Case "Currency()"
ReDim outa(rb1 To ub1 - lb1 + rb1) As Currency
Case "Date()"
ReDim outa(rb1 To ub1 - lb1 + rb1) As Date
Case "Double()"
ReDim outa(rb1 To ub1 - lb1 + rb1) As Double
Case "Integer()"
ReDim outa(rb1 To ub1 - lb1 + rb1) As Integer
Case "Long()"
ReDim outa(rb1 To ub1 - lb1 + rb1) As Long
Case "Single()"
ReDim outa(rb1 To ub1 - lb1 + rb1) As Single
Case "String()"
ReDim outa(rb1 To ub1 - lb1 + rb1) As String
Case "Variant()"
ReDim outa(rb1 To ub1 - lb1 + rb1) As Variant
Case Else
Msg = "The function accepts arrays of only built-in types."
If TypeOf Application.Caller Is Range Then
ConvertBase = Msg: Exit Function
Else
MsgBox Msg, 16: Exit Function
End If
End Select

If TypeName(outa) < "Object()" Then
For i = rb1 To ub1 - lb1 + rb1
outa(i) = ina(i + lb1 - rb1)
Next
End If

ElseIf p = 2 Or p = 3 Then

'For convenience in reference
lb2 = LBound(ina, 2)
ub2 = UBound(ina, 2)
If p = 2 Then
'Redimension and load the 2-D output array
Select Case TypeName(ina)
Case "Object()"
ReDim outa(rb1 To ub1 - lb1 + rb1, rb2 To ub2 - lb2 +
rb2) As Object
For i = rb1 To ub1 - lb1 + rb1
For j = rb2 To ub2 - lb2 + rb2
Set outa(i, j) = ina(i + lb1 - rb1, j + lb2 - rb2)
Next
Next
Case "Boolean()"
ReDim outa(rb1 To ub1 - lb1 + rb1, rb2 To ub2 - lb2 +
rb2) As Boolean
Case "Byte()"
ReDim outa(rb1 To ub1 - lb1 + rb1, rb2 To ub2 - lb2 +
rb2) As Byte
Case "Currency()"
ReDim outa(rb1 To ub1 - lb1 + rb1, rb2 To ub2 - lb2 +
rb2) As Currency
Case "Date()"
ReDim outa(rb1 To ub1 - lb1 + rb1, rb2 To ub2 - lb2 +
rb2) As Date
Case "Double()"
ReDim outa(rb1 To ub1 - lb1 + rb1, rb2 To ub2 - lb2 +
rb2) As Double
Case "Integer()"
ReDim outa(rb1 To ub1 - lb1 + rb1, rb2 To ub2 - lb2 +
rb2) As Integer
Case "Long()"
ReDim outa(rb1 To ub1 - lb1 + rb1, rb2 To ub2 - lb2 +
rb2) As Long
Case "Single()"
ReDim outa(rb1 To ub1 - lb1 + rb1, rb2 To ub2 - lb2 +
rb2) As Single
Case "String()"
ReDim outa(rb1 To ub1 - lb1 + rb1, rb2 To ub2 - lb2 +
rb2) As String
Case "Variant()"
ReDim outa(rb1 To ub1 - lb1 + rb1, rb2 To ub2 - lb2 +
rb2) As Variant
Case Else
Msg = "The function accepts arrays of only built-in types."
If TypeOf Application.Caller Is Range Then
ConvertBase = Msg: Exit Function
Else
MsgBox Msg, 16: Exit Function
End If
End Select

If TypeName(ina) < "Object()" Then
For i = rb1 To ub1 - lb1 + rb1
For j = rb2 To ub2 - lb2 + rb2
outa(i, j) = ina(i + lb1 - rb1, j + lb2 - rb2)
Next
Next
End If

ElseIf p = 3 Then

'For convenience in reference
lb3 = LBound(ina, 3)
ub3 = UBound(ina, 3)

'Redimension and load the 3-D output array
Select Case TypeName(ina)
Case "Object()"
ReDim outa(rb1 To ub1 - lb1 + rb1, rb2 To ub2 - lb2 +
rb2, rb3 To ub3 - lb3 + rb3) As Object
For i = rb1 To ub1 - lb1 + rb1
For j = rb2 To ub2 - lb2 + rb2
For k = rb3 To ub3 - lb3 + rb3
Set outa(i, j, k) = ina(i + lb1 - rb1, j +
lb2 - rb2, k + lb3 - rb3)
Next
Next
Next
Case "Boolean()"
ReDim outa(rb1 To ub1 - lb1 + rb1, rb2 To ub2 - lb2 +
rb2, rb3 To ub3 - lb3 + rb3) As Boolean
Case "Byte()"
ReDim outa(rb1 To ub1 - lb1 + rb1, rb2 To ub2 - lb2 +
rb2, rb3 To ub3 - lb3 + rb3) As Byte
Case "Currency()"
ReDim outa(rb1 To ub1 - lb1 + rb1, rb2 To ub2 - lb2 +
rb2, rb3 To ub3 - lb3 + rb3) As Currency
Case "Date()"
ReDim outa(rb1 To ub1 - lb1 + rb1, rb2 To ub2 - lb2 +
rb2, rb3 To ub3 - lb3 + rb3) As Date
Case "Double()"
ReDim outa(rb1 To ub1 - lb1 + rb1, rb2 To ub2 - lb2 +
rb2, rb3 To ub3 - lb3 + rb3) As Double
Case "Integer()"
ReDim outa(rb1 To ub1 - lb1 + rb1, rb2 To ub2 - lb2 +
rb2, rb3 To ub3 - lb3 + rb3) As Integer
Case "Long()"
ReDim outa(rb1 To ub1 - lb1 + rb1, rb2 To ub2 - lb2 +
rb2, rb3 To ub3 - lb3 + rb3) As Long
Case "Single()"
ReDim outa(rb1 To ub1 - lb1 + rb1, rb2 To ub2 - lb2 +
rb2, rb3 To ub3 - lb3 + rb3) As Single
Case "String()"
ReDim outa(rb1 To ub1 - lb1 + rb1, rb2 To ub2 - lb2 +
rb2, rb3 To ub3 - lb3 + rb3) As String
Case "Variant()"
ReDim outa(rb1 To ub1 - lb1 + rb1, rb2 To ub2 - lb2 +
rb2, rb3 To ub3 - lb3 + rb3) As Variant
Case Else
Msg = "The function accepts arrays of only built-in types."
If TypeOf Application.Caller Is Range Then
ConvertBase = Msg: Exit Function
Else
MsgBox Msg, 16: Exit Function
End If
End Select

If TypeName(ina) < "Object()" Then
For i = rb1 To ub1 - lb1 + rb1
For j = rb2 To ub2 - lb2 + rb2
For k = rb3 To ub3 - lb3 + rb3
outa(i, j, k) = ina(i + lb1 - rb1, j + lb2 -
rb2, k + lb3 - rb3)
Next
Next
Next
End If
End If
End If

'Convert the input array to the resulting base
InputArray = outa

'Return converted array for calls from other functions
ConvertBase = outa

End Function
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Option Base error... pmguerra[_4_] Excel Programming 1 April 11th 06 11:02 PM
Can you Auto fill address in excell with a data base? bayou beot Excel Worksheet Functions 1 May 12th 05 09:21 AM
Option Commands (Option Explicit / Option Base etc) - Scope Alan Excel Programming 8 November 1st 04 02:22 AM
Knowledge Base 247412 need help to make work Ian Ornstein Excel Programming 2 January 30th 04 01:02 PM
Option Base and reading from Access Don Wiss Excel Programming 3 January 22nd 04 06:38 AM


All times are GMT +1. The time now is 07:56 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"