This is a multi-part message in MIME format.
--------------090702000508020807070209
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
In a previous posting, a scripter using scripting language other
than vbScript, and further a language which has no math functions,
and was wondering if there was some com object that would offer
the capability of calling the vbs math functions.
A previous response to that O.P. recommended installing the ms
"Script Control", and place some vbScript coding inside the control
to calculate the desired math functions.
In addition to that, if you are courageous enough, or foolhardy enough,
to call api's from script, then you can call the (vb) math functions
directly. All you need is a relatively "light-weight" com control
suitable for calling api's, which you could write yourself, or use
one already available, like: "DynaWrap".
Note that there are several (standard) dll's around containing math
function entry points. Among these are the "vb runtimes": msvbvm50.dll,
and msvbvm60.dll, plus vba5.dll and vba6.dll, any of which you may
have if you have any vb5 or vb6 apps installed on your system. You
can also find the math functions in vbar332.dll, which you will have
if you have VBA (Visual Basic for Applications) on your system.
Here are the vb-style declarations for the math functions entry-
points:
Declare Function rtcCos Lib "msvbvm60.dll" (ByVal dblNumber As Double)
As Double
Declare Function rtcSin Lib "msvbvm60.dll" (ByVal dblNumber As Double)
As Double
Declare Function rtcSqr Lib "msvbvm60.dll" (ByVal dblNumber As Double)
As Double
Declare Function rtcTan Lib "msvbvm60.dll" (ByVal dblNumber As Double)
As Double
by now, you get the drift. I don't have an exact exhaustive
listing, but you should be able to find at least: Sine, Cosine,
Tangent, ArcTangent, Exp, Log, and Sqrt. Many (if not most) of
the other functions may be derived from those just listed.
There is a script attached, which calls the rtcSin function, and
compares the result returned with the vbScript's own Sin function.
I can testify that the attached script works with win98se, but it
may take some "adjustments" to get it working with winXP...
If you read this far, you may have come to the (obvious) conclusion
that a vbScrpter would have no use for this, because all those
math functions are already available in vbScript. However, if you
poke around among the entry points of the dll's mentioned above,
you may find some intriguing entry points whose functionality is
available in vb, but _not_ in vbScript.
cheers, jw
p.s. Technical Factoid for Dynawrap fans. Initially this script
didn't work (gasp!). How could that happen? I know what you're
thinking: it was me -- Naw!!! It had to be dynawrap. Even
though I know nothing about c++, I combed through both DynaWrap
and DynaCall source looking for "something", and I found it.
Previously, I had thought that the "f" (for flag) input parameter
was strictly for telling DynaWrap what type of calling sequence
was used (_stdcall or _cdecl). However there are other flags.
More specifically, there is "4" for returning a "Math4" result,
and "8" for returning a "Math8" result. After some googling
and head-scratching, it became apparent that "VT_R8" (8 byte real),
variant type "Double", and "Math8" were all talking about THE
SAME THING(!). At least that's what I assumed. And so that
explains the previously questionable "f=s8" parameter, and
eventually how I got the rtcSin function to work with DynaWrap.
--------------090702000508020807070209
Content-Type: text/plain;
name="wshCallingRTCSinFunction_wDynawrap.vbs.txt"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="wshCallingRTCSinFunction_wDynawrap.vbs.txt"
' wsh Test Calling the Math functions in vba5.dll, jw 16Sept06
'
' --- description block --------------------------
'
' Title: Test calling Math Functions (using Dynawrap)...
'
' Description: Motivated by a newsgroup posting, which asked about
' using the vbScript math functions in some other scripting
' language...
'
' Note that there are several (standard) dll's around
' containing math function entry points. Among these are
' vba5.dll and vba6.dll and the vb-runtimes (which you will
' have if you have any vb5 or vb6 apps installed on your
' system). You can also find the math functions in
' vbar332.dll, which you will have if you have VBA
' (Visual Basic for Applications) on your system.
'
' All of the above have the math functions: sine, cosine, tan,
' atan, Exp, Log, and so on, i.e., all the usual suspects...
'
' This script is only testing the sine function, but that
' should be enough to get you going...
'
' Author: mr_unreliable (all rights reserved)
' Website: none at this time (contact via: news://microsoft.public.scripting.vbscript)
'
' Usage: Use at you own risk, tested on win98se...
'
' Acknowledgments: none
'
' --- revision history ---------------------------
' 16Sept06: initial attempt
'
' --- end of description block -------------------
Option Explicit
Dim sSpace : sSpace = vbCrLf & vbCrLf
Dim sResults : sResults = "Results: " & sSpace ' initialize
Dim oDW ' as object
' Declare Function rtcSin Lib "msvbvm50.dll" (ByVal dblNumber As Double) As Double
Set oDW = CreateObject("DynamicWrapper") ' instantiate dynawrap
oDW.Register "MSVBVM50.DLL", "rtcSin", "i=d", "f=s8", "r=d" ' double parameter, and return value
Dim vntSine : vntSine = CDbl(0) ' initialize, type-cast as double...
vntSine = oDW.rtcSin(CDbl(1)) ' sine of one radian
' MsgBox("rtcSin returned a variant of type: " & TypeName(vntSine))
sResults = sResults & " rtcSin(1) returns: " & CStr(vntSine) & sSpace
vntSine = CDbl(0) ' reinitialize...
' call the vbs sine function, to cross-check the previous result...
vntSine = Sin(CDbl(1))
sResults = sResults & " vbsSin(1) returns: " & CStr(vntSine)
MsgBox sResults, vbInformation, " << texting rtcsine function >> "
Set oDW = nothing ' (may be omitted for those who trust microsoft implicitly)
WScript.Quit
--------------090702000508020807070209--