473,396 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Option strict question.

Bob
I got a bit of code that launches Word and opens a file, as follows
Private sub OpenWord(Byval Fname as string)

Dim MyWord As New Microsoft.Office.Interop.Word.Application

Dim doc As Microsoft.Office.Interop.Word.Document

doc = MyWord.Documents.Open(Fname)

doc.activate()

MyWord.visible = true

end sub

When my project properties has Option strict On (which is what I want) I get
a blue underline in the IDE under the variable Fname (string type) and it
tells me that the string type can not be converted to object implicitly. I
do look at the intellisense of the Open method and I see the parameter
filename is of type object.

What do I need to do to be able to use my passed parameter Fname in the Open
method?

Thanks for any help

Bob
Aug 14 '06 #1
6 1081
I cannot use office interop, however if the input is an object of a string,
could you simply use cObj(somestring)?

"Bob" <bd*****@sgiims.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>I got a bit of code that launches Word and opens a file, as follows
Private sub OpenWord(Byval Fname as string)

Dim MyWord As New Microsoft.Office.Interop.Word.Application

Dim doc As Microsoft.Office.Interop.Word.Document

doc = MyWord.Documents.Open(Fname)

doc.activate()

MyWord.visible = true

end sub

When my project properties has Option strict On (which is what I want) I
get a blue underline in the IDE under the variable Fname (string type) and
it tells me that the string type can not be converted to object
implicitly. I do look at the intellisense of the Open method and I see the
parameter filename is of type object.

What do I need to do to be able to use my passed parameter Fname in the
Open method?

Thanks for any help

Bob


Aug 14 '06 #2
Bob,

Did you try it explicitly
dim oFname as object = Fname
doc = MyWord.Documents.Open(oFname)

or just cast it
doc = MyWord.Documents.Open(DirectCast(Fname,object))

Office interop is not my favorite kind of sport therefore just a gues.

Cor

"Bob" <bd*****@sgiims.comschreef in bericht
news:%2****************@TK2MSFTNGP04.phx.gbl...
>I got a bit of code that launches Word and opens a file, as follows
Private sub OpenWord(Byval Fname as string)

Dim MyWord As New Microsoft.Office.Interop.Word.Application

Dim doc As Microsoft.Office.Interop.Word.Document

doc = MyWord.Documents.Open(Fname)

doc.activate()

MyWord.visible = true

end sub

When my project properties has Option strict On (which is what I want) I
get a blue underline in the IDE under the variable Fname (string type) and
it tells me that the string type can not be converted to object
implicitly. I do look at the intellisense of the Open method and I see the
parameter filename is of type object.

What do I need to do to be able to use my passed parameter Fname in the
Open method?

Thanks for any help

Bob


Aug 14 '06 #3
Bob wrote:
I got a bit of code that launches Word and opens a file, as follows
Private sub OpenWord(Byval Fname as string)

Dim MyWord As New Microsoft.Office.Interop.Word.Application

Dim doc As Microsoft.Office.Interop.Word.Document

doc = MyWord.Documents.Open(Fname)

doc.activate()

MyWord.visible = true

end sub
Do you need to control the Word session? Why not use the Process
class:

Process.Start(Fname)

That should automatically start Word with that document.

Aug 14 '06 #4
Process.Start seems to be a much simpler solution if it meets the OP's needs.
I would second it. The big trick with the PIA's (primary interop assemblies)
is that they're a PIA. This is particularly true if you deploy to clients
who have differing versions of office installed as the PIA's are targeted
to individual office versions.

Jim Wooley
http://devauthority.com/blogs/jwooley/default.aspx
Bob wrote:
>I got a bit of code that launches Word and opens a file, as follows
Private sub OpenWord(Byval Fname as string)

Dim MyWord As New Microsoft.Office.Interop.Word.Application

Dim doc As Microsoft.Office.Interop.Word.Document

doc = MyWord.Documents.Open(Fname)

doc.activate()

MyWord.visible = true

