vb6.0 setup and addin setup

Add-in Express™ Support Service
That's what is more important than anything else

vb6.0 setup and addin setup
 
Ashish Sharma


Guest


Hi,

I am creating an application like spell checker which will poplup for a word if that word is there in the database and shows the alternative for that word to the user. once the user click on "Replace" button the alternative text shown in the list box of the form shw overwrite the text in the msword window.

Dim Selec As Word.Selection = Nothing
' coding for selecting the word in msword window
'after this below coding for replacing the text
Selec.Text = lstAlternative.SelectedItem & ""

the above code is not working.

i m having same application created using vb6.0 and when i run the setup for vb6.0 addin my "Replace button" coding is working fine.

Don't know watz going on ?
Posted 11 Mar, 2008 06:03:56 Top
Sergey Grischenko


Add-in Express team


Posts: 7230
Joined: 2004-07-05
Hi Ashish.

Where do you initialize the Selec variable?
Posted 11 Mar, 2008 12:08:35 Top
Ashish Sharma


Guest


Hi Sergey,

I had initialize the Selec Variable in some other function and i m able to get the highlighted text in a messagebox

Dim Selec As Word.Selection = Nothing
Dim actDoc As Word.Document = Nothing
Dim sen As Word.Sentences = Nothing
Try
Selec = ActiveWindow.Selection
actDoc = ActiveWindow.Document
sen = ActiveWindow.Document.Sentences

Selec.SetRange(sen.Item(1).Words.Item(count).Start, sen.Item(1).Words.Item(count).End - 1)

after this i m using replace coding here
Selec.Text = lstAlternative.SelectedItem & ""

Posted 11 Mar, 2008 12:30:34 Top
Sergey Grischenko


Add-in Express team


Posts: 7230
Joined: 2004-07-05
Ashish, what is the lstAlternative reference?
Please send me a sample project that reproduces the issue. I will test it.
Posted 11 Mar, 2008 13:31:21 Top
Ashish Sharma


Guest


Below is the code which i m using for replacing the selected text in msword window with "XXX" if user type the word "ashish".

after replacing the word MSword window is not taking any focus and i have to close the word window focefully by going to task manger and ending Ms word.

Private Sub AddinModule_OnKeyDown(ByVal sender As System.Object, ByVal virtualKey As System.Int32, ByVal keystrokeFlags As System.Int32, ByVal ctrl As System.Boolean, ByVal shift As System.Boolean) Handles MyBase.OnKeyDown
If virtualKey = 32 Then
Dim ActiveWindow As Object = Nothing
Dim sen As Word.Sentences = Nothing
Dim par As Word.Paragraph = Nothing
Dim ab As Word.Paragraphs = Nothing
Dim Selec As Word.Selection = Nothing
' Dim rang As Word.Range = Nothing

Try
ActiveWindow = AddinExpress.MSO.ADXAddinModule.CurrentInstance.HostApplication.ActiveWindow

ab = ActiveWindow.Document.Paragraphs
sen = ActiveWindow.Document.Sentences
Selec = ActiveWindow.Selection
Dim NoOfWordsNew As Integer = 0
NoOfWordsNew = sen.Item(1).Words.Count()

'if in the docume the word ashish is found then replace that word with "XXX"
If ("ashish" = sen.Item(1).Words.Item(NoOfWordsNew - 1).Text) Then
MsgBox(" Word Found ")
Selec.SetRange(sen.Item(1).Words.Item(NoOfWordsNew - 1).Start, sen.Item(1).Words.Item(NoOfWordsNew - 1).End)
Selec.Text = "XXX"

'the below one is also not working
'sen.Item(1).Words.Item(3).Text = "XXX"
End If
Finally
If Not (ab Is Nothing) Then Marshal.ReleaseComObject(ab)
If Not (sen Is Nothing) Then Marshal.ReleaseComObject(sen)
If Not (par Is Nothing) Then Marshal.ReleaseComObject(par)
If Not (Selec Is Nothing) Then Marshal.ReleaseComObject(Selec)
If Not (ActiveWindow Is Nothing) Then Marshal.ReleaseComObject(ActiveWindow)

End Try
End If
End Sub
Posted 13 Mar, 2008 02:46:18 Top
Ashish Sharma


Guest


i had also mailed the sample project to support mail
Posted 13 Mar, 2008 07:57:14 Top
Sergey Grischenko


Add-in Express team


Posts: 7230
Joined: 2004-07-05
Hi Ashish.

All indexes in the Office Object model are not zero based. Please try to replace the code 'NoOfWordsNew - 1' with 'NoOfWordsNew'.
Posted 13 Mar, 2008 10:51:48 Top
Ashish Sharma


Guest


replacing the code 'NoOfWordsNew - 1' with 'NoOfWordsNew' will never satisfy the if condition

If ("ashish" = sen.Item(1).Words.Item(NoOfWordsNew - 1).Text) Then

because the moment i press space the
sen.Item(1).Words.Item(NoOfWordsNew).Text will have " " in it

i had already mailed the project to the support id.
Posted 13 Mar, 2008 11:17:37 Top
Sergey Grischenko


Add-in Express team


Posts: 7230
Joined: 2004-07-05
Hi Ashish.

I tested the project. I managed to reproduce the issue. Now I don't have any solution. I will let you know if I find a workaround. I think the cause of the issue is that Word proceses the user input in a separate thread.

Posted 13 Mar, 2008 12:00:58 Top
Ashish Sharma


Guest


Hi Sergey

any luck

Posted 14 Mar, 2008 08:06:03 Top