PC Review


Reply
Thread Tools Rate Thread

Conversion issue with option strict

 
 
John
Guest
Posts: n/a
 
      13th Apr 2004
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 With Quote
 
 
 
 
Gary Hunt
Guest
Posts: n/a
 
      13th Apr 2004
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

"John" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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 With Quote
 
John
Guest
Posts: n/a
 
      13th Apr 2004

Dim WordDoc As Word.Document
"Gary Hunt" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...

> 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
>
> "John" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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 With Quote
 
John
Guest
Posts: n/a
 
      13th Apr 2004
PS: Option Explicit on as well. Thanks.

Regards

"Gary Hunt" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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
>
> "John" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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 With Quote
 
John
Guest
Posts: n/a
 
      13th Apr 2004
I have tried this;

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

Thanks

Regards



"Gary Hunt" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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
>
> "John" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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 With Quote
 
Gary Milton
Guest
Posts: n/a
 
      13th Apr 2004
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

"John" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I have tried this;
>
> WordDoc = WordApp.Documents.Add(CObj(Temp))
> and the error has gone. Is this correct?
>
> Thanks
>
> Regards
>
>
>
> "Gary Hunt" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
> > 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
> >
> > "John" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RE: object conversion w/ option strict on =?Utf-8?B?SmVycnlI?= Microsoft Dot NET 0 17th Sep 2004 09:15 PM
Re: object conversion with option strict on Mattias Sjögren Microsoft Dot NET 1 17th Sep 2004 09:13 PM
object conversion with option strict on =?Utf-8?B?SmVycnlI?= Microsoft Dot NET 0 17th Sep 2004 07:21 PM
object conversion w/ option strict on =?Utf-8?B?SmVycnlI?= Microsoft Dot NET 0 17th Sep 2004 07:19 PM
Narrowing Array Conversion with Option Strict On Codemonkey Microsoft VB .NET 9 12th Jan 2004 01:36 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:12 AM.