-1

I wrote a subroutine and was using the following code without any error in that sub routine.

Only relevant code:

Dim CandleEndTimes() as Date

NoOfCndlInDay = 5

ReDim Preserve CandleEndTimes(NoOfCndlInDay)

CandleEndTimes = Array(#10:30:00 AM#, #12:00:00 PM#, #1:30:00 PM#, #3:00:00 PM#, #3:30:00 PM#)

Then to make this subroutine handle more than one cases, I removed the statement assigning values to the array CandleEndTimes and defined it as a parameter as under

Sub CustomCandles(UseOnBookName As String, UseOnSheetName As String, NoOfCndlInDay As Integer, CandleEndTimes() As Date)

The code of the subroutine used to call the above sub:

Sub callingcust()

Dim Min90CandleEndTimes() As Date

ReDim Preserve Min90CandleEndTimes(5)

Min90CandleEndTimes = Array(#10:30:00 AM#, #12:00:00 PM#, #1:30:00 PM#, #3:00:00 PM#, #3:30:00 PM#)


End Sub

While debugging the code at the statement used to assign values i get a error 13

Can anyone see anything wrong with the above code. In case you feel that the info is not sufficient do let me know what else I need to share.

Kindly help!

Community
  • 1
  • 1

1 Answers1

0

the Array function returns a Variant type which is why you get a Type Mismatch error - you may only assign one array to another in one operation if the target array is dynamic and of the same type as the source. you would need 5 discrete assignments

Dim Min90CandleEndTimes() As Date

ReDim Preserve Min90CandleEndTimes(5)

Min90CandleEndTimes(1) = #10:30:00 AM#
Min90CandleEndTimes(2) = #12:00:00 PM#
Min90CandleEndTimes(3) = #1:30:00 PM#
Min90CandleEndTimes(4) = #3:00:00 PM#
Min90CandleEndTimes(5) = #3:30:00 PM#

by the way, unless you have Option Base 1 set, your array has 6 elements ;-)

JosieP
  • 3,360
  • 1
  • 13
  • 16