Transferring ranges to/from arrays
Thanks, Tom.
What is the theory behind going to a 2-dim array here? Is it
because x, y & z are names for consecutive cells in a column?
Also, how would I pass the array to my function, which is written in C++?
With 1-dim array I use:
Private Declare Function mixerSM Lib "hvacTKDLL.dll" _
(ByRef inArgs As Double, ByRef outArgs As Double) As Long
Sub mixerDriver()
Dim inArgs(5) As Double, outArgs(6) As Double
Dim ec
inArgs(0) = Worksheets("mixer").Range("wAirEnt1").Value ' Test value
= 0.01
inArgs(1) = Worksheets("mixer").Range("wAirEnt2").Value ' Test value
= 0.005
...
ec = mixerSM(inArgs(0), outArgs(0))
If ec = 0 Then
Worksheets("mixer").Range("mAirEnt2").Value = outArgs(0)
Worksheets("mixer").Range("mAirEnt1").Value = outArgs(1)
....
End If
End Sub
But if inArgs is 2-dimensional, presumably I would do
ec = mixerSM(inArgs(0,0), outArgs(0,0))
But the compiler doesn't like it.
Sorry to be so dense....
Ed
"Tom Ogilvy" wrote in message
...
Dim inargs as Variant
inargs = Range("x").Resize(3,1).Value
' inargs is a 1 to 3, 1 to 1 array (two dimensions)
Range("x").Resize(3,1).Value = outargs
--
Regards,
Tom Ogilvy
Jag Man wrote in message
...
What is the most efficient way to load data from a sheet range into an
array
so I can
pass the data to a DLL function? And, to transfer the results back into
another sheet range?
That is, I want to do something like this
Sub mySub
inargs(0) = Range("x").value
inargs(1) = Range("y").value
inargs(2) = Range("z").value
ec = theDllFunction(inargs(0), outargs(0)
Range("a").Value = outargs(0)
Range("b").Value = outargs(1)
Range("c").Value = outargs(2)
End
The above works, but if the cells named x, y, z, and those named a, b,
c,
are in a contiguous ranges it seems there must be
a more efficient way to do this.
TIA
Ed
|