MS Word properties that are read-only in VB.Net but not in VBA

G

Guest

Apologies if this is the wrong forum. I normally post in the Word Programming
group, but this seemed like more of a VB.Net question.

I'm moving code from VBA over to Visual Studio Express 2005 (Visual Basic)
while still learning about VB.Net. (Not a good combination, I know.)

One problem I'm seeing is that certain lines of code that work when run
inside Word fail in a VB.Net app because I'm trying to set a read-only
property. For example, when dealing with the Range object in Word, in the VBA
Editor, you can write this:

dim r as Range
[blah blah blah]
r.Characters.Last= "T"

This should make the last character in the range "r" a capital T. It works
in the VBA Editor with no errors, but in Visual Studio Express, it tells me
"Last is a read-only property."

I tried creating a variable:

dim strTmp as String
strTmp=r.Characters.Last
strTmp="T"

But that doesn't work, because it won't let you assign "Last" to a string.
Any ideas?

Again, I wasn't certain where to put this, but I saw other Microsoft Word
questions here and figured I'd add my own. Thanks in advance!
 
G

Guest

Solved by the following, but I'm still curious to understand what's really
going on.

Dim rLastChar As Word.Range
rLastChar = r.Characters.Last
rLastChar.Text = "T"
 
A

Armin Zingler

Benjamino5 said:
Apologies if this is the wrong forum. I normally post in the Word
Programming group, but this seemed like more of a VB.Net question.

I'm moving code from VBA over to Visual Studio Express 2005 (Visual
Basic) while still learning about VB.Net. (Not a good combination, I
know.)

One problem I'm seeing is that certain lines of code that work when
run inside Word fail in a VB.Net app because I'm trying to set a
read-only property. For example, when dealing with the Range object
in Word, in the VBA Editor, you can write this:

dim r as Range
[blah blah blah]
r.Characters.Last= "T"

The type of the Last property is Range. "T" is a string. You can not assign
a string to a range property. Maybe you wanted to write

r.Characters.Last.Text = "T"


Armin
 
A

Armin Zingler

Benjamino5 said:
Solved by the following, but I'm still curious to understand what's
really going on.

Dim rLastChar As Word.Range
rLastChar = r.Characters.Last
rLastChar.Text = "T"


Do you know what Default properties are? "Text" is the default property of
the Range class. In VB.Net, Default properties without arguments are not
supported. You must explicitly refer to the property. It wasn't clear
whether you wanted to assign something to the Last property or to the
Default property of the Last property. In VBA, it's not as strict, which has
the disadvantage that the code is not as clear (as your question shows), and
it has performance drawbacks because it has to find the default property at
runtime, then assign the value or raise an error if there wasn't a Default
property at all. VB.Net eliminates this cause of fault before, at compile
time.


Armin
 
G

Guest

Armin,

I'd heard vaguely of this issue but hadn't fully understood it. Thanks! I'm
going to spend a lot more time looking into default properties from now on. I
see what you mean about this reducing problems and improving performance.

Ben

Armin Zingler said:
Benjamino5 said:
Apologies if this is the wrong forum. I normally post in the Word
Programming group, but this seemed like more of a VB.Net question.

I'm moving code from VBA over to Visual Studio Express 2005 (Visual
Basic) while still learning about VB.Net. (Not a good combination, I
know.)

One problem I'm seeing is that certain lines of code that work when
run inside Word fail in a VB.Net app because I'm trying to set a
read-only property. For example, when dealing with the Range object
in Word, in the VBA Editor, you can write this:

dim r as Range
[blah blah blah]
r.Characters.Last= "T"

The type of the Last property is Range. "T" is a string. You can not assign
a string to a range property. Maybe you wanted to write

r.Characters.Last.Text = "T"


Armin
 
K

kwek

Hi...

I am new to VB.net. Curretly i working with my final year project. Nw i need to read and find the content from the doc file. I have to read the whole content of the doc file.And will start to find the content from the references below.

Example:

References:

[1] L. Bernstein, “Get The Design Right”. IEEE Software, Vol. 10 No. 5, September 1993, pp. 61-63.

[2] Z. Razak, “The Internet Global Villages”, in Using IT to Build a Better Future Conference, Kuala Lumpur, 3 October 1995.


i need to get content within quotes “ ” from the references which is the title. Is there any solution to read and search all the "title" from doc???

EggHeadCafe - .NET Developer Portal of Choice
http://www.eggheadcafe.com
 
L

lmefford

Hi...

I am new to VB.net. Curretly i working with my final year project. Nw i need to read and find the content from the doc file. I have to read the whole content of the doc file.And will start to find the content from the references below.

Example:

References:

[1] L. Bernstein, "Get The Design Right". IEEE Software, Vol. 10 No. 5, September 1993, pp. 61-63.

[2] Z. Razak, "The Internet Global Villages", in Using IT to Build a Better Future Conference, Kuala Lumpur, 3 October 1995.

i need to get content within quotes " " from the references which is the title. Is there any solution to read and search all the "title" from doc???

EggHeadCafe - .NET Developer Portal of Choicehttp://www.eggheadcafe.com

I haven't worked with the interop.word, but I'm using interop.excel
right now. If I'm understanding you correctly, you want to be able to
pull the book titles from the references regardless of what the title
is, or what?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top