end sub
Do you need to control the Word session? Why not use the Process
class:

Process.Start(Fname)

That should automatically start Word with that document.

Aug 14 '06 #5
Bob
Yeah I tried that and it works, thanks Cor
Bob
"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:uD**************@TK2MSFTNGP03.phx.gbl...
Bob,

Did you try it explicitly
dim oFname as object = Fname
doc = MyWord.Documents.Open(oFname)

or just cast it
doc = MyWord.Documents.Open(DirectCast(Fname,object))

Office interop is not my favorite kind of sport therefore just a gues.

Cor

"Bob" <bd*****@sgiims.comschreef in bericht
news:%2****************@TK2MSFTNGP04.phx.gbl...
>>I got a bit of code that launches Word and opens a file, as follows
Private sub OpenWord(Byval Fname as string)

Dim MyWord As New Microsoft.Office.Interop.Word.Application

Dim doc As Microsoft.Office.Interop.Word.Document

doc = MyWord.Documents.Open(Fname)

doc.activate()

MyWord.visible = true

end sub

When my project properties has Option strict On (which is what I want) I
get a blue underline in the IDE under the variable Fname (string type)
and it tells me that the string type can not be converted to object
implicitly. I do look at the intellisense of the Open method and I see
the parameter filename is of type object.

What do I need to do to be able to use my passed parameter Fname in the
Open method?

Thanks for any help

Bob



Aug 14 '06 #6
Bob
Thanks I will try the process ,
I was having a problem with the distributed test app that would not start
Word, so you may have saved me anoter problem. Thanks again
Bob
"Chris Dunaway" <du******@gmail.comwrote in message
news:11*********************@m79g2000cwm.googlegro ups.com...
Bob wrote:
>I got a bit of code that launches Word and opens a file, as follows
Private sub OpenWord(Byval Fname as string)

Dim MyWord As New Microsoft.Office.Interop.Word.Application

Dim doc As Microsoft.Office.Interop.Word.Document

doc = MyWord.Documents.Open(Fname)

doc.activate()

MyWord.visible = true

end sub

Do you need to control the Word session? Why not use the Process
class:

Process.Start(Fname)

That should automatically start Word with that document.

Aug 14 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Kenneth | last post by:
Should I have it ON or OFF //Kenneth
0
by: JerryH | last post by:
I'm using a 3rd party dll to retrieve some data (I have no choice in this!), this returns an Object variable that I know contains an array of singles. The following code works fine if I set option...
0
by: JerryH | last post by:
I'm using a 3rd party dll to retrieve some data (I have no choice in this!), this returns an Object variable that I know contains an array of singles. The following code works fine if I set option...
9
by: Microsoft News | last post by:
I have a project that was created all with Option Strict OFF. Works great, not a problem with it. But if I turn Option Strict ON then I get a LOT of errors. My question, should I even care...
11
by: Daylor | last post by:
hi. im using option strict on. im doing in ,from the simple reason ,to be warn when there are implict conversion like string to int ,int to string. BUT. the price ,(now i see ), is very bad....
8
by: Rich | last post by:
Hello, If I leave Option Strict Off I can use the following syntax to read data from a Lotus Notes application (a NotesViewEntry object represents a row of data from a Lotus Notes View - like a...
30
by: Microsoft News | last post by:
I have a project that was created all with Option Strict OFF. Works great, not a problem with it. But if I turn Option Strict ON then I get a LOT of errors. My question, should I even care...
17
by: David | last post by:
Hi all, I have the following problem: my program works fine, but when I add option strict at the top of the form, the following sub fails with an error that option strict does not allow late...
8
by: Rory Becker | last post by:
A wise man once said: "Never put off until runtime what you can fix at compile time." Actually I think he said it about 10 minutes before I started this post. I am a firm believer, like the...
8
by: =?Utf-8?B?R3JlZw==?= | last post by:
We have an application in our office that has the Option Strict option set to off right now. I do understand it should be set to ON, but right now, I'm just going to continue with it this way since...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.