Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / General / May 2006

Tip: Looking for answers? Try searching our database.

newbie question - how to create an instance of an application object

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
GSP@DCS - 26 May 2006 10:41 GMT
To put things into perspective, I've been using Visual Studio for a total of
1 week now. I'm researching how to transports data from Filemaker to MySQL
and found an interesting article on how to accomplish this. I just can't
interpret the instructions into tasks that I can do. In the article, the
author says....

I do a daily automated export from a filemaker application to MS Access and
I have done it in the past to mysql as well.  I am also 90%
done writing a VB.net app that does similiar stuff. It is pretty easy do
because FileMaker exposes itself to Windows via a COM object. So
basically in either VBA or VB.net/VB6/C++ you just add the FileMaker COM
object as a reference and then create an instance of the FileMaker
Application object and Filemaker document object.  Look at the sample code I
have posted below.

Now I've figured ou tpart of it. I created a new project (blank) and have
added the Filemaker COM reference (what ever that is). So now I can see the
FMPRO50LIB under reference which is under my project name "FMInterface". How
do I create an instance of the application and document objects?

The sample code he provided is below....

*********  Sample Code   ***********
********* This is provided as is with no guarentee  ********

Function ControlFileMaker()
'On Error GoTo errorhandler

Dim cnn1 As ADODB.Connection
Dim rstFileMakerImportLog As ADODB.Recordset
Dim strCnn As String

Dim dtStartTime As Date
Dim dtEndTime As Date
Dim ExportCompleted As Boolean
Dim ErrorMessage As String
Dim strSQL As String

Dim appFM As FMPRO50Lib.Application
Set appFM = New FMPRO50Lib.Application

Dim FMdocs As FMPRO50Lib.Documents
Set FMdocs = appFM.Documents
Dim fmCinApps As FMPRO50Lib.Document
appFM.Visible = False

' Open a connection to Import Log table.

dtStartTime = Time
'Connects to my FileMaker database

Set fmCinApps = FMdocs.Open("C:<somefilename>.fp5", <password>)

'calls the "jason export" script in the <somefilename>.fp5 file
'that exports all records based on my find set as a .dbf then it opens

fmCinApps.DoFMScript ("jason export")

'the following do loop is used to prevent MSAccess from going to the
rest
'of the code until
'FileMaker is done exporting its data
Do Until IsEmpty(FMdocs.Active)
Loop

'I have set up a log table in my access program and the following
Do.cmd.runsql writes the date, start time and end time of the import.
'If the import
'fails then the errorhandler will run a different SQL statement that
'will list the date, starttime and error message.
strSQL = "INSERT INTO tblFileMakerImportLog ( RunDate, StartTime,
EndTime, Completed ) values ('" & Date & "', '" & dtStartTime & "', '"
&
Time() & "', true);"
Debug.Print strSQL

'Stops Access from popping up any warning messages about appending
'data to my log table
DoCmd.SetWarnings False
DoCmd.RunSQL (strSQL)
DoCmd.SetWarnings True

'I can not remember why I commented out the next command.  It is
suppose to run the sub routine that cloose filemaker.  There must have
been some bug in my code that
'I never corrected.

'CloseFileMaker
Exit Function

errorhandler:
strSQL = "INSERT INTO tblFileMakerImportLog ( RunDate, StartTime,
EndTime, Completed, note ) values ('" & Date & "', '" & dtStartTime &
"', '" & Time() & "', true,'" & Err.Description & ");"
Debug.Print strSQL

DoCmd.SetWarnings False
DoCmd.RunSQL (strSQL)
DoCmd.SetWarnings True

CloseFileMaker

End Function

Sub CloseFileMaker()
Dim appFM As FMPRO50Lib.Application
Set appFM = New FMPRO50Lib.Application

Dim FMdocs As FMPRO50Lib.Documents
Set FMdocs = appFM.Documents
Dim fmCinApps As FMPRO50Lib.Document
appFM.Visible = True
appFM.Quit

End Sub
Carlos J. Quintero [VB MVP] - 29 May 2006 09:36 GMT
Hi,

For VB.NET programming questions, it is better to use the newsgroup
microsoft.public.dotnet.languages.vb. This newsgroup is really about VS.NET,
the IDE.

That said, you can create COM objects in VB.NET in two ways:

- If you have added a reference, you can use early binding:

Dim obj As MyCOMTypeLibrary.MyClass

obj = New MyCOMTypeLibrary.MyClass()

- If not, the equivalent late binding of the CreateObject function of VB6 in
VB.NET is:

Dim objType As System.Type
Dim obj As Object

objType = System.Type.GetTypeFromProgId("MyCOMTypeLibrary.MyClass")
obj = System.Activator.CreateInstance(objType)

Your post and your sample is too long to look into and you don´t say the
specific error that you get, but the above should help.

Signature

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio
You can code, design and document much faster:
http://www.mztools.com

> To put things into perspective, I've been using Visual Studio for a total
> of 1 week now. I'm researching how to transports data from Filemaker to
[quoted text clipped - 112 lines]
>
> End Sub

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.