Help wordbasic code vs. activedocument

B

Bob Alston

Have a numeric form field of length 3.

What does the following line NOT work

WordBasic.setformresult "Nutrition2", 4

While the next line DOES work
ActiveDocument.FormFields("nutrition2").Result = 4

?

I am using the wordbasic commands, which work quite well to set text
fields in form fields and are 60 times faster than the activedocument
equivalent. But for numeric fields, the wordbasic code does not work.

What am I missing.

bob

bobalston9 At yahoo D O T c o m
 
D

Doug Robbins - Word MVP

Use

WordBasic.setformresult "Nutrition2", "4"


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
J

Jay Freedman

In case you're interested, there is a genuine reason for this apparent
discrepancy.

In the syntax

ActiveDocument.FormFields("nutrition2").Result = 4

the .Result property is of data type String, while the 4 is of data type
Integer. The equal-sign operator has multiple overloads to do automatic data
type conversion (technically, "coercion") for mismatches like this.

The WordBasic.SetFormResult function doesn't have any such overload; when you
try to assign an Integer value to its String argument, it just throws a type
mismatch error. You must give it a string, which is what the added quotes
provide.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all
may benefit.
 

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