The best way to describe the functionality is to use an example. To use KISSsoft from Excel, you must first activate the KISSsoftCOM type library in the Visual Basic Editor in .
The first example shows how to use a single gear calculation to define the tip and root circles of a gear:
Public Sub ExampleKISSsoftCOM()
Dim ksoft As CKISSsoft
Dim da As String
Dim df As String
' get KISSsoft instance
set ksoft = New CKISSsoft
' get KISSsoft module for single gear
Call ksoft.GetModule("Z011", False)
' set values
Call ksoft.SetVar("ZR[0].z", "20")
Call ksoft.SetVar("ZS.Geo.mn", "5.0")
Call ksoft.SetVar("ZR[0].x.nul", "0.5")
' Calculate
Call ksoft.Calculate
' get values
da = ksoft.GetVar("ZR[0].da.nul")
df = ksoft.GetVar("ZR[0].df.nul")
' release module
Call ksoft.ReleaseModule
' release server
Set ksoft = Nothing
End Sub
The second example shows how to display the KISSsoft user interface:
Public Sub ExampleKISSsoftCOM()
Dim ksoft As CKISSsoft
Dim da As String
Dim df As String
' get KISSsoft instance
Set ksoft = New CKISSsoft
' get KISSsoft module for single gear
Call ksoft.GetModule("Z011", True)
' show interface
Call ksoft.ShowInterface(True)
' get values
da = ksoft.GetVar("ZR[0].da.nul")
df = ksoft.GetVar("ZR[0].df.nul")
Call ksoft.ReleaseModule
Set ksoft = Nothing
End Sub
The same example with "later binding" (the exact property or method is not determined until runtime, which enables you to compile the Visual Basic client without having to know the exact function of the call):
Public Sub ExampleKISSsoftCOM()
Dim ksoft As Object
Dim da As String
Dim df As String
' get KISSsoft Object
Set ksoft = CreateObject("KISSsoftCOM.KISSsoft")
' get KISSsoft module for single gear
Call ksoft.GetModule("Z011", True)
' show interface
Call ksoft.ShowInterface(True)
' get values
da = ksoft.GetVar("ZR[0].da.nul")
df = ksoft.GetVar("ZR[0].df.nul")
Call ksoft.ReleaseModule
Set ksoft = Nothing
End Sub
The fourth example shows a contact analysis that was run using the caControll.dat control file (you will find an example file in the dat folder) and they way messages were processed after the calculation:
Public Sub ExampleKISSsoftCOM()
On Error GoTo ExitOnErr
Dim ksoft As CKISSsoft
' get KISSsoft instance
Set ksoft = New CKISSsoft
' get KISSsoft module for gear pair
Call ksoft.GetModule("Z012", True)
' load File – change this to fit to a real file on your machine
Call ksoft.LoadFile("C:\yourPathHere\ExCOM3.z12")
' calculate
Call ksoft.Calculate
Dim ioData(0 To 2) as String
' Which calculation to start
ioData (0) = "CalculatePathOfContactForPairKS"
' controlling file
ioData (1) = "C:\ yourPathHere\caControl.dat"
' Path for results
ioData (2) = "C:\ yourPathHere\prot"
' calculate contact analysis
Call ksoft.CallFuncNParam(ioData)
' Check for messages
Dim mess As Variant
Dim types As Variant
Dim numElem As Long
Dim typesElem As Long
Dim typesElemStr As String
Call ksoft.Message(mess, types, numElem)
If (numElem > 0) Then
Dim msg As String
For i = 0 To numElem - 1
msg = CStr(mess(i))
typesElemStr = CStr(types(i))
typesElem = CLng(types(i))
If (typesElem = 0) Then
Call MsgBox(msg, vbInformation)
ElseIf (typesElem = 1) Then
Call MsgBox(msg, vbExclamation)
Else
Call MsgBox(msg, vbCritical)
End If
Next
End If
' close ksoft
Call ksoft.ReleaseModule
' no problems, so exit
Exit Sub
ExitOnErr:
MsgBox ("error occurred when calling KISSsoft.")
End Sub