Skip to content

Commit 1f48c36

Browse files
committed
Update VBAexpressions.cls
Implicit multiplication is allowed in expressions when parentheses are used. Examples: `(2)(3)`, `a(5)`.
1 parent c2b8b2c commit 1f48c36

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

src/VBAexpressions.cls

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,9 +1525,11 @@ Private Function FormatLiteralString(ByRef aString As String, _
15251525
End If
15261526
End Function
15271527
Private Function FormatEntry(expression As String) As String
1528-
FormatEntry = Replace(Replace(Replace(RemoveDupNegation(ApplyLawOfSigns _
1529-
(ReconstructLiteralStrings(CStr(expression), _
1530-
Join$(Split(expression, d_Space), vbNullString)))), "()", "('')"), "{{", "({{"), "}}", "}})")
1528+
FormatEntry = ReplaceImpliedMult( _
1529+
Replace(Replace(Replace(RemoveDupNegation(ApplyLawOfSigns _
1530+
(ReconstructLiteralStrings(CStr(expression), _
1531+
Join$(Split(expression, d_Space), vbNullString)))), "()", "('')"), "{{", "({{"), "}}", "}})") _
1532+
)
15311533
End Function
15321534

15331535
Private Function ToLiteralString(ByRef aString As String) As String
@@ -4219,6 +4221,29 @@ Private Function Replace_(ByRef expression As String) As String
42194221
Replace_ = tmpEval
42204222
End Function
42214223

4224+
Private Function ReplaceImpliedMult(expression As String) As String
4225+
Dim tmpPos As Long
4226+
Dim tmpStr As String
4227+
Dim LookupPos As Long
4228+
4229+
LookupPos = 1
4230+
tmpStr = expression
4231+
tmpPos = InStrB(LookupPos, tmpStr, d_lParenthesis)
4232+
Do While tmpPos
4233+
If tmpPos > 2 Then
4234+
If InStr(1, op_AllItems, MidB(tmpStr, tmpPos - 2, 2)) = 0 Then 'Implied multiplication found
4235+
tmpStr = MidB(tmpStr, 1, tmpPos - 1) & op_mult & MidB(tmpStr, tmpPos)
4236+
End If
4237+
LookupPos = tmpPos + 4
4238+
tmpPos = InStrB(LookupPos, tmpStr, d_lParenthesis)
4239+
Else
4240+
LookupPos = tmpPos + 2
4241+
tmpPos = InStrB(LookupPos, tmpStr, d_lParenthesis)
4242+
End If
4243+
Loop
4244+
ReplaceImpliedMult = tmpStr
4245+
End Function
4246+
42224247
Private Function Right_(ByRef expression As String) As String
42234248
Dim argsCount As Long
42244249
Dim tmpData() As String

0 commit comments

Comments
 (0)