VBA/Excel/Access/Word/Language Basics/Compiler Directive — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 12:46, 26 мая 2010
Содержание
Use #Const to define the constant
#Const UseEventLog = True
Private Sub DebugPrint(ByVal Source As String, ByVal Message As String)
#If UseEventLog Then
Call EventLog.WriteEntry("Source: " & Source & " Message: " & Message)
#Else
Debug.Print "Source: " & Source & " Message: " & Message
#End If
End Sub
Use #If
#Const Debugging = True
Public Sub Trap(ByVal Source As String, ByVal Message As String)
#If Debugging Then
Call DebugPrint(Source, Message)
Stop
#End If
End Sub
Use string text value as the compiler directive
#Const Language = "Spanish"
Sub cmdConditionalCompilation_Click()
#If Language = "Spanish" Then
msgBox "Hola, Que Tal?"
#Else
msgBox "Hello, How Are You?"
#End If
End Sub
With the compiler directive
#Const Language = 1
Sub ConditionalIf()
#If Language = 1 Then
msgBox "Hola, Que Tal?"
#Else
msgBox "Hello, How Are You?"
#End If
End Sub