Home  |  Index  |  Dotnet4all Snippets  |  Submit resources
About  |  Mail us  
Dotnet4all Logo

  Conversion issue with option strict (Friday, September 03, 2004)




Found the following interesting discussion in the Newsgroups:

Conversion issue with option strict
by:John

Hi

I am getting conversion errors in the below code on the lines highlighted in red. Would appreciate any tips on how to fix these errors.

Thanks

Regards
dim Company_ID As String
dim Temp As String
dim WordApp As Word.Application
company_id = "xxxx1"
temp = "c:\...\xxx.dot"
WordApp = New Word.Application
WordDoc = WordApp.Documents.Add(Temp) 'ERROR: Option Strict On disallows
implicit conversions from 'System.Object' to 'String'.
With WordDoc
.Variables.Add("CompanyID", Company_ID) 'ERROR: Option Strict On disallows
implicit conversions from 'System.Object' to 'String'.
End With


 Reply:
by:Gary Hunt

 What have you defined WordDoc as? and do you have Option Explicit on as well?

Most of us code with both Option Explicit and Option Strict turned on - anything else is just guessing :-)

The template you are passing in is defined as a Variant within the Documents.Add method so that might be causing the problem but I'm guessing the definition of WordDoc is the issue.

cheers,

g


 Reply:
by:John

 
Dim WordDoc As Word.Document


 Reply:
by:John

 PS: Option Explicit on as well. Thanks.

Regards



 Reply:
by:John

 I have tried this;

WordDoc = WordApp.Documents.Add(CObj(Temp))
and the error has gone. Is this correct?

Thanks

Regards


 Reply:
by:Gary Milton

 Hi John,

You can either do what you have just done or you can declare Temp as an Object instead of a String (same goes for Company_ID).

Gary








 
Previous Posts
    - How to activate the childform, arraylist, childmdi...
    - How to activate the childform, arraylist, childmdi...
    - Basic data processing with .net
    - Multiuser Problem in .net
    - MD5 checksum of Visual Studio 2k5 preview
    - scrollbar.scroll event occuring twice
    - Help with Graphics primitives
    - Setting button image with vb.net
    - ByRef parameters for objects / reference types
    - Two combo boxes tied together on data set with .ne...

Archives
    - 08/01/2004 - 08/08/2004
    - 08/08/2004 - 08/15/2004
    - 08/15/2004 - 08/22/2004
    - 08/22/2004 - 08/29/2004
    - 08/29/2004 - 09/05/2004
    - 09/05/2004 - 09/12/2004
    - 09/12/2004 - 09/19/2004
    - 09/19/2004 - 09/26/2004
    - 09/26/2004 - 10/03/2004
    - 10/03/2004 - 10/10/2004
    - 01/02/2005 - 01/09/2005
    - 01/09/2005 - 01/16/2005
    - 01/30/2005 - 02/06/2005
    - 01/01/2006 - 01/08/2006


Disclaimer & Terms of Use  | DotNet4All.Com concept & © 2004 - 2007 by  Zelders²  - Holland