@@ -33,6 +33,8 @@ Private Const BEG_FOR = "For "
33
33
Private Const END_FOR = "Next "
34
34
Private Const BEG_DOWHILE = "Do While "
35
35
Private Const BEG_DOUNTIL = "Do Until "
36
+ Private Const BEG_WHILE = "While "
37
+ Private Const END_WHILE = "Wend"
36
38
37
39
Private Const BEG_TYPE = "Type "
38
40
Private Const END_TYPE = "End Type"
@@ -41,11 +43,14 @@ Private Const BEG_PV_TYPE = "Private Type "
41
43
42
44
' Single words that need to be handled separately
43
45
Private Const ONEWORD_END_FOR = "Next"
46
+ Private Const ONEWORD_DO = "Do"
44
47
Private Const ONEWORD_END_LOOP = "Loop"
45
48
Private Const ONEWORD_ELSE = "Else"
46
49
Private Const BEG_END_ELSEIF = "ElseIf"
47
50
Private Const BEG_END_CASE = "Case "
48
51
52
+ Private Const THEN_KEYWORD = "Then"
53
+ Private Const LINE_CONTINUATION = "_"
49
54
50
55
Private Const INDENT = " "
51
56
@@ -93,7 +98,8 @@ Private Sub initializeWords()
93
98
94
99
w.Add BEG_IF, 1
95
100
w.Add END_IF, -1
96
- w.Add BEG_SELECT, 2 'because any following 'Case' indents to the left
101
+ 'because any following 'Case' indents to the left we jump two
102
+ w.Add BEG_SELECT, 2
97
103
w.Add END_SELECT, -2
98
104
w.Add BEG_WITH, 1
99
105
w.Add END_WITH, -1
@@ -102,6 +108,8 @@ Private Sub initializeWords()
102
108
w.Add END_FOR, -1
103
109
w.Add BEG_DOWHILE, 1
104
110
w.Add BEG_DOUNTIL, 1
111
+ w.Add BEG_WHILE, 1
112
+ w.Add END_WHILE, -1
105
113
106
114
w.Add BEG_TYPE, 1
107
115
w.Add END_TYPE, -1
@@ -170,11 +178,16 @@ Public Sub formatCode(codePane As codeModule)
170
178
If isEqual(ONEWORD_ELSE, line) _
171
179
Or lineStartsWith(BEG_END_ELSEIF, line) _
172
180
Or lineStartsWith(BEG_END_CASE, line) Then
181
+ ' Case, Else, ElseIf need to jump to the left
173
182
levelChange = 1
174
183
indentLevel = -1 + indentLevel
175
184
ElseIf isLabel(line) Then
185
+ ' Labels don't have indentation
176
186
levelChange = indentLevel
177
187
indentLevel = 0
188
+ ' check for oneline If statemts
189
+ ElseIf isOneLineIfStatemt(line) Then
190
+ levelChange = 0
178
191
Else
179
192
levelChange = indentChange(line)
180
193
End If
@@ -221,6 +234,10 @@ Private Function indentChange(ByVal line As String) As Integer
221
234
indentChange = -1
222
235
GoTo hell
223
236
End If
237
+ If isEqual(ONEWORD_DO, line) Then
238
+ indentChange = 1
239
+ GoTo hell
240
+ End If
224
241
Dim word As String
225
242
Dim vord As Variant
226
243
For Each vord In w.Keys
@@ -249,7 +266,23 @@ Private Function lineStartsWith(begin As String, strToCheck As String) As Boolea
249
266
End Function
250
267
251
268
252
- Public Function isLabel (line As String ) As Boolean
269
+ ' Returns True if strToCheck ends with ending, ignoring case
270
+ Private Function lineEndsWith (ending As String , strToCheck As String ) As Boolean
271
+ lineEndsWith = False
272
+ Dim length As Integer
273
+ length = Len(ending)
274
+ If Len(strToCheck) >= length Then
275
+ lineEndsWith = isEqual(ending, right(strToCheck, length))
276
+ End If
277
+ End Function
278
+
279
+
280
+ Private Function isLabel (line As String ) As Boolean
253
281
'it must end with a colon: and may not contain a space.
254
282
isLabel = (right(line, 1 ) = ":" ) And (InStr(line, " " ) < 1 )
255
283
End Function
284
+
285
+
286
+ Private Function isOneLineIfStatemt (line As String ) As Boolean
287
+ isOneLineIfStatemt = (lineStartsWith(BEG_IF, line) And (Not lineEndsWith(THEN_KEYWORD, line)) And Not lineEndsWith(LINE_CONTINUATION, line))
288
+ End Function
0 commit comments