How to infer debug information from Alternates Panel output in WSR - debugging

I have this Windows Speech Recognition (WSRMacro) script which compounds multiple words that are spoken into a single word:
"Happy children"
-> "Happychildren"
However, a bug in the script appears under certain circumstances and I do not know how to deduce what the problem is. Although the above example works, the following does not:
"Happy children bake a cake"
Instead of compounding the words as above, the Alternates Panel appears with the following prompt:
-> Alternates Panel (Say the number next to the item you want followed by OK):
(1) Replace that withhappychildrenbakeacake
(2) replace that withhappychildrenbakeacake
(3) replace that with no space happy no space
children no space bake no space a no space cake
Can I infer any particular bug in the script below from the Alternates Panel output above?
Or is there anything I can add to the script to get more useful feedback about the nature of the bug?
<command priority="5">
<listenFor>compound that</listenFor>
<emulateRecognition>select that</emulateRecognition>
<sendKeys>{250 WAIT}{{CTRL}}c{250 WAIT}</sendKeys>
<script language="VBScript">
<![CDATA[
that = Application.clipboardData.GetData("text")
Set regEx = New RegExp
regEx.Pattern = "[^\s\w,;:]"
If regEx.Test(that) Then
Application.SetTextFeedback("Try again without any punctuation selected")
Else
regEx.Pattern = "(\s) *(\S)"
regEx.Global = True
that = regEx.Replace(" " & that, "$1no space $2")
On Error Resume Next
Application.EmulateRecognition("replace that with" & that)
If 0 <> Err.Number Then
Application.SetTextFeedback("Try again with only the digits selected")
End If
End If
]]>
</script>
</command>

Sounds like you're trying to use this in an application that doesn't natively support Text Services Framework.
More seriously, why aren't you using the builtin commands 'Remove spaces from that' or 'concatenate that'?

Related

Can I open a word document and execute find operation using a script?

