Book a Demo

Author Topic: VBA EA Automation  (Read 8848 times)

EA2412

  • EA User
  • **
  • Posts: 66
  • Karma: +0/-0
    • View Profile
VBA EA Automation
« on: October 21, 2009, 05:30:12 pm »
Hi at all

I´m trying to get access to my EA shared model on MySQL Server using VBA. I think the implementation works fine but on starting the code the only thing what happens is that I´m prompted to type in my password and user account. The EA model does not appear.

Does anybody can help me on that problem?

Thanks in advance

Code: [Select]
Public Sub OpenRepository()

        Dim MyRep As New EA.Repository
        Dim MyPro As New EA.Project
        Dim GUID As String

        Set MyRep = CreateObject("EA.Repository")

        MyRep.OpenFile ("")
        Set MyPro = MyRep.GetProjectInterface()
End Sub

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: VBA EA Automation
« Reply #1 on: October 21, 2009, 06:41:05 pm »
Don't you think that is due to the
Code: [Select]
MyRep.OpenFile ("")I don't really see the sense of that line.

If you want to open a model that uses security you can use the
Operation "Repository.OpenFile2 (string FilePath, string Username, string Password)"


Geert

EA2412

  • EA User
  • **
  • Posts: 66
  • Karma: +0/-0
    • View Profile
Re: VBA EA Automation
« Reply #2 on: October 21, 2009, 09:05:08 pm »
Hi Geert,

thanks for your replay. I took off the path to the MySQL database. I thought that it will work with MyRep.OpenFile ("path")?

Thanks in advance

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: VBA EA Automation
« Reply #3 on: October 21, 2009, 09:37:54 pm »
In that case you'll need to provide the connectionstring to the database.

Geert

EA2412

  • EA User
  • **
  • Posts: 66
  • Karma: +0/-0
    • View Profile
Re: VBA EA Automation
« Reply #4 on: October 21, 2009, 09:55:54 pm »
Hi Geert,

I did it like in the following code

Code: [Select]
Public Sub OpenRepository()

        Dim MyRep As New EA.Repository
        Dim MyPro As New EA.Project
        Dim GUID As String

        Set MyRep = CreateObject("EA.Repository")

        MyRep.OpenFile ("model --- DBType=0;Connect=Provider=MSDASQL.1;Persist Security Info=False;Data Source=Model")
        Set MyPro = MyRep.GetProjectInterface()
End Sub

but the model didn´t appear. I was looking at the task manager and saw that there was a process going on regarding EA.exe. A minute  later the process was gone away. Don´t understand that.

Do you have any ideas?

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: VBA EA Automation
« Reply #5 on: October 22, 2009, 08:11:21 am »
As soon as that function finishes (ie. The project loads) the Repository object is going to go out of scope, so EA will close.

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: VBA EA Automation
« Reply #6 on: October 22, 2009, 11:32:01 am »
Quote
As soon as that function finishes (ie. The project loads) the Repository object is going to go out of scope, so EA will close.
Simon,

Do you mean the connection string is valid as shown with all the preamble?  I thought you needed to parse it and only provide the appropriate substring....

TIA,
Paolo
« Last Edit: October 22, 2009, 05:10:23 pm by PaoloFCantoni »
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: VBA EA Automation
« Reply #7 on: October 22, 2009, 05:03:48 pm »
I don't know if the connectionstring is valid, but Simon has a point.
You'll have to define the repository variable outside your sub or pass it to something else as a parameter since it will be destroyed as soon as the sub ends.

Geert

EA2412

  • EA User
  • **
  • Posts: 66
  • Karma: +0/-0
    • View Profile
Re: VBA EA Automation
« Reply #8 on: October 22, 2009, 11:48:38 pm »
Hi Geert,

thanks for your answer. Would you please give me an example for that you are describing. I´m a bit new at VBA.

Thanks in advance

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: VBA EA Automation
« Reply #9 on: October 23, 2009, 08:36:49 am »
I'm afraid I don't know VBA very well either, but Geert has understood what I was getting at.  I was not commenting on the connection string at all.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: VBA EA Automation
« Reply #10 on: October 23, 2009, 07:03:38 pm »
Well, for example something like this
Code: [Select]
Dim MyRep As New EA.Repository
Dim MyPro As New EA.Project

Public Sub OpenRepository()

        Dim GUID As String

        Set MyRep = CreateObject("EA.Repository")

        MyRep.OpenFile ("model --- DBType=0;Connect=Provider=MSDASQL.1;Persist Security Info=False;Data Source=Model")
        Set MyPro = MyRep.GetProjectInterface()
End Sub

It is all about the lifetime of your variables. If you define a variable within a prodedure or function then the scope of this variable is limited to said procedure or function.
This means that it will be destroyed as soon as the function or procedure ends.
By defining your variables outside the sub you can use them even if the sub is finished. (as long as the object containing the variable is still alive.

Geert