Hi All,
We have successfully implemented a VBA macro ( below ) that calls and executes a function from a DLL. We are happy with the macro as
it behaves as expected. Now, however, we'd like to call the Function that the macro runs from a worksheet cell. The function name (PEEP) appears
in the formula autocomplete, but once we pass in the arguments, all we get is a #Name?. Would appreciate your thoughts and help.
Here's the call of the function from the worksheet:
=PEEP(F3,B2:B2001,E11,F4,I3,J3,F5,J19,J18,2000,1)
Here's the VBA Macro Code:
Option Explicit
Option Base 1
Public Declare Function PEEP Lib _
"C:\Excel Unit Test Builder\Measurement Functions.dll" _
(ByVal referenceTriggerIndex As Double, ByRef y As Double, ByVal dt As Double, _
ByVal t0 As Double, ByVal expectedLowLimit As Double, ByVal expectedHighLimit As Double, _
cursorIndices As Double, passFail As Integer, result As Double, ByVal yArraySize As Long, ByVal ciAarraySize As Long) As Long
Sub Endpressure()
'=================================================================================
' Declare varibles here
'=================================================================================
Dim pres_array_size As Integer ' Constant: Holds pressure array size from the worksheet
Dim testvariable As Double ' Placeholder variable for Input or Output values
Dim passFail As Integer ' Output: Holds Pass/Fail Result
Dim result As Double ' Output: Holds measured PEEP Value
Dim y() As Double ' Input: Array that holds all baseline pressure values
Dim expectedLowLimit As Double ' Input: Holds PEEP high limit
Dim expectedHighLimit As Double ' Input: Holds PEEP low limit
Dim referenceTriggerIndex As Double ' Input: Holds start point for PEEP measurement
Dim dt As Double ' Input: Holds sample rate of pressure data
Dim t0 As Double ' Input: Holds value where pressure waveform begins
Dim cursorIndices(2) As Double ' Output: Holds cursor placement data
Dim yArraySize As Long ' DLL Field: Holds Array Size info
Dim ciAarraySize As Long ' DLL Field: Holds Cursor Array info
Dim Pass_Fail As String ' Used to convert passFail integer into "Pass" or "Fail" string
Dim iterate As Integer
'=================================================================================
' Load the variables from the worksheet here
'=================================================================================
pres_array_size = Worksheets("waveform data").Cells(11, 7).Value
expectedLowLimit = Worksheets("waveform data").Cells(3, 9).Value
expectedHighLimit = Worksheets("waveform data").Cells(3, 10).Value
referenceTriggerIndex = Worksheets("waveform data").Cells(3, 6).Value
dt = Worksheets("waveform data").Cells(11, 5).Value
t0 = Worksheets("waveform data").Cells(3, 6).Value
yArraySize = Worksheets("waveform data").Cells(11, 7).Value
ciAarraySize = 2
ReDim y(pres_array_size)
'=================================================================================
' Load the y baseline pressure array from the worksheet here
'=================================================================================
For iterate = 2 To (pres_array_size - 1)
y(iterate) = Worksheets("waveform data").Cells(iterate, 2).Value
Next
'=================================================================================
' Call and process the DLL here
'=================================================================================
Call PEEP(referenceTriggerIndex, y(1), dt, t0, expectedLowLimit, expectedHighLimit, cursorIndices(1), passFail, result, yArraySize, ciAarraySize)
If passFail = 0 Then Pass_Fail = "Fail"
If passFail = 1 Then Pass_Fail = "Pass"
'=================================================================================
' Display the results on the spreadsheet here
'=================================================================================
Worksheets("waveform data").Cells(10, 18).Value = result
Worksheets("waveform data").Cells(11, 18).Value = Pass_Fail
End Sub
We have successfully implemented a VBA macro ( below ) that calls and executes a function from a DLL. We are happy with the macro as
it behaves as expected. Now, however, we'd like to call the Function that the macro runs from a worksheet cell. The function name (PEEP) appears
in the formula autocomplete, but once we pass in the arguments, all we get is a #Name?. Would appreciate your thoughts and help.
Here's the call of the function from the worksheet:
=PEEP(F3,B2:B2001,E11,F4,I3,J3,F5,J19,J18,2000,1)
Here's the VBA Macro Code:
Option Explicit
Option Base 1
Public Declare Function PEEP Lib _
"C:\Excel Unit Test Builder\Measurement Functions.dll" _
(ByVal referenceTriggerIndex As Double, ByRef y As Double, ByVal dt As Double, _
ByVal t0 As Double, ByVal expectedLowLimit As Double, ByVal expectedHighLimit As Double, _
cursorIndices As Double, passFail As Integer, result As Double, ByVal yArraySize As Long, ByVal ciAarraySize As Long) As Long
Sub Endpressure()
'=================================================================================
' Declare varibles here
'=================================================================================
Dim pres_array_size As Integer ' Constant: Holds pressure array size from the worksheet
Dim testvariable As Double ' Placeholder variable for Input or Output values
Dim passFail As Integer ' Output: Holds Pass/Fail Result
Dim result As Double ' Output: Holds measured PEEP Value
Dim y() As Double ' Input: Array that holds all baseline pressure values
Dim expectedLowLimit As Double ' Input: Holds PEEP high limit
Dim expectedHighLimit As Double ' Input: Holds PEEP low limit
Dim referenceTriggerIndex As Double ' Input: Holds start point for PEEP measurement
Dim dt As Double ' Input: Holds sample rate of pressure data
Dim t0 As Double ' Input: Holds value where pressure waveform begins
Dim cursorIndices(2) As Double ' Output: Holds cursor placement data
Dim yArraySize As Long ' DLL Field: Holds Array Size info
Dim ciAarraySize As Long ' DLL Field: Holds Cursor Array info
Dim Pass_Fail As String ' Used to convert passFail integer into "Pass" or "Fail" string
Dim iterate As Integer
'=================================================================================
' Load the variables from the worksheet here
'=================================================================================
pres_array_size = Worksheets("waveform data").Cells(11, 7).Value
expectedLowLimit = Worksheets("waveform data").Cells(3, 9).Value
expectedHighLimit = Worksheets("waveform data").Cells(3, 10).Value
referenceTriggerIndex = Worksheets("waveform data").Cells(3, 6).Value
dt = Worksheets("waveform data").Cells(11, 5).Value
t0 = Worksheets("waveform data").Cells(3, 6).Value
yArraySize = Worksheets("waveform data").Cells(11, 7).Value
ciAarraySize = 2
ReDim y(pres_array_size)
'=================================================================================
' Load the y baseline pressure array from the worksheet here
'=================================================================================
For iterate = 2 To (pres_array_size - 1)
y(iterate) = Worksheets("waveform data").Cells(iterate, 2).Value
Next
'=================================================================================
' Call and process the DLL here
'=================================================================================
Call PEEP(referenceTriggerIndex, y(1), dt, t0, expectedLowLimit, expectedHighLimit, cursorIndices(1), passFail, result, yArraySize, ciAarraySize)
If passFail = 0 Then Pass_Fail = "Fail"
If passFail = 1 Then Pass_Fail = "Pass"
'=================================================================================
' Display the results on the spreadsheet here
'=================================================================================
Worksheets("waveform data").Cells(10, 18).Value = result
Worksheets("waveform data").Cells(11, 18).Value = Pass_Fail
End Sub