SmartTag being recognised multiple times

N

NickP

Hi there,

My SmartTags are being recognised more than once, and as I have a
property that is initialised to a default value, it clears the tag, for
example

1. Type MyTag
2. Tag gets recognised, property "Stuff" is initialised with a value of
"Empty"
3. Invoke verb "Foobar", property "Stuff" gets changed to a temporary
filename
4. Press return
5. Repeat from step 2, then end

Sometimes it even gets recognised more than once in the first instance.

So basically, what I'm asking is, how do I stop this? I am following
the standard MS sample for recognising tags, and it is this that has the
bug...

----

http://msdn2.microsoft.com/en-us/library/aa163620(office.10).aspx

.......


Public Sub Recognize(ByVal strRecText As String, _
ByVal DataType As SmartTagLib.IF_TYPE, _
ByVal LocaleID As Integer, _
ByVal RecognizerSite As SmartTagLib.ISmartTagRecognizerSite) _
Implements SmartTagLib.ISmartTagRecognizer.Recognize

Dim intLocation As Integer = InStr(strRecText, "VB.NET",
CompareMethod.Text)
If intLocation > 0 Then
Dim stPropBag As ISmartTagProperties =
RecognizerSite.GetNewPropertyBag()
Dim strPropType As String
' Determine the data type (as a string).
Select Case DataType
Case IF_TYPE.IF_TYPE_CELL
strPropType = "IF_TYPE_CELL"
Case IF_TYPE.IF_TYPE_CHAR
strPropType = "IF_TYPE_CHAR"
Case IF_TYPE.IF_TYPE_PARA
strPropType = "IF_TYPE_PARA"
Case IF_TYPE.IF_TYPE_REGEXP
strPropType = "IF_TYPE_REGEXP"
Case IF_TYPE.IF_TYPE_SINGLE_WD
strPropType = "IF_TYPE_SINGLE_WD"
End Select
'Add the data type to the property bag.
stPropBag.Write("DataType", strPropType)
'Add the text sent to the function.
stPropBag.Write("Text", strRecText)
'Add the LocaleID.
stPropBag.Write("LocaleID", LocaleID)
'Commit the SmartTag.
RecognizerSite.CommitSmartTag("urn:samples-msdn-microsoft-
com#VBNetSmartTag", _
intLocation, 6, stPropBag) << this line ends up
getting called twice which overwrites the previous SmartTag.
End If
End Sub

-----

Some how, I need to check to see if the Smart Tag has already been
commited. But then again, surely if it has already been committed, it
shouldn't be recognising it again?

Thanks in advance.

Nick.
 
N

NickP

Hi there,

I have managed to work around the issue by introducing an indexer into
my tag recognition. For example

MyTag_1 or MyTag_60

I then use the index to check to see if the property has already been
set and is available. That way the tag can even be completely erased, but
when you type it again, the property is still available. Which is perfect
for my need.

Of course I had to use Regular Expressions to analyse the string
correctly as the method in the default sample only allows for 1 tag per
paragraph.

Nick.
 
N

NickP

Actually this doesn't help at all. Is it just me or does this whole Smart
Tag system seem flawed?

How am I supposed to retain a list of custom properties? When I load the
document again, it recognises the tag "again", rather than just loading the
old one, which i would have hoped to have been saved. And then commits it
again, erasing the old information.

How is everyone else using these?

Nick.
 
N

NickP

I can only presume that this isn't meant to happen. As I've just modifed
the sample by MS to include an integer custom property with an increment
verb. That works, but only on 1 tag, every other tags value is not saved.
I'll upload a sample of what I'm doing in a minute...
 
N

NickP

Ahaaa! I have discovered the problem.

Changing a Smart Tags properties does not mark the document as being dirty
and in requirement of a save, so pressing save, unless I have actually
changed the document in another way, does not do anything. My tags are
saving as expected now.

Nick.
 
J

Jialiang Ge [MSFT]

Hello Nick

I am glad to see you have found a workaround for the issue. Honestly, I
cannot figure out how to reproduce the problem. What is that 'property'?
How is it set in your code? I tested the demo project in
http://msdn2.microsoft.com/en-us/library/aa163620(office.10).aspx. It works
well in my side. If you need any other cocern, please feel free to raise
it. But please add a more detailed description of the issue.

Sincerely,
Jialiang Ge ([email protected], remove ¡®online.¡¯)
Microsoft Online Community Support

==================================================
For MSDN subscribers whose posts are left unanswered, please check this
document: http://blogs.msdn.com/msdnts/pages/postingAlias.aspx

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express/Windows Mail, please make sure
you clear the check box ¡°Tools/Options/Read: Get 300 headers at a time¡±
to see your reply promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided ¡°AS IS¡± with no warranties, and confers no
rights.
 
N

NickP

FYI.

Document.Saved = False

NickP said:
Ahaaa! I have discovered the problem.

Changing a Smart Tags properties does not mark the document as being dirty
and in requirement of a save, so pressing save, unless I have actually
changed the document in another way, does not do anything. My tags are
saving as expected now.

Nick.
 
N

NickP

Hi Jialiang,

1. Download modified sample source code from
http://nickpateman.m6.net/files/SmartTagVBNet.zip
2. Compile Solution
3. Install solution on target system
4. Register VBNetSmartTag.dll using regasm manually as even
Microsofts own example doesn't perform the deployment process correctly.
5. Create a word document and type the phrase VB.NET
6. Click on the Smart Tag action, and then click "Show custom
property"
Note, value = 0
7. Click on the Smart Tag action, and then click on "Increment custom
property"
Repeat step 6, Note, value = 1
8. Save
9. Close, and reopen the document
10. Once the tag has been recognised, click on the Smart Tag action and
then click on "Show custom property"
the value should = 1
11. Click on the Smart Tag action, and then click on "Increment custom
property"
Repeat step 10, Note, value = 2
12. Click save on the Quick Access Toolbar
Repeat from step 9

Note how the value reverts back to 1, unless you change the document via
another means, such as changing the text etc.

The resoluton was to mark the ActiveDocument.Saved property to False
after using the Properties.Write method.

Cheers.

Nick.
 

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