我想打电话给matlab&同时从visual basic 6运行.m文件但是我得到这个运行时错误'91',变量没有设置bla bla。我搜索了互联网以找到任何解决方案,但我不能。我的代码有问题,我不知道它是什么。任何人都可以检查&看错了什么?
Private Sub Form_Load()
Dim MatLab As Object
Dim Result As String
Dim MReal(1, 3) As Double
Dim MImag(1, 3) As Double
Dim mat_exe As String
Dim mat_io_folder As String
Dim mat_m As String
mat_exe = "G:\matlab\bin\matlab.exe"
mat_io_folder = "G:\Farin\New folder"
mat_m = "Untitled.m"
FileName = mat_exe & " " & "addpath('mat_io_folder') & mat_m" & " -s1"
runmatlab = Shell(FileName, 1)
Result = MatLab.Execute("cd G:\Farin\New folder")
Result = MatLab.Execute("Untitled")
'Calling m-file from VB
'Assuming solve_bvp exists at specified location
'Result = MatLab.Execute("cd G:\Farin\New folder\Untitled")
End Sub
答案 0 :(得分:2)
VB6中的错误91表示未设置对象变量,在猜测时,它将是语句
result = MatLab.Execute("...")
Matlab被声明为一个对象,但尚未赋值。可以在https://msdn.microsoft.com/en-us/library/aa264975(v=VS.60).aspx
中找到VB6运行时错误列表另一个问题是文件名分配。它应该读
FileName = mat_exe & " " & "addpath('" & mat_io_folder & "') " & mat_m & " -s1"
在运行shell命令之前,可能会想到MsgBox文件名。