Can I do this operation in any command line or any scripting language ?
I have a string and I want to search for it in word document exactly as a user would do it.
Steps:
1- I want to open the document.
2- select the text that matches the string I have.
You can do this with AutoHotkey or the closed-source but free AutoIt. Both of them can emulate user input and interact with the operating system through special scripting languages.
If you use one of the recent versions of Microsoft Word, this page could help you. It features a short example of how to control Microsoft Word's main interface with AutoHotkey. You'd just have to add some code to press Ctrl-F, input your search string and press the find button.
Alternatively, Ekkehard's links could also be useful if you prefer to directly use Word's macro functionality.
Yep, easy in autoit. This will search & highlight the word "three":
#include <Word.au3>
$oWordApp = _WordCreate(#ScriptDir & "\blah.doc")
$oDoc = _WordDocGetCollection($oWordApp, 0)
$FindText = "three"
With $oWordApp.Selection.Find
.Forward = True
.ClearFormatting
.Wrap = 1 ;.Wrap could be $wdFindContinue which is 1
.Execute($FindText)
EndWith

VBScript: Appending a word to the MS "Word" 2003 document

Here is a short code that opens my "fox.doc" :
Set wd = CreateObject("Word.Application")
wd.Visible = True
Set doc = wd.Documents.Open("c:\fox.doc")
I need to add only one word "bottle" in the end of this document (after it has been opened). Which lines should I add to my small vbs script for that?
You can learn a lot by recording macros in Word and then making the, usually small, changes that will make the code work in VBScript.
Set r = doc.Words.Last
r.InsertAfter (" bottle")

RS232c VB6 help

Hey all, i am trying to turn on a A/V Reciever with a RS232 command using the VB6 comm32. To turn it on it says to use:
Command code Parameter code CR Code set example
PW ON <CR> PWON<CR>
And this is my VB6 code i am currently using that doesnt seem to work...
MSComm.CommPort = 2
MSComm.Settings = "9600,n,8,1"
MSComm.PortOpen = True
If Not MSComm.PortOpen Then
MsgBox "not opened"
Else
MSComm.Output = "PWON" & Chr(13)
Do While MSComm.InBufferCount > 0
Text1.Text = Text1.Text & MSComm.Input
Loop
End If
The reciever never turns on. What could i be doing incorrectly? I checked to make sure the com port was 2 and it is.
David
You are just sending the characters <CR> rather than a real carriage return (ASCII code 13). Documentation for serial peripherals often puts the names of control characters in brackets (see Wikipedia for a list of them). You need the line:
MSComm.Output = "PWON" & Chr(13)
It also seems that the code that follows to read data from the serial port should be changed because if the data has not arrived in the serial port's buffer yet, it will read nothing. Take a look at Microsoft's example for how to do so. You could decide to stop reading once a particular substring in the input has been found, once a certain number of bytes have been read (Len function), etc.

Reformatting text (or, better, LaTeX) in 80 colums in SciTE

I recently dived into LaTeX, starting with the help of a WYSIWYM editor like Lix. Now I'm staring writing tex files in Sci-TE, It already has syntax higlighting and I adapted the tex.properties file to work in Windows showing a preview on Go [F5]
One pretty thing Lyx does, and it's hard to acheive with a common text editor, is to format text in 80 columns: I can write a paragraph and hit Return each time I reach near the edge column but if, after the first draft, I want to add or cut some words here and there I end up breaking the layout and having to rearrange newlines.
It would be useful to have a tool in Sci-TE so I can select a paragraph of text I added or deleted some words in and have it rearranged in 80 columns. Probably not something working on the whole document since it could probably break some intended anticipated line break.
Probably I could easily write a Python plugin for geany, I saw vim has something similar, but I'd like to know if its' possible in Sci-TE too.
I was a bit disappointed when I found no answer as I was searching for same. No helpers by Google either, so I searched for Lua examples and syntax in a hope to craft it myself. I don't know Lua so this can perhaps be made differently or efficiently but its better then nothing I hope - here is Lua function which needs to be put in SciTE start-up Lua script:
function wrap_text()
local border = 80
local t = {}
local pos = editor.SelectionStart
local sel = editor:GetSelText()
if #sel == 0 then return end
local para = {}
local function helper(line) table.insert(para, line) return "" end
helper((sel:gsub("(.-)\r?\n", helper)))
for k, v in pairs(para) do
line = ""
for token in string.gmatch(v, "[^%s]+") do
if string.len(token .. line) >= border then
t[#t + 1] = line
line = token .. " "
else
line = line .. token .. " "
end
end
t[#t + 1] = line:gsub("%s$", "")
end
editor:ReplaceSel(table.concat(t, "\n"))
editor:GotoPos(pos)
end
Usage is like any other function from start-up script, but for completness I'll paste my tool definition from SciTE properties file:
command.name.8.*=Wrap Text
command.mode.8.*=subsystem:lua,savebefore:no,groupundo
command.8.*=wrap_text
command.replace.selection.8.*=2
It does respect paragraphs, so it can be used on broader selection, not just one paragraph.
This is one way to do it in scite: first, add this to your .SciTEUser.properties (Options/Open User Options file):
# Column guide, indicates long lines (https://wiki.archlinux.org/index.php/SciTE)
# this is what they call "margin line" in gedit (at right),
# in scite, "margin" is the area on left for line numbers
edge.mode=1
edge.column=80
... and save, so you can see a line at 80 characters.
Then scale the scite window, so the text you see is wrapped at the line.
Finally, select the long line text which is to be broken into lines, and do Edit / Paragraph / Split (for me the shortcut Ctrl-K also works for that).
Unfortunately, there seems to be no "break-lines-as-you-type" facility in scite, like the "Line Breaking" facility in geany. not anymore, now there's a plugin - see this answer
Well, I was rather disappointed that there seems to be no "break-lines-as-you-type" facility in scite; and I finally managed to code a small Lua plugin/add-on/extension for that, and released it here:
lua-users wiki: Scite Line Break
Installation and usage instructions are in the script itself. Here is how SciTE may look when the extension properly installed, and toggle activated after startup:
Note that it's pretty much the same functionality as in geany - it inserts linebreaks upon typing text - but not on pressing backspace, nor upon copy/pasting.
the same but more easy, I think...
put this in the user properties:
command.name.0.*=swrap
command.0.*=fold -s $(FileNameExt) > /tmp/scite_temp ; cat /tmp/scite_temp >$(FileNameExt)
command.is.filter.0.*=1
Ciao
Pietro

VB6 control iteration: one control gives me an error; which one?

I am trying to loop through all controls in a form:
For Each ctrl in Me.Controls
in order enable/disable the control based on some conditions.
But there is a control on the form that gives an error when I try to access it. What kind of control does that, and how do I find it?
When you get your error and click Debug, is the error on the line setting a control's Enabled property?
If so, add a Debug.Print statement writing out the control's name. Do so on the line before setting the Enabled property.
Here's what I mean:
Dim ctrl As Control
For Each ctrl In Me.Controls
Debug.Print ctrl.Name
ctrl.Enabled = True
Next
The Debug.Print statement will write out to the Immediate Window the name of the control that was last processed in the loop, presumably the one that caused your error.
EDIT
This might work. Put this control in a Panel control and set the Panel's Enabled property to False. If I recall correctly, in VB6 setting a container control's Enabled property to False will also set the container's child controls Enabled to False. If your control's Enabled property really is read-only, I'm curious what would happen.
Try this:
Dim ctr As Control
Dim CtrStatus Boolean
CtrStatus = False
For Each ctr In Me.Controls
If (SSTab.hwnd = GetParent(ctr.hwnd)) Then
Call CallByName(ctr, "Enabled", VbLet, CtrStatus)
else
ctr.Enabled = CtrStatus
End If
Next
Another approach is as follows, that also works at runtime (as opposed to just in the IDE):
private sub SetEnabled()
on error goto errHandle
Dim ctrl As Control
For Each ctrl In Me.Controls
ctrl.Enabled = True
Next
exitPoint:
exit sub
errHandle:
MsgBox "Error " & err.Description & " with Control " & ctrl.Name
resume exitPoint
end sub
Suppress the error reports before the loop and then set it back to standard error handling:
On Error Resume Next
For Each ctrl In Me.Controls
ctrl.Enabled = lIsEnabled
Next
On Error GoTo 0
OR name your controls with a standard prefix/suffix that you can check by name and skip in the loop.
For Each ctrl In Me.Controls
If Left(ctrl.Name, 3) = "sst" Then
ctrl.Enabled = lIsEnabled
End If
Next
Tosa: from your comment on AngryHacker's answer, I think you are checking the container incorrectly.
Your code is like this
' BAD CODE '
If ctrl.Container = fraMovies Then
For me that gives error 450 Wrong number of arguments or invalid property assignment. Do you get the same error?
The code should use Is rather than =, like this
' GOOD CODE '
If ctrl.Container Is fraMovies Then
Explanation. You want to check whether two variables "point" to the same control. Controls are objects: you must use Is not = to check whether two object variables "point" to the same object. This is a classic pitfall in VB6.
One last word. Next time, could you try to post 10 lines or less of actual code, reproducing the error, and give the exact error number and message and the exact line on which it occurs? It really does make it much easier for us to solve your problem - I know it's work for you to shorten the code, but you'll get better answers that way.
EDIT Welcome back! :) You said some controls don't have a Container property. You could try wrapping the test in On Error Resume Next, something like this.
' GOOD CODE '
Dim bMatch As Boolean
Dim ctrl As Control
For Each ctrl In Me.Controls
bMatch = False
On Error Resume Next
bMatch = (ctrl.Container Is fraMovies)
On Error Goto 0
If bMatch Then
ctrl.Enabled = True
End If
Next
To avoid such problems follow the given rules while naming contols
When you name an element in your Visual Basic application, the first character of that name must be an alphabetic character or an underscore.
**Begin each separate word in a name with a capital letter, as in FindLastRecord and RedrawMyForm.
Begin function and method names with a verb, as in InitNameArray or CloseDialog.
Begin class, structure, module, and property names with a noun, as in EmployeeName or CarAccessory.
Begin interface names with the prefix "I", followed by a noun or a noun phrase, like IComponent, or with an adjective describing the interface's behavior, like IPersistable. Do not use the underscore, and use abbreviations sparingly, because abbreviations can cause confusion.
Begin event handler names with a noun describing the type of event followed by the "EventHandler" suffix, as in "MouseEventHandler".
In names of event argument classes, include the "EventArgs" suffix.
If an event has a concept of "before" or "after," use a suffix in present or past tense, as in "ControlAdd" or "ControlAdded".
For long or frequently used terms, use abbreviations to keep name lengths reasonable, for example, "HTML", instead of "Hypertext Markup Language". In general, variable names greater than 32 characters are difficult to read on a monitor set to a low resolution. Also, make sure your abbreviations are consistent throughout the entire application. Randomly switching in a project between "HTML" and "Hypertext Markup Language" can lead to confusion.
Avoid using names in an inner scope that are the same as names in an outer scope. Errors can result if the wrong variable is accessed. If a conflict occurs between a variable and the keyword of the same name, you must identify the keyword by preceding it with the appropriate type library. For example, if you have a variable called Date, you can use the intrinsic Date function only by calling DateTime.Date.

Resources