empty document variables

J

Jan Kucera

Hi, XML Word format, I set these variables:
<w:docVars>
<w:docVar w:name="myVar1" w:val="Kibo" />
<w:docVar w:name="myVar2" w:val="Xibo" />
<w:docVar w:name="myVar3" w:val="Jaffo" /> ;-)))) getting loving
these...
<w:docVar w:name="myVar4" w:val="" />
<w:docVar w:name="myVar5" w:val="" />
</w:docVars>

In the document, I have fields that refers to these variables.
However, the variables with empty strings are not present in the document!
The field reports an error and ActiveDocument.Variables.Count returns 3.

How can I set the variables to empty string?

Thanks,
Jan
 
J

Jonathan West

Jan Kucera said:
Hi, XML Word format, I set these variables:
<w:docVars>
<w:docVar w:name="myVar1" w:val="Kibo" />
<w:docVar w:name="myVar2" w:val="Xibo" />
<w:docVar w:name="myVar3" w:val="Jaffo" /> ;-)))) getting loving
these...
<w:docVar w:name="myVar4" w:val="" />
<w:docVar w:name="myVar5" w:val="" />
</w:docVars>

In the document, I have fields that refers to these variables.
However, the variables with empty strings are not present in the document!
The field reports an error and ActiveDocument.Variables.Count returns 3.

How can I set the variables to empty string?

You can't. It is a holdover from the days before VBA when the method of
deleting a variable was to set it to a blank string. The nearest you can get
is to set it to a single space, and manage your code so that a single space
is treated as an empty string.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
J

Jan Kucera

Jonathan West said:
You can't. It is a holdover from the days before VBA when the method of
deleting a variable was to set it to a blank string. The nearest you can
get is to set it to a single space, and manage your code so that a single
space is treated as an empty string.

Well, nothing else remains so I will do like that. But why is the Word then
saving variables with empty strings......

Thanks for pointing that out before I get mad :), Jan.
 
J

Jean-Guy Marcil

Jan Kucera was telling us:
Jan Kucera nous racontait que :
Well, nothing else remains so I will do like that. But why is the
Word then saving variables with empty strings......

A string containing a space is not an empty string... ;-)

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

Jonathan West

Jean-Guy Marcil said:
Jan Kucera was telling us:
Jan Kucera nous racontait que :


A string containing a space is not an empty string... ;-)

I think the question Jan was asking is why, if when you set a Variable to an
empty string and it therefore disappears from the Variables collection in
VBA, does the tag of the Variable still appear with empty content when you
save the file as XML?

And I have no definite answer. I suspect it is a bug.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
J

Jan Kucera

Jonathan West said:
I think the question Jan was asking is why, if when you set a Variable to
an empty string and it therefore disappears from the Variables collection
in VBA, does the tag of the Variable still appear with empty content when
you save the file as XML?

And I have no definite answer. I suspect it is a bug.

Yes Jonathan, that was the question - thanks. ;-)
However you wrote a new information to me - when I set the variable to the
empty string, it will be deleted?
I was sooo near using Variables.Add("myVar", '") just to define it and set
later...

Jan
 
J

Jonathan West

Jan Kucera said:
Yes Jonathan, that was the question - thanks. ;-)
However you wrote a new information to me - when I set the variable to the
empty string, it will be deleted?

Yes. At least, it will disappear from the Variables collection in VBA. As
you have seen, the matching XML tag seems not to disappear.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
J

Jean-Guy Marcil

Jonathan West was telling us:
Jonathan West nous racontait que :

I think the question Jan was asking is why, if when you set a
Variable to an empty string and it therefore disappears from the
Variables collection in VBA, does the tag of the Variable still
appear with empty content when you save the file as XML?

Well done.
Your crystal ball is better than mine!

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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