VB与MATLAB混合编程探讨

[09-12 17:52:18]   来源:http://www.88dzw.com  单片机学习   阅读:8781

文章摘要:Dim i As IntegerDim a As IntegerDim b As StringText1.Text = ″″Open App.Path & ″\t.txt ″ For Output As #1For i = 1 To 16a = Int(10 * Rnd)Print #1, LTrim(a)b = b & Str(a) & Chr(13) & Chr(10)Next iText1.Text = bClose #1End Sub声明mlfTest()函数:Private Declare Sub mlfTest Lib ″G\test\dll\dll.dll″ 调用该函数的事

VB与MATLAB混合编程探讨,标签:单片机开发,单片机原理,单片机教程,http://www.88dzw.com
Dim i As Integer

Dim a As Integer

Dim b As String

Text1.Text = ″″

Open App.Path & ″\t.txt ″ For Output As #1

For i = 1 To 16

a = Int(10 * Rnd)

Print #1, LTrim(a)

b = b & Str(a) & Chr(13) & Chr(10)

Next i

Text1.Text = b

Close #1

End Sub

声明mlfTest()函数:

Private Declare Sub mlfTest Lib ″G\test\dll\dll.dll″ 

调用该函数的事件代码:

Private Sub Command2_Click()

MlfTest '调用函数

End Sub

本例中未向函数传递参数,也无需函数返回运算结果,故采用调用子程序过程(Sub)方式直接调用。结果由VB读取文件获得:

Private Sub Command3_Click()

Dim str1 As String

Dim str2 As String

Text2.Text = ″″

Open App.Path & ″\t.txt″ For Input As #1

Do While Not EOF1

Line Input #1 str1

str2 = str2 & str1 & Chr(13) & Chr(10)

Loop

Text2.Text = str2

Close #1

End Sub

本例在Windows XP、VB6.0、VC++6.0、MATLAB6.5下调试通过。VB与MATLAB的混合编程,可以脱离MATLAB环境运行,有利于程序发布及使用。通过二者结合,减少了设计算法的时间,降低了编程难度,同时兼顾了代码安全和界面友好。程序界面如图2所示。




上一页  [1] [2] [3] 


Tag:单片机学习单片机开发,单片机原理,单片机教程单片机学习

《VB与MATLAB混合编程探讨》相关文章

分类导航
最新更新
热门排行