View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Jag Man Jag Man is offline
external usenet poster
 
Posts: 38
Default Transferring ranges to/from arrays

Tom,
I think I have this figured out, but what I've come to isn't elegant. The
upshot is that (a) Only Variants can
be used to move data to/from ranges, (b) the functions in my DLL want ByRef
Doubles, and (c) Since one
cannot assign to arrays, the array of doubles has to be assigned on a
one-at-a-time basis.

Since I want to use the same DLL functions from other languages as well as
VBA, I don't want to go to SafeArray.

Let me know if you can disput my findings, as I could be missing something
yet...

Here is what worked:

Private Declare Function enthalpySM Lib "hvacTKDLL.dll" _
(ByRef inArgs As Double, ByRef outArgs As Double) As Long
'
' Trying to set up array args from sheet columns
'
Sub ArrayArgTest()
Dim inVars As Variant
Dim outVars As Variant
Dim inArgs(2) As Double, outArgs(1) As Double
Dim ec As Long
inVars = Range("TDb").Resize(2, 1).Value ' Get a column from sheet

'inArgs = inVars ' Won't work, as one cannot assign to array
For i = 0 To 1
inArgs(i) = inVars(i + 1, 1)
Next i

' ec = enthalpySM(inVars(1, 1), outVars(1, 1)) ' Wont work. Gives a Type
mismatch error
ec = enthalpySM(inArgs(0), outArgs(0)) ' my args must be ByRef Doubles

outVars = outArgs ' Here I can do it the easy way
Range("h").Resize(1, 1).Value = outArgs ' Put a column into the sheet
End Sub


Ed


"Tom Ogilvy" wrote in message
...
One other thought

an array picked up from the worksheet like that is 1 based. so the first
element is 1,1

myarray(1 to # rows, 1 to # columns)

That has little relevance in your DLL, but at in the argument list, it
might.

--
Regards,
Tom Ogilvy