Pages in topic:   < [1 2]
Visual Basic Macro: Can someone debug it?
Thread poster: Patricia Rosas
Patricia Rosas
Patricia Rosas  Identity Verified
United States
Local time: 15:54
Spanish to English
+ ...
TOPIC STARTER
In memoriam
now the debugger doesn't like: Jul 31, 2009

speech.Speak vbNullString, SVSFPurgeBeforeSpeak

Should I take out the ' on the previous line?

Would you be willing to cut and copy your module here? Or are you certain it is identical to mine?


 
Jaroslaw Michalak
Jaroslaw Michalak  Identity Verified
Poland
Local time: 00:54
Member (2004)
English to Polish
SITE LOCALIZER
My module Jul 31, 2009

Yes, the commented line should be green, I do not know why yours is not... Are you sure it is a simple (straight) apostrophe?

Here's my module, I'm pretty sure it is the same as yours:

Code:

Dim speech As SpVoice 'Don't overlook this line!

Sub SpeakText()
'Based on a macro by Mathew Heikkila
&#... See more
Yes, the commented line should be green, I do not know why yours is not... Are you sure it is a simple (straight) apostrophe?

Here's my module, I'm pretty sure it is the same as yours:

Code:

Dim speech As SpVoice 'Don't overlook this line!

Sub SpeakText()
'Based on a macro by Mathew Heikkila
'
On Error Resume Next
Set speech = New SpVoice
If Len(Selection.Text) > 1 Then 'speak selection
speech.Speak Selection.Text, _
SVSFlagsAsync + SVSFPurgeBeforeSpeak
Else 'speak whole document
speech.Speak ActiveDocument.Range(0, ActiveDocument.Characters.Count).Text, _
SVSFlagsAsync + SVSFPurgeBeforeSpeak
End If
Do
DoEvents
Loop Until speech.WaitUntilDone(10)
Set speech = Nothing
End Sub

Sub StopSpeaking()
'Based on a macro by Mathew Heikkila
'used to interrupt any running speech to text
'On Error Resume Next
speech.Speak vbNullString, SVSFPurgeBeforeSpeak
Set speech = Nothing
End Sub



What you mean exactly by „doesn't like”? It stops on that line when you try to stop the speech?

Pause/Break should be one of three keys grouped together above Insert/Home etc., together with PrScrn and ScrollLock. It is not present on every keyboard, especially laptops...
Collapse


 
Patricia Rosas
Patricia Rosas  Identity Verified
United States
Local time: 15:54
Spanish to English
+ ...
TOPIC STARTER
In memoriam
so strange Jul 31, 2009

Jabberwock wrote:

Yes, the commented line should be green, I do not know why yours is not... Are you sure it is a simple (straight) apostrophe?


It was green after I saved it, but I didn't notice.

I used the organizer to erase the earlier module and then created a new one into which I pasted your code. When I first ran it, it said there was a compiler error and these lines are now RED:

speech.Speak Selection.Text, _

and

speech.Speak ActiveDocument.Range(0, ActiveDocument.Characters.Count).Text, _

Next, I put the cursor at the first line (Dim) and it jumps to the last end sub and says
"Only comments can appear after end sub, end function, or end property."

I am on a terrible deadline, but after Monday, I'll study up on how to use VB and then I'll come back and let you know if I've had any luck.

Thanks for your persistence and patience!


 
Daniel Grau
Daniel Grau  Identity Verified
Argentina
Member (2008)
English to Spanish
It seems two constants are not being defined Jul 31, 2009

The code sample I mentioned before defines two additional constants at the top of the subroutines (the "Declaration" section). If you don't define SVSFlagsAsync and SVSFPurgeBeforeSpeak as constants, they are considered to be variables with an initial value of zero/null, so the values passed to the "speech" command are zero.

Try this:

Dim speech as SpVoice 'Don't overlook this line!
Const SVSFlagsAsync = 1
Const SVSFPurgeBeforeSpeak = 2

Sub
... See more
The code sample I mentioned before defines two additional constants at the top of the subroutines (the "Declaration" section). If you don't define SVSFlagsAsync and SVSFPurgeBeforeSpeak as constants, they are considered to be variables with an initial value of zero/null, so the values passed to the "speech" command are zero.

Try this:

Dim speech as SpVoice 'Don't overlook this line!
Const SVSFlagsAsync = 1
Const SVSFPurgeBeforeSpeak = 2

Sub SpeakText()
'Based on a macro by Mathew Heikkila
'
On Error Resume Next
Set speech = New SpVoice
If Len(Selection.Text) > 1 Then 'speak selection
speech.Speak Selection.Text, _
SVSFlagsAsync + SVSFPurgeBeforeSpeak
Else 'speak whole document
speech.Speak ActiveDocument.Range(0, ActiveDocument.Characters.Count).Text, _
SVSFlagsAsync + SVSFPurgeBeforeSpeak
End If
Do
DoEvents
Loop Until speech.WaitUntilDone(10)
Set speech = Nothing
End Sub

Sub StopSpeaking()
'Based on a macro by Mathew Heikkila
'used to interrupt any running speech to text
On Error Resume Next
speech.Speak vbNullString, SVSFPurgeBeforeSpeak
Set speech = Nothing
End Sub

The errors you were getting for the two lines ending in "_" are probably due to their being followed by a blank line, as "_" is the "line continuation" character. Thus, the truncated line has a blank continuation and generates an error. Make sure the only blank lines above are those preceding the "Sub" statements.

Daniel
Collapse


 
Patricia Rosas
Patricia Rosas  Identity Verified
United States
Local time: 15:54
Spanish to English
+ ...
TOPIC STARTER
In memoriam
Thanks, but it still doesn't work ... Jul 31, 2009

Daniel,

I appreciate your help, but I cut and pasted your code in and still won't stop speaking. I must be doing something stupid. The speaking routine works perfectly. I'll try to figure this out once my Monday deadline is behind me.

But any further suggestions from anyone will be greatly appreciated!

Patricia


 
Vito Smolej
Vito Smolej
Germany
Local time: 00:54
Member (2004)
English to Slovenian
+ ...
SITE LOCALIZER
the two constants ... Aug 1, 2009

Daniel Grau wrote:

The code sample I mentioned before defines two additional constants at the top of the subroutines (the "Declaration" section). If you don't define SVSFlagsAsync and SVSFPurgeBeforeSpeak as constants ...


are defined in the sapilib.dll dcom library, so including sapi defines them anyhow (*)

So ... what happens in StopSpeaking, if On Error Resume Next is commented out - like this

' On Error Resume Next


?

Regards

Vito


*: a line at the top, stating Option explicit would detect the "undefined" status by itself.


 
Pages in topic:   < [1 2]


To report site rules violations or get help, contact a site moderator:


You can also contact site staff by submitting a support request »

Visual Basic Macro: Can someone debug it?






Trados Studio 2022 Freelance
The leading translation software used by over 270,000 translators.

Designed with your feedback in mind, Trados Studio 2022 delivers an unrivalled, powerful desktop and cloud solution, empowering you to work in the most efficient and cost-effective way.

More info »
CafeTran Espresso
You've never met a CAT tool this clever!

Translate faster & easier, using a sophisticated CAT tool built by a translator / developer. Accept jobs from clients who use Trados, MemoQ, Wordfast & major CAT tools. Download and start using CafeTran Espresso -- for free

Buy now! »



Forums
  • All of ProZ.com
  • Term search
  • Jobs
  • Forums
  • Multiple search