Measurement Studio for VB6

cancel
Showing results for 
Search instead for 
Did you mean: 

nonlinearfit .net

I am trying to upgrade from measurement studio for vb6 to .net. I do NOT want the .net version of measurement studio. I need to use the function CWStat.NonLinearFit. I used the example for vb6 which worked fine on my computer. After I used the convert utility in Visual studio .net, I get a type mismatch exception when I call CWStat.NonLinearFit. Has anyone been able to use this function with .net?
0 Kudos
Message 1 of 2
(6,560 Views)
I received a response from NI technical support that CW ActiveX components have not been tested on VB.NET and they have not been modified. NI does not guarantee CW to work on Visual Studio .NET. Nevertheless, if anyone is having trouble with type mismatch exceptions using CWStat.NonLinearFit (or any other function), I have developed a workaround by creating a vb6 activex wrapper for CW for use with .NET.
The code below will create an activex dll which can be called from a vb .Net application. To use the dll in Visual studio .net, create a project and add the dll as a com reference.
--------------------------------
vb .net sample
--------------------------------
Dim WithEvents mLSfit As New CWWrapper.CWStat
Dim x,y,coef As Double()

'initialize arrays x,y,coef
mLSfit.NonLinearFit(x, y, coef, mse, 1000)

Private Sub mLSfit_NonLinearFitModelProcedure(ByRef x As Object, ByRef Coefficients As Object, ByRef f As Object) Handles mLSfit.NonLinearFitModelProcedure
'calculate f(x,a) for your function, where a is the set of coefficients.
f = Math.Sqrt(Coefficients(0) ^ 2 + Coefficients(1) ^ 2 * (x - Coefficients(2)) ^ 2)
End Sub


--------------------------------------
cwwrapper.vbp - vb6 project file
--------------------------------------
Type=OleDll
Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\WINDOWS\System32\stdole2.tlb#OLE Automation
Object={E7BC3920-33D4-11D0-8B73-0020AF31CEF9}#1.4#0; cwanalysis.ocx
Class=CWStat; CWStatWrapper.cls
Form=Form1.frm
Startup="(None)"
HelpFile=""
Title="CWWrapper"
ExeName32="CWStatWrapper.dll"
Command32=""
Name="CWWrapper"
HelpContextID="0"
CompatibleMode="1"
CompatibleEXE32="CWStatWrapper.dll"
MajorVer=1
MinorVer=0
RevisionVer=0
AutoIncrementVer=0
ServerSupportFiles=0
VersionCompanyName="Ophir Optronics"
VersionFileDescription=".Net wrapper for CWStat"
CompilationType=0
OptimizationType=0
FavorPentiumPro(tm)=0
CodeViewDebugInfo=0
NoAliasing=0
BoundsCheck=0
OverflowCheck=0
FlPointCheck=0
FDIVCheck=0
UnroundedFP=0
StartMode=1
Unattended=0
Retained=0
ThreadPerObject=0
MaxNumberOfThreads=1
ThreadingModel=1
DebugStartupOption=0

[MS Transaction Server]
AutoRefresh=1
--------------------------------------
cwstatwrapper.cls - vb6 activex interface
--------------------------------------
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "CWStat"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Private mForm
Public Event NonLinearFitModelProcedure(x As Variant, Coefficients As Variant, f As Variant)

Friend Sub RaiseNLFitEvent(x As Variant, Coefficients As Variant, f As Variant)
RaiseEvent NonLinearFitModelProcedure(x, Coefficients, f)
End Sub

Private Sub Class_Initialize()
Set mForm = Form1
Set Form1.mParent = Me
End Sub

Public Function NonLinearFit(x, y, coef, MSError, Optional iter)
NonLinearFit = Form1.CWStat1.NonLinearFit(x, y, coef, MSError, iter)
End Function
--------------------------------------
form1.frm - form for cwstat control
--------------------------------------
VERSION 5.00
Object = "{E7BC3920-33D4-11D0-8B73-0020AF31CEF9}#1.4#0"; "cwanalysis.ocx"
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3195
ClientLeft = 60
ClientTop = 345
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3195
ScaleWidth = 4680
StartUpPosition = 3 'Windows Default
Begin CWAnalysisControlsLib.CWStat CWStat1
Left = 120
Top = 120
_Version = 65540
_ExtentX = 847
_ExtentY = 847
_StockProps = 0
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Public mParent As CWStat
Private Sub CWStat1_NonLinearFitModelProcedure(x As Variant, Coefficients As Variant, f As Variant)
mParent.RaiseNLFitEvent x, Coefficients, f
End Sub
0 Kudos
Message 2 of 2
(6,560 Views)