Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 10th, 2006, 03:40 PM
Authorized User
 
Join Date: Mar 2006
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default Class Method takes Forever to run.

I have a class(EncounterForm) that basicly is fed SQL patient Data and prints a Word Doc. with the patient Info on it.
the method(.FormFill) to do this works well enough, but it pauses the first time it is called, I mean like a 3 or 4 minute pause. then it runs fine for the rest of the records. What am I doing to cause this pause, and why does it work after the first call?

The code for the method is :

Public Function FormFill(ByVal docname) As String


        Dim wordApp = New Word.Application
        wordApp = CreateObject("Word.Application")
        Dim wordDoc = New Word.Document

        Try

            Application.DoEvents()
            With wordApp
                .WindowState = Word.WdWindowState.wdWindowStateMinimize
                .Visible = False
                wordDoc = wordApp.Documents.Open(trim("Q:\" + docname), , True)
                wordDoc.Activate()
                .ActiveDocument.Bookmarks("PtName").Select()
                .Selection.Text = mstrPatientName
                .ActiveDocument.Bookmarks("Street1").Select()
                .Selection.Text = mstrStreet1
                .ActiveDocument.Bookmarks("Street2").Select()
                .Selection.Text = mstrStreet2
                .ActiveDocument.Bookmarks("City").Select()
                .Selection.Text = mstrCity
                .ActiveDocument.Bookmarks("State").Select()
                .Selection.Text = mstrState
                .ActiveDocument.Bookmarks("Zip").Select()
                .Selection.Text = mstrZip
                .ActiveDocument.Bookmarks("Phone").Select()
                .Selection.Text = mstrPhone
                .ActiveDocument.Bookmarks("InsName").Select()
                .Selection.Text = mstrInsurance
                .ActiveDocument.Bookmarks("Policy").Select()
                .Selection.Text = mstrPolicy
                .ActiveDocument.Bookmarks("CoPay").Select()
                .Selection.Text = mstrCoPay
                .ActiveDocument.Bookmarks("CoIns").Select()
                .Selection.Text = mstrCoIns
                '.ActiveDocument.Bookmarks("Attachments").Select()
                '.Selection.Text = mstrAttachments
                .ActiveDocument.Bookmarks("PtName2").Select()
                .Selection.Text = mstrPatientName
                '.ActiveDocument.Bookmarks("Acct").Select()
                ' .Selection.Text = mstrAcct
                .ActiveDocument.Bookmarks("Mr").Select()
                .Selection.Text = mstrMr
                .ActiveDocument.Bookmarks("Dob").Select()
                .Selection.Text = mstrDOB
                .ActiveDocument.Bookmarks("Dt").Select()
                .Selection.Text = mstrDte
                .ActiveDocument.Bookmarks("Time").Select()
                .Selection.Text = mstrTime
                .ActiveDocument.Bookmarks("Service").Select()
                .Selection.Text = mstrService
                .ActiveDocument.Bookmarks("Category").Select()
                .Selection.Text = mstrCategory
                .ActiveDocument.PrintOut(background:=False) 'then print it out
                .ActiveDocument.Close(False)
            End With
            wordApp.quit()

            GoTo Cleanup

        Catch ex As Exception
            MessageBox.Show("Error accessing Word document.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1)
            wordApp.quit()
            GoTo Cleanup
        End Try





Cleanup:


        wordApp = Nothing
        wordDoc = Nothing
        GC.Collect() ' <-- *** Important! ***
        GC.WaitForPendingFinalizers() ' <-- *** Important! ***
    End Function


----------------------
I would appreciate any input on this problem


 
Old April 11th, 2006, 09:18 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there...

as far as i know, calling the garbage collector by yourself is not a good idea.. let the GC run when he needs to.. don't force it...

also why so many goto???

HTH

Gonzalo





Similar Threads
Thread Thread Starter Forum Replies Last Post
can we pass integer in a method which takes object khatu_jec C# 4 March 31st, 2008 04:02 AM
xslt.Load method in c# takes about 8 seconds pradeepn XSLT 2 August 31st, 2007 03:53 PM
Instance of same class in main method ajit Java Basics 1 July 1st, 2006 06:26 PM
Compile method (Compiler class) stalker C# 2 November 11th, 2004 01:19 PM
About method of class in Web Service hueduongit .NET Web Services 5 December 11th, 2003 09:09 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.