| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1184 人关注过本帖, 1 人收藏
标题:求助 matlab与VB混编,应用COM技术
只看楼主 加入收藏
基地苦咖啡
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2017-4-13
结帖率:0
收藏(1)
已结贴  问题点数:20 回复次数:2 
求助 matlab与VB混编,应用COM技术
程序代码:
Private zxd As hanyzxd.hanyzxdClass
Dim xlApp As Excel.Application '定义EXCEL类
Dim xlBook As Excel.Workbook '定义工件簿类
Dim xlsheet As Excel.Worksheet '定义工作表类
Dim a() As Double, k As Integer
Private Sub Form_Load()
Me.Picture = LoadPicture("C:\Users\Administrator\Desktop\2013韩越\vb\zhuti.jpg")
Me.AutoRedraw = True
Set zxd = New hanyzxd.hanyzxdClass
End Sub
Private Sub Form_Resize()
Me.PaintPicture Me.Picture, 0, 0, Me.ScaleWidth, Me.ScaleHeight
End Sub
Private Sub Option1_Click()
If Text1.Text <> "" Then
Command1.Enabled = True
End If
End Sub

Private Sub Option2_Click()
If Text1.Text <> "" Then
Command1.Enabled = True
End If
End Sub
Private Sub Option3_Click()
If Text1.Text <> "" Then
Command1.Enabled = True
End If
End Sub
Private Sub Text1_Change()
If Text1.Text <> "" Then
Option1.Enabled = True
Option2.Enabled = True
Option3.Enabled = True
End If
End Sub
Private Sub Command1_Click() '打开EXCEL过程
If Dir("C:\Users\Administrator\Desktop\2013韩越\vb\shuju.bz") = "" Then '判断EXCEL是否打开
Set xlApp = CreateObject("Excel.Application") '创建EXCEL应用类
xlApp.Visible = True '设置EXCEL可见
Set xlBook = xlApp.Workbooks.Open("C:\Users\Administrator\Desktop\2013韩越\vb\shuju.xlsx") '打开EXCEL工作簿
If Option1.Value = True Then
Set xlsheet = xlBook.Worksheets(1) '打开EXCEL工作表
End If
If Option2.Value = True Then
Set xlsheet = xlBook.Worksheets(2)
End If
If Option3.Value = True Then
Set xlsheet = xlBook.Worksheets(3)
End If
xlsheet.Activate '激活工作表
xlBook.RunAutoMacros (xlAutoOpen) '运行EXCEL中的启动宏
Else
MsgBox ("EXCEL已打开")
End If
End Sub
Private Sub Command2_Click()
k = Text1.Text
ReDim a(1 To k, 3)
For i = 1 To 3
    For j = 1 To k
        a(j, i) = xlsheet.Cells(j + 1, i)
        Next j
    Next i
xlBook.RunAutoMacros (xlAutoClose) '执行EXCEL关闭宏
xlBook.Close (True) '关闭EXCEL工作簿
xlApp.Quit '关闭EXCEL
Set xlApp = Nothing '释放EXCEL对象
End Sub
Private Sub Command3_Click()
Dim x() As Variant, y() As Variant, wuchazxd As Variant
k = Val(Text1.Text)
ReDim x(k) As Variant, y(k) As Variant
    For i = 1 To k
      x(i) = a(i, 1)
      y(i) = a(i, 2)
      Next i
      Call zxd.HYzxd(1, wuchazxd, x, y)
      Text2.Text = Format(wuchazxd, "0.000000")
End Sub

运行之后,Call zxd.HYzxd(1, wuchazxd, x, y)错误,但不用改变任何程序,直接运行就能得出正确的结果!个人认为是wuchazxd的定义有问题,不知道怎么解决
搜索更多相关主题的帖子: matlab 技术 
2017-04-13 22:04
基地苦咖啡
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2017-4-13
收藏
得分:0 
求助,各位大神
2017-04-13 22:05
xiangyue0510
Rank: 14Rank: 14Rank: 14Rank: 14
等 级:贵宾
威 望:86
帖 子:941
专家分:5244
注 册:2015-8-10
收藏
得分:20 
没弄过,帮顶
2017-04-14 16:47
快速回复:求助 matlab与VB混编,应用COM技术
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019302 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved