Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Could anybody tell me where I can find some simple tutorial how to convert a
VBA function to an .xll function? I have the sample project from the book Professional Excel Development and I can load that in VC6 ++. It looks I can just add my function (converted to C) to this sample projects and change a few other things in the Sample.c and Sample.def files. I don't know anything about C though and I am trying to do this quickly without learning some C fundamentals. This is the function I would like to convert: Function Framingham(Age As Long, _ SysBP As Long, _ TotChol As Double, _ HDL As Double, _ Optional Sex As String = "male", _ Optional Diabetes As String = "", _ Optional LVH As String = "", _ Optional Smoke As String = "", _ Optional Years As Long = 10) As Double On Error GoTo ERROROUT Dim dB0 As Double Dim dB1 As Double Dim dB2 As Double Dim dB3 As Double Dim dB4 As Double Dim dB5 As Double Dim dB6 As Double Dim dB7 As Double Dim dB8 As Double Dim dB9 As Double Dim dB10 As Double Dim dTheta As Double Dim dTheta1 As Double Dim dMu As Double Dim dU As Double Dim dS As Double Dim dProb As Double Dim btSex As Byte Dim btDiabetes As Byte Dim btLVH As Byte Dim btSmoke As Byte If Age < 35 Or Age 75 Or _ SysBP < 50 Or SysBP 300 Or _ TotChol < 1 Or TotChol 30 Or _ HDL < 0.2 Or HDL 10 Or _ Years 10 Then Framingham = 0 Exit Function End If dB0 = 15.5305 dB1 = 28.4441 dB2 = -1.4792 dB3 = -14.4588 dB4 = 1.8515 dB5 = -0.9119 dB6 = -0.2767 dB7 = -0.7181 dB8 = -0.1759 dB9 = -0.1999 dB10 = -0.5865 dTheta = 0.9145 dTheta1 = -0.2784 If UCase(Sex) = "FEMALE" Then btSex = 1 If UCase(Diabetes) = "YES" Then btDiabetes = 1 If UCase(LVH) = "YES" Then btLVH = 1 If UCase(Smoke) = "YES" Then btSmoke = 1 dMu = dB0 + _ dB1 * btSex + _ dB2 * Log(Age) + _ dB3 * Log(Age) * btSex + _ dB4 * Log(Age) ^ 2 * btSex + _ dB5 * Log(SysBP) + _ dB6 * btSmoke + _ dB7 * Log(TotChol / HDL) + _ dB8 * btDiabetes + _ dB9 * btDiabetes * btSex + _ dB10 * btLVH dS = Exp(dTheta + (dTheta1 * dMu)) dU = (Log(Years) - dMu) / dS dProb = 1 - Exp(-Exp(dU)) Framingham = Round(dProb * 100, 2) Exit Function ERROROUT: Framingham = -1 End Function Thanks for any advice. RBS |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Ordered a copy of:
C++ for VB Programmers - Jonathan Morrison That should set me on the way not only for xll programming but also for regular dll's. RBS "RB Smissaert" wrote in message ... Could anybody tell me where I can find some simple tutorial how to convert a VBA function to an .xll function? I have the sample project from the book Professional Excel Development and I can load that in VC6 ++. It looks I can just add my function (converted to C) to this sample projects and change a few other things in the Sample.c and Sample.def files. I don't know anything about C though and I am trying to do this quickly without learning some C fundamentals. This is the function I would like to convert: Function Framingham(Age As Long, _ SysBP As Long, _ TotChol As Double, _ HDL As Double, _ Optional Sex As String = "male", _ Optional Diabetes As String = "", _ Optional LVH As String = "", _ Optional Smoke As String = "", _ Optional Years As Long = 10) As Double On Error GoTo ERROROUT Dim dB0 As Double Dim dB1 As Double Dim dB2 As Double Dim dB3 As Double Dim dB4 As Double Dim dB5 As Double Dim dB6 As Double Dim dB7 As Double Dim dB8 As Double Dim dB9 As Double Dim dB10 As Double Dim dTheta As Double Dim dTheta1 As Double Dim dMu As Double Dim dU As Double Dim dS As Double Dim dProb As Double Dim btSex As Byte Dim btDiabetes As Byte Dim btLVH As Byte Dim btSmoke As Byte If Age < 35 Or Age 75 Or _ SysBP < 50 Or SysBP 300 Or _ TotChol < 1 Or TotChol 30 Or _ HDL < 0.2 Or HDL 10 Or _ Years 10 Then Framingham = 0 Exit Function End If dB0 = 15.5305 dB1 = 28.4441 dB2 = -1.4792 dB3 = -14.4588 dB4 = 1.8515 dB5 = -0.9119 dB6 = -0.2767 dB7 = -0.7181 dB8 = -0.1759 dB9 = -0.1999 dB10 = -0.5865 dTheta = 0.9145 dTheta1 = -0.2784 If UCase(Sex) = "FEMALE" Then btSex = 1 If UCase(Diabetes) = "YES" Then btDiabetes = 1 If UCase(LVH) = "YES" Then btLVH = 1 If UCase(Smoke) = "YES" Then btSmoke = 1 dMu = dB0 + _ dB1 * btSex + _ dB2 * Log(Age) + _ dB3 * Log(Age) * btSex + _ dB4 * Log(Age) ^ 2 * btSex + _ dB5 * Log(SysBP) + _ dB6 * btSmoke + _ dB7 * Log(TotChol / HDL) + _ dB8 * btDiabetes + _ dB9 * btDiabetes * btSex + _ dB10 * btLVH dS = Exp(dTheta + (dTheta1 * dMu)) dU = (Log(Years) - dMu) / dS dProb = 1 - Exp(-Exp(dU)) Framingham = Round(dProb * 100, 2) Exit Function ERROROUT: Framingham = -1 End Function Thanks for any advice. RBS |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Excel Data Validation/Lookup function does function correcty | Excel Worksheet Functions | |||
LINKEDRANGE function - a complement to the PULL function (for getting values from a closed workbook) | Excel Worksheet Functions | |||
Emulate Index/Match combo function w/ VBA custom function | Excel Worksheet Functions | |||
Adding a custom function to the default excel function list | Excel Programming | |||
User-Defined Function pre-empting Built-in Function? How to undo???? | Excel Programming |