3

In Dragon NaturallySpeaking's advanced scripting, is there any way to define constants that would be available for all voice commands?


For example, I have two voice commands:

Sub Main
    originalClipboard = Clipboard
    Clipboard("~\cite{}")
    SendKeys "^v"
    Wait(0.3)
    SendKeys "{LEFT}"
    Clipboard(originalClipboard)
End Sub

And

Sub Main
    Clipboard("os.path.join()")
    SendKeys "^v"
    Wait(0.3)
    SendKeys "{Left}"
End Sub

I would prefer to store 0.3 in a global constant.

Franck Dernoncourt
  • 77,520
  • 72
  • 342
  • 501

1 Answers1

2

Yes, using the '#Uses directive to incorporate a global set of constants and functions into a script.

See http://www.nuance.com/products/help/dragon/dragon-for-pc/scriptref/Content/vbs/uses_comment.htm

So, for example, I have a global file that includes many constants and functions which can be used by any script that starts with:

 '#Uses "C:\Scripts\pgGlobal.bas.txt"

You can use it to define constants:

Public Const myWait = "0.3"

Here is but one function and its associated constants (but you can just literally define constants by themselves, too, as above):

Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
' Use this function to get System parameters (screen, mouse, etc.)
'
Public Const SM_CXSCREEN = 0  '  The width of the primary display monitor.
Public Const SM_CYSCREEN = 1  '  The height of the primary display monitor.
Public Const SM_XVIRTUALSCREEN = 76  '  The left side of the virtual screen.
Public Const SM_YVIRTUALSCREEN = 77  '  The top of the virtual screen.
Public Const SM_CXVIRTUALSCREEN = 78  '  The width of the virtual screen.
Public Const SM_CYVIRTUALSCREEN = 79  '  The height of the virtual screen.
Public Const SM_CMONITORS = 80  '  The number of display monitors.
'

And it gets called like so:

'#uses "C:\Scripts\pgGlobal.bas.txt"
Sub Main
    MsgBox "Primary Width: " & GetSystemMetrics(SM_CXSCREEN) & _
        " x Primary Height: " & GetSystemMetrics(SM_CYSCREEN) & vbCrLf & _
        "Number of monitors: " & GetSystemMetrics(SM_CMONITORS) & vbCrLf & _
        "Total Width: " & GetSystemMetrics(SM_CXVIRTUALSCREEN) & _
        " x Total Height: " & GetSystemMetrics(SM_CYVIRTUALSCREEN) & vbCrLf & _
        "Left Pixel: " & GetSystemMetrics(SM_XVIRTUALSCREEN) & _
        " x Top Pixel: " & GetSystemMetrics(SM_XVIRTUALSCREEN)
End Sub

to give me a message box having all those parameters.

PGilm
  • 2,262
  • 1
  • 14
  • 26