Cannot create ActiveX component/ File not found
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ahmed Siddig
el 12 de Jun. de 2018
Comentada: Ahmed Siddig
el 13 de Jun. de 2018
Hello again , am using vb.net and i have a matlab (.m) function and i want to run it inside vb.net so i used:
Dim Matlab As Object
Dim Result As String
Then i created a button so that when i press it it plots the graph of the matlab function using:
Matlab = CreateObject("Matlab.Application")
Result = Matlab.Execute("cd C:\Users\Bo$$\Documents\MATLAB\DF.m")
But i get this error:
(Cannot create ActiveX component)
on the command
Matlab = CreateObject("Matlab.Application")
So i tried:
Shell(Matlab.execute("DF"))
instead of the (Result) command. The plot appeared but i got this error (File not found) and i couldn't proceed with my program can you help me out thanks.
0 comentarios
Respuesta aceptada
Guillaume
el 12 de Jun. de 2018
Can you please use proper formatting (i.e. the {}Code button that's above the edit box when you write/edit your question) rather than inventing your own formatting.
I don't see how that Shell command would even work since the first argument to Shell must be the path of the executable. Not a VB object.
If
Matlab = CreateObject("Matlab.Application");
does not work then most likely Matlab is not registered properly as a COM server. Follow the instructions there
Note that your
cd C:\Users\Bo$$\Documents\MATLAB\DF.m
in your matlab execute is meaningless (unless DF.m is a folder. If you meant to call the script/function DF.m then the proper syntax would be:
Result = Matlab.Execute("C:\Users\Bo$$\Documents\MATLAB\DF.m")
with no cd at all.
Note that as documented in CreateObject, you're using late binding which is not recommended (slow). You could use early binding instead by adding to matlab on the COM tab of your project property. Then your code would be simply
Dim matlab As Matlab.Application
matlab.Execute("C:\Users\Bo$$\Documents\MATLAB\DF.m")
7 comentarios
Guillaume
el 13 de Jun. de 2018
The only thing that worked was ...
Well, no. By your own statement it didn't work since you get a file not found error. And it's no wonder it doesn't work you're trying to run the result returned by matlab.Execute as a shell command. If you were to run matlab through the shell then you'd have to pass the path to matlab and you don't need to create a COM object.
I'm not too sure of the reason for your CO_E_SERVER_EXEC_FAILURE. Are you sure that matlab is activated and has a valid license in the context in which your VB program execute?
I've just created a very basic VB.Net program in VS2015 with the following code:
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim matlab As New MLApp.MLApp
Dim result As String
matlab.Visible = True
result = matlab.Execute("cd C:\users\xxx\Documents\matlab\answers\")
result = matlab.Execute("answer")
End Sub
End Class
After adding a reference to Matlab of course. This executes without any issue. Matlab COM server starts (you can see its window) and executes the script as required.
I've also tried with late binding:
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim matlab As Object
Dim result As String
matlab = CreateObject("Matlab.Application")
matlab.Visible = True
result = matlab.Execute("cd C:\users\xxx\Documents\matlab\answers\")
result = matlab.Execute("answer")
End Sub
End Class
Again, no issue.
Más respuestas (0)
Ver también
Categorías
Más información sobre Use COM Objects in MATLAB en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!