-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathXdebug.cls
275 lines (201 loc) · 6.38 KB
/
Xdebug.cls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "Xdebug"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'namespace=xvba_modules\Xdebug
'Flag for debug check if the app is in Dev Or Build
Public env As String
'Count off Debug printed
Private printDebugCount As Integer
Private OS_TMP__FOLDER_PATH As String
Private IMMEDIATE_FOLDER As String
Private IMMEDIATE_FILE As String
Private DEBUG_FILE_PATH As String
Const EMPTY_TYPE = 0
Const NULL_TYPE = 1
Const ERROR_TYPE = 10
Const INTEGER_TYPE = 2
Const LONG_TYPE = 3
Const SINGLE_TYPE = 4
Const DOUBLE_TYPE = 5
Const CURRENCY_TYPE = 6
Const DATE_TYPE = 7
Const DECIMAL_TYPE = 14
Const LONG_LONG_TYPE = 20
Const BOOLEAN_TYPE = 11
Const STRING_TYPE = 8
Const ARRAY_TYPE = 8204
Const OBJECT_TYPE = 9
Const VARIANT_TYPE = 12
Const DATA_OBJECT_TYPE = 13
Private Const MESSAGE_SPACE = " "
Public errorSource As String
Public errorTitle As String
'/*
'Flag for Actrive os Deactive VBA Debug.Print
'*/
Public vbaDebugPrintActive As Boolean
Private Sub class_initialize()
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
OS_TMP__FOLDER_PATH = fso.GetSpecialFolder(2)
IMMEDIATE_FOLDER = "xvba_immediate"
IMMEDIATE_FILE = "immediate.txt"
vbaDebugPrintActive = True
errorSource = ""
printDebugCount = 0
errorTitle = "XVBA: New Error Was Found"
env = "DEV"
DEBUG_FILE_PATH = OS_TMP__FOLDER_PATH & "\" & IMMEDIATE_FOLDER & "\" & IMMEDIATE_FILE
End Sub
Public Function printx(inputValue As Variant,Optional messageType As Integer = 1)
if(env="DEV") Then
Dim messageText As String
messageText = createOutputMessage(inputValue)
Call writeDebugFileContent(messageText,messageType)
End If
End Function
Public Function printError()
if(env="DEV") Then
Dim message As String
message = ErrorHanddler()
Call writeDebugFileContent(message,0)
End If
End Function
'/*
'
'Print The Error And Raise New
'This Print error is used for children functions and Subs
'Is used for functions that was called from other subs os functions
'
'*/
Public Function printErrorAndRaise()
if(env="DEV") Then
Dim oldErrorTitle As String
'Get last Error Title
oldErrorTitle = errorTitle
'Create New Error Title
errorTitle = "XVBA: New Error Was Found >>> Raised <<<"
'Get Error Message
Dim message As String
message = ErrorHanddler()
'Reset the Error Title to the oldest
errorTitle = oldErrorTitle
Call writeDebugFileContent(message,0)
Err.Raise Err.Number
End If
End Function
'/*
'
'Write Debug ino on File
'
'
'*/
Private Function writeDebugFileContent(messageText,messageType)
Dim filePath As String
Dim FileNum As Integer
Dim PREFIX As String
filePath = DEBUG_FILE_PATH
FileNum = FreeFile
printDebugCount = printDebugCount + 1
PREFIX = "(" & printDebugCount & ") " & Now & " - "
Open filePath For Append As #FileNum
Dim debugMessage As String
Select Case messageType
Case 0 'Error Message
debugMessage= PREFIX & "Error:" & messageText
Case 1 'Success
debugMessage= PREFIX & messageText
Case Else 'No Type Set
debugMessage= PREFIX & "Info:" & messageText
End Select
Print #FileNum,debugMessage
Close #FileNum
If (vbaDebugPrintActive) Then
Debug.Print debugMessage
End If
End Function
Private Function createOutputMessage(inputValue) As String
Dim typeOfVar As Integer
Dim response As String
typeOfVar = VarType(inputValue)
'Set Error Source Macro/Function name
Err.Source="createOutputMessage"
Select Case typeOfVar
Case STRING_TYPE
response = "String: " & inputValue
Case INTEGER_TYPE
response = "Integer: " & CStr(inputValue)
Case LONG_TYPE
response = "Long: " & CStr(inputValue)
Case SINGLE_TYPE
response = "Single: " & CStr(inputValue)
Case DOUBLE_TYPE
response = "Double: " & CStr(inputValue)
Case CURRENCY_TYPE
response = "Currenty: " & CStr(inputValue)
Case DATE_TYPE
response = "Date: " & CStr(inputValue)
Case DECIMAL_TYPE
response = "Decimal: " & CStr(inputValue)
Case LONG_LONG_TYPE
response = "LongLong: " & CStr(inputValue)
Case BOOLEAN_TYPE
response = "Boolean: " & CStr(inputValue)
Case ARRAY_TYPE
response = makeArrayTypeMessage(inputValue)
Case EMPTY_TYPE
response = "Empty: "
Case OBJECT_TYPE
response = "Object: " & TypeName(inputValue)
Case NULL_TYPE
response = "Null: "
Case ERROR_TYPE
response = "Error: "
Case VARIANT_TYPE
response = "Variant: "
Case DATA_OBJECT_TYPE
response = "Data Object: " & TypeName(inputValue)
Case Else
response = "Type Not Supported yet please inform xvba developer "
Debug.Print typeOfVar
Debug.Print inputValue
End Select
createOutputMessage = response
End Function
Private Function makeArrayTypeMessage(inputValue)As String
Dim nextItem As Variant
Dim response As String
Dim message As String
For Each nextItem In inputValue
message = createOutputMessage(nextItem)
response = response & " [ " & message & " ]" & vbCrLf
Next nextItem
makeArrayTypeMessage = "Array: " & vbCrLf & response
End Function
Private Function ErrorHanddler() As String
Dim errorDescription As String
Dim numberDescription As String
Dim lineError As String
Dim sourceError As String
Dim errorTitleMsg As String
Dim errorSourceMsg As String
errorTitleMsg = vbCrLf & MESSAGE_SPACE & errorTitle
errorSourceMsg = vbCrLf & MESSAGE_SPACE & "Error Source: " & errorSource
Select Case Err.Number
Case 11
numberDescription = vbCrLf & MESSAGE_SPACE & "Error Number: " & Err.Number
lineError = vbCrLf & MESSAGE_SPACE & "Error Line: " & Erl
errorDescription = vbCrLf & MESSAGE_SPACE & "Error Description: " & Err.Description
Case Else
numberDescription = vbCrLf & MESSAGE_SPACE & "Error Number: " & Err.Number
lineError = vbCrLf & MESSAGE_SPACE & "Error Line: " & Erl
errorDescription = vbCrLf & MESSAGE_SPACE & "Error Description: " & Err.Description
End Select
ErrorHanddler = errorTitleMsg & lineError & errorSourceMsg & numberDescription & errorDescription
End Function