November 02, 2008

Tips 1


Use #If ccDebug to View Hidden Automation Servers

One of the problems with testing and debugging a remote automation server is that the server application typically remains hidden, doing its work in the background. Hence, when something goes wrong, you frequently can't tell what has happened or where in your code your application is being derailed.

Consequently, when you're developing, testing, and debugging your application, it's a good idea to make sure that otherwise hidden automation server remain visible. You can do this by using code like the following to make sure that a new instance of an automation server (in this case Microsoft Word) is visible:

Dim objWord as Word.Application
Set objWord = New Application

#If ccDebug Then
objWord.Visible = True
#End If

You can define the project-level conditional compiler constant ccDebug in either of two ways:

*

By including the line
#Const ccDebug = 1

in the declarations section of a form or code module.
*

By using the Make tab of the Project Properties dialog (select the Project Properties option from the VB Project menu) and entering the following in the Conditional Compilation Arguments text box:
ccDebug = 1

Then, whenever your code runs in the design-time environment, you automation server will be visible. When you are ready to create the final executable, you should either set the ccDebug conditional compilation constant to 0 or, if you've used the Conditional Compilation Arguments text box, remove its definition.

0 comments:

Post a Comment

 

Copyright 2008 All Rights Reserved | Blogger Template by Computer Science and Computer Tips