如何通过vb调用lingo求解线性规划之

如题所述

在VB里面“工程”菜单下面添加“添加模块”,打开对话框,找到路径:X:\Program Files\lingo80\Dll(X为驱动盘)下的“Lingd80.bas”,添加到VB中。
在VB界面上设计Text1和Text2、Command1。
编写语句:
Private Sub Command1_Click()
'------------------------
Dim nError As Long
Dim pLINGO As Long
Dim nPointersNow As Long
Dim cScript As String
Dim Apppath As String
Dim dStatus As Double
Apppath = "take" & Space(1) & Right(App.Path, Len(App.Path) - 2)
'------------------------
On Error GoTo ERROREXIT
pLINGO = LScreateEnvLng()
'------------------------
Dim x As Double, y As Double
x = Text1.Text
'------------------------
nError = LSsetPointerLng(pLINGO, x, nPointersNow)
nError = LSsetPointerLng(pLINGO, y, nPointersNow)
'------------------------
On Error GoTo ERROREXIT
nError = LSexecuteScriptLng(pLINGO, cScript)
'------------------------
dStatus = -1#
nError = LSsetPointerLng(pLINGO, dStatus, nPointersNow)
'------------------------
cScript = "SET ECHOIN 1" & Chr(10)
cScript = cScript & Apppath & "\LINGO1.lng" & Chr(10)
cScript = cScript & "GO" & Chr(10)
cScript = cScript & "QUIT" & Chr(10)
cScript = cScript & Chr(0)
On Error GoTo ERROREXIT
nError = LSexecuteScriptLng(pLINGO, cScript)
'------------------------
LScloseLogFileLng (pLINGO)
LSdeleteEnvLng (pLINGO)
'------------------------
Text2.Text = y
ERROREXIT:
End Sub
然后再用lingo8.0编写代码(命名为LINGO1.lng,注意要保存为.lng文件):
model:
data:
x=@pointer(1);
enddata
y=x*2;
data:
@pointer(2)=y;
enddata
end
将.lng文件和VB代码放同一文件夹,即可运行VB控制Lingo的输入(本程序是由VB的Text1输入x,由lingo完成y=2x计算,计算结果返回到VB中Text2)。
温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网