VoiceCommand




Option Explicit
'Class VoiceCommand

'Version 1.00.00

Private blnInit As Boolean 'Has object been created With Initialize Function
Private lngIndex As Long 'Index of command in voice control
'local variable(s) to hold property valu

' e(s)

Private mvarMenu As Long 'local copy
Private mvarID As Long 'local copy
Private mvarDescription As String 'local copy
Private mvarCommand As String 'local copy
Private mvarCategory As String 'local copy
Private mvarFlags As FlagValues 'local copy
Private mvarAction As String 'local copy
Private mvarVoiceControl As Vcommand 'local copy
'used for commmand flags values


Public Enum FlagValues
FlagsNotYetSet = -1
NoFlags = 0
Verify = 1
DisabledTemp = 2
DisableTemp_Verify = 3
DisablePermanently = 4
DisablePerm_Verify = 5
NoRename = 8
Verify_NoRename = 9
DisableTemp_NoRename = 10
DisableTemp_Verify_NoRename = 11
DisablePerm_NoRename = 12
DisablePerm_Verify_NoRename = 13
End Enum

'used to describe errors seen in initialization


Public Enum InitializeExitCodes
InitializedOK = -1
ErrorIDNotSet = 1
ErrorCommandNotSpecified = 2
ErrorCategoryNotDefined = 3
ErrorFlagsNotSet = 4
ErrorActionNotDefined = 5
ErrorVoiceControlNotDefined = 6
ErrorMenuNotSet = 7
ErrorUnknownError = 32767
End Enum

'flags for the EnableItem command


Private Enum EnableItemFlag
ByPosition = 1
ByID = 2
End Enum

Private Function FindCommand() As Long
Dim lngTemp As Long
Dim Command As String
Dim Description As String
Dim Category As String
Dim Flags As FlagValues
Dim Action As String
If blnInit = False Then
FindCommand = 0
Exit Function
End If
For lngTemp = 1 To VoiceControl.CountCommands(mvarMenu)
VoiceControl.GetCommand mvarMenu, lngTemp, Command, _
Description, Category, Flags, Action
If Command = mvarCommand Then
FindCommand = lngTemp
Exit Function
End If
Next lngTemp
End Function

Public Function Enable() As Boolean
Select Case mvarFlags
Case FlagValues.DisablePermanently, FlagValues.DisabledTemp
mvarFlags = NoFlags
Case FlagValues.DisablePerm_NoRename, FlagValues.DisableTemp_NoRename
mvarFlags = NoRename
Case FlagValues.DisablePerm_Verify, FlagValues.DisableTemp_Verify
mvarFlags = Verify
Case FlagValues.DisablePerm_Verify_NoRename, FlagValues.DisableTemp_Verify_NoRename
mvarFlags = Verify_NoRename
Case Else
Enable = True
Exit Function
End Select
Enable = SetCommand()
End Function

Private Function SetCommand() As Boolean
'used to set attributes in a command aft

' er the command has already been initiali

' zed

Dim Temp As InitializeExitCodes

If blnInit = False Then
SetCommand = False
Exit Function
End If
'could change this to trap for uninitial

' ized lngIndex (=-1)

'but this is a safety net for a changing

' index

'although that should never happen (don'

' t laugh pat)

lngIndex = FindCommand()
mvarVoiceControl.SetCommand mvarMenu, lngIndex, _
mvarID, mvarCommand, mvarDescription, mvarCategory, _
mvarFlags, mvarAction
SetCommand = True
End Function


Public Function Disable(Optional Temporary As Boolean = True) As Boolean

If Temporary = True Then

Select Case mvarFlags
Case FlagValues.FlagsNotYetSet, FlagValues.NoFlags
mvarFlags = DisabledTemp
Case FlagValues.NoRename
mvarFlags = DisableTemp_NoRename
Case FlagValues.Verify
mvarFlags = DisableTemp_Verify
Case FlagValues.Verify_NoRename
mvarFlags = DisableTemp_Verify_NoRename
Case Else
Disable = True
Exit Function
End Select
Else

Select Case mvarFlags
Case FlagValues.FlagsNotYetSet, FlagValues.NoFlags
mvarFlags = DisablePermanently
Case FlagValues.NoRename
mvarFlags = DisablePerm_NoRename
Case FlagValues.Verify
mvarFlags = DisablePerm_Verify
Case FlagValues.Verify_NoRename
mvarFlags = DisablePerm_Verify_NoRename
Case Else
Disable = True
Exit Function
End Select
End If
Disable = SetCommand()
End Function

Public Function Initialize() As InitializeExitCodes
Dim blnTemp As Boolean
Dim lngTemp As Long

If mvarCommand = "" Then
Initialize = ErrorCommandNotSpecified
Exit Function
End If

