P
Paolo
From a newbie,
As I understand it having public constants or variables is not a good
idea. So I coded a function instead -- I have a set of hexadecimals
for use in an API function. Instead of using the hexadecimal value in
my calling function, I use a more understandable string to refer to
them. My code is below. Note I could have used a public constant to
refer to the hexadecimal value, but I used a function instead. Is
there a better way other than using a public constant or my not so
elegant solution below? Any criticism regarding the code are gladly
accepted, as I said I am just starting out!
Thanks in advance,
Paolo
E-mail address is not checked. Send e-mail to
(e-mail address removed), eliminating the NOSPAM.
Public Declare Function MessageBeep _
Lib "user32" (ByVal wType As Long) As Long
Public Function DeclareHex(MB As String) As Long
On Error GoTo ErrHandler
Select Case MB
Case IconAsterisk, IconInformation
DeclareHex = &H40&
Case IconExclamation
DeclareHex = &H30&
Case IconQuersion
DeclareHex = &H20&
Case IconHand
DeclareHex = &H20&
Case Default
DeclareHex = &HFF
Case MotherboardSpeaker
DeclareHex = &HFFFFFF
End Select
End Function
Private Sub ElementID_KeyPress(KeyAscii As Integer)
On Error GoTo ErrHandler
Call MessageBeep(DeclareHex(Default))
Exit_ElementID_KeyPress:
Exit Sub
ErrHandler:
MsgBox "ElementID_KeyPress(KeyAscii As Integer)." & vbCrLf & vbCrLf
& _
"Error #" & Err.Number & vbCrLf & vbCrLf & Err.Description
Err.Clear
Resume Exit_ElementID_KeyPress
End Sub
As I understand it having public constants or variables is not a good
idea. So I coded a function instead -- I have a set of hexadecimals
for use in an API function. Instead of using the hexadecimal value in
my calling function, I use a more understandable string to refer to
them. My code is below. Note I could have used a public constant to
refer to the hexadecimal value, but I used a function instead. Is
there a better way other than using a public constant or my not so
elegant solution below? Any criticism regarding the code are gladly
accepted, as I said I am just starting out!
Thanks in advance,
Paolo
E-mail address is not checked. Send e-mail to
(e-mail address removed), eliminating the NOSPAM.
Public Declare Function MessageBeep _
Lib "user32" (ByVal wType As Long) As Long
Public Function DeclareHex(MB As String) As Long
On Error GoTo ErrHandler
Select Case MB
Case IconAsterisk, IconInformation
DeclareHex = &H40&
Case IconExclamation
DeclareHex = &H30&
Case IconQuersion
DeclareHex = &H20&
Case IconHand
DeclareHex = &H20&
Case Default
DeclareHex = &HFF
Case MotherboardSpeaker
DeclareHex = &HFFFFFF
End Select
End Function
Private Sub ElementID_KeyPress(KeyAscii As Integer)
On Error GoTo ErrHandler
Call MessageBeep(DeclareHex(Default))
Exit_ElementID_KeyPress:
Exit Sub
ErrHandler:
MsgBox "ElementID_KeyPress(KeyAscii As Integer)." & vbCrLf & vbCrLf
& _
"Error #" & Err.Number & vbCrLf & vbCrLf & Err.Description
Err.Clear
Resume Exit_ElementID_KeyPress
End Sub