If mvarID = -1 Then
Initialize = ErrorIDNotSet
Exit Function
End If

If mvarMenu = -1 Then
Initialize = ErrorMenuNotSet
Exit Function
End If

If mvarFlags = FlagsNotYetSet Then
Initialize = ErrorFlagsNotSet
Exit Function
End If

If mvarAction = "" Then
Initialize = ErrorActionNotDefined
Exit Function
End If

If mvarCategory = "" Then
Initialize = ErrorCategoryNotDefined
Exit Function
End If

If mvarVoiceControl Is Nothing Then
Initialize = ErrorVoiceControlNotDefined
Exit Function
End If
mvarVoiceControl.AddCommand mvarMenu, mvarID, mvarCommand, mvarDescription, mvarCategory, mvarFlags, mvarAction
blnInit = True
Initialize = InitializedOK
End Function

Public Function DeleteCommand() As Boolean
Dim blnTemp As Boolean

If blnInit = False Then
DeleteCommand = True
Exit Function
End If
blnTemp = VoiceControl.Initialized

If blnTemp = True Then
VoiceControl.Deactivate mvarMenu
lngIndex = FindCommand
VoiceControl.Remove mvarMenu, lngIndex
DeleteCommand = True
End If
End Function

Public Property Set VoiceControl(ControlObject As Vcommand)

If mvarVoiceControl Is Nothing Then
Else
If ControlObject <> mvarVoiceControl Then
DeleteCommand
End If
End If
Set mvarVoiceControl = ControlObject
End Property

Public Property Get VoiceControl() As Vcommand
Set VoiceControl = mvarVoiceControl
End Property


Public Property Let Action(ByVal vData As String)
'used when assigning a value to the prop

' erty, on the left side of an assignment.

'

'Syntax: X.Action = 5

mvarAction = vData
SetCommand
End Property

Public Property Get Action() As String
'used when retrieving value of a propert

' y, on the right side of an assignment.

'Syntax: Debug.Print X.Action

Action = mvarAction
End Property

Public Property Let Flags(ByVal vData As FlagValues)
'used when assigning a value to the prop

' erty, on the left side of an assignment.

'

'Syntax: X.Flags = 5

mvarFlags = vData
SetCommand
End Property

Public Property Get Flags() As FlagValues
'used when retrieving value of a propert

' y, on the right side of an assignment.

'Syntax: Debug.Print X.Flags

Flags = mvarFlags
End Property

Public Property Let Category(ByVal vData As String)
'used when assigning a value to the prop

' erty, on the left side of an assignment.

'

'Syntax: X.Category = 5

mvarCategory = vData
SetCommand
End Property

Public Property Get Category() As String
'used when retrieving value of a propert

' y, on the right side of an assignment.

'Syntax: Debug.Print X.Category

Category = mvarCategory
End Property

Public Property Let Command(ByVal vData As String)
'used when assigning a value to the prop

' erty, on the left side of an assignment.

'

'Syntax: X.Command = 5

mvarCommand = vData
SetCommand
End Property

Public Property Get Command() As String
'used when retrieving value of a propert

' y, on the right side of an assignment.

'Syntax: Debug.Print X.Command

Command = mvarCommand
End Property

Public Property Let Description(ByVal vData As String)
'used when assigning a value to the prop

' erty, on the left side of an assignment.

'

'Syntax: X.Description = 5

mvarDescription = vData
SetCommand
End Property

Public Property Get Description() As String
'used when retrieving value of a propert

' y, on the right side of an assignment.

'Syntax: Debug.Print X.Description

Description = mvarDescription
End Property

Public Property Let ID(ByVal vData As Long)
'used when assigning a value to the prop

' erty, on the left side of an assignment.

'

'Syntax: X.ID = 5

mvarID = vData
SetCommand
End Property

Public Property Get ID() As Long
'used when retrieving value of a propert

' y, on the right side of an assignment.

'Syntax: Debug.Print X.ID

ID = mvarID
End Property

Public Property Let Menu(ByVal vData As Long)
'used when assigning a value to the prop

' erty, on the left side of an assignment.

'

'Syntax: X.Menu = 5

mvarMenu = vData
SetCommand
End Property

Public Property Get Menu() As Long
'used when retrieving value of a propert

' y, on the right side of an assignment.

'Syntax: Debug.Print X.Menu

Menu = mvarMenu
End Property

Private Sub Class_Initialize()
mvarMenu = -1
mvarID = -1
mvarFlags = FlagsNotYetSet
blnInit = False
Set mvarVoiceControl = Nothing
lngIndex = -1
End Sub

Private Sub Class_Terminate()
Set mvarVoiceControl = Nothing
End Sub










( voicecommand.html )- by Paolo Puglisi - Modifica del 17/12/2023