Skip to content

Commit 52552b0

Browse files
committed
VBA-Expressions v3.2.11
1 parent dbf9a9d commit 52552b0

13 files changed

+562
-50
lines changed

docs/assets/img/VBAExprManual.pdf

5.2 KB
Binary file not shown.

src/LO Basic/VBAExpressions.update.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<description xmlns="https://openoffice.org/extensions/update/2006"
33
xmlns:xlink="https://www.w3.org/1999/xlink">
44
<identifier value="com.ecpsolutions.extensions.vbaexpressions.oxt"/>
5-
<version value="1.1.1"/>
5+
<version value="1.1.2"/>
66
<update-download>
7-
<src xlink:href="https://github.com/ws-garcia/VBA-Expressions/releases/download/v3.2.10/VBAExpressions.oxt"/>
7+
<src xlink:href="https://github.com/ws-garcia/VBA-Expressions/releases/download/v3.2.11/VBAExpressions.oxt"/>
88
</update-download>
99
</description>

src/LO Basic/VBAExpressionsLib/TestRunner.xba

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Private tTotal As Long
88

99
&apos;#
1010
&apos;////////////////////////////////////////////////////////////////////////////////////////////
11-
&apos; Copyright © 2024 W. García
11+
&apos; Copyright © 2024-2025 W. García
1212
&apos; GPL-3.0 license | https://www.gnu.org/licenses/gpl-3.0.html/
1313
&apos; https://github.com/ws-garcia
1414
&apos;////////////////////////////////////////////////////////////////////////////////////////////
@@ -364,6 +364,27 @@ Sub RunAllTests
364364
&quot;INSTR(&apos;Gear&apos;;&apos;e&apos;)&quot;, _
365365
&quot;2&quot; _
366366
)
367+
&apos;Analytical Geometry
368+
Run( _
369+
&quot;Distance between two points&quot;, _
370+
&quot;ROUND(DISTANCE({{3.1441;0}};{{4.45415;3.1441}});4)&quot;, _
371+
&quot;3.4061&quot; _
372+
)
373+
Run( _
374+
&quot;Lines intersection&quot;, _
375+
&quot;MROUND(LINESINTERSECT({{12;0};{0;5}};{{0;1.31004};{0.79693;3.22267}});2)&quot;, _
376+
&quot;{{1.31;4.45}}&quot; _
377+
)
378+
Run( _
379+
&quot;Parallel line&quot;, _
380+
&quot;MROUND(PARALLEL({{12;0};{0;5}};{{3.1441;0}});2)&quot;, _
381+
&quot;{{3.14;0};{0;1.31}}&quot; _
382+
)
383+
Run( _
384+
&quot;Perpendicular line&quot;, _
385+
&quot;MROUND(PERPENDICULAR({{12;0};{0;5}};{{3.1441;0}});2)&quot;, _
386+
&quot;{{3.14;0};{4.45;3.14}}&quot; _
387+
)
367388
SF_Exception.debugprint(&quot;Passed tests:&quot;,sAcum)
368389
SF_Exception.debugprint(&quot;Failed tests:&quot;,tTotal - sAcum)
369390
SF_Exception.debugprint(&quot;Passed tests Ratio:&quot;,Round(100*sAcum/tTotal,2) &amp;&quot;%&quot;)

src/LO Basic/VBAExpressionsLib/UDFunctions.xba

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Option VBASupport 1
66
option ClassModule
77
&apos;#
88
&apos;////////////////////////////////////////////////////////////////////////////////////////////
9-
&apos; Copyright © 2024 W. García
9+
&apos; Copyright © 2024-2025 W. García
1010
&apos; GPL-3.0 license | https://www.gnu.org/licenses/gpl-3.0.html/
1111
&apos; https://github.com/ws-garcia
1212
&apos;////////////////////////////////////////////////////////////////////////////////////////////

src/LO Basic/VBAExpressionsLib/VBAcallBack.xba

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ option Compatible
55
option ClassModule
66
&apos;#
77
&apos;////////////////////////////////////////////////////////////////////////////////////////////
8-
&apos; Copyright © 2024 W. García
8+
&apos; Copyright © 2024-2025 W. García
99
&apos; GPL-3.0 license | https://www.gnu.org/licenses/gpl-3.0.html/
1010
&apos; https://github.com/ws-garcia
1111
&apos;////////////////////////////////////////////////////////////////////////////////////////////

src/LO Basic/VBAExpressionsLib/VBAexpressions.xba

Lines changed: 374 additions & 22 deletions
Large diffs are not rendered by default.

src/LO Basic/VBAExpressionsLib/VBAexpressionsScope.xba

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ option ClassModule
77
Option Base 0
88
&apos;#
99
&apos;///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
10-
&apos; Copyright © 2024 W. García
10+
&apos; Copyright © 2024-2025 W. García
1111
&apos; GPL-3.0 license | https://www.gnu.org/licenses/gpl-3.0.html/
1212
&apos; https://github.com/ws-garcia
1313
&apos;///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

src/LO Basic/VBAExpressionsLib/VBAstrHelper.xba

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ option ClassModule
77
Option Base 0
88
&apos;#
99
&apos;///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
10-
&apos; Copyright © 2024 W. García
10+
&apos; Copyright © 2024-2025 W. García
1111
&apos; GPL-3.0 license | https://www.gnu.org/licenses/gpl-3.0.html/
1212
&apos; https://github.com/ws-garcia
1313
&apos;///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

src/LO Basic/release-notes_en.txt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
# A single one
2-
## New function
3-
- [x] `INSTR`
1+
# Embracing analytic geometry basis!
2+
## Setting changes
3+
- [x] The `GallopingMode` option is disabled by default.
4+
## Bug fixed
5+
- [x] Broken tokenization for expressions involving evaluable literal strings.
6+
## New functions
7+
- [x] `DISTANCE`: computes the distance between two Cartesian points.
8+
- [x] `LINESINTERSECT`: computes the intersection point between two lines defined by two points each.
9+
- [x] `PARALLEL`: computes two points representing a line parallel to the given one and containing the given point.
10+
- [x] `PERPENDICULAR`: computes two points representing a line perpendicular to the given one and containing the given point.
411

512
## Download
6-
https://github.com/ws-garcia/VBA-Expressions/releases/download/v3.2.10/VBAExpressions.oxt
13+
https://github.com/ws-garcia/VBA-Expressions/releases/download/v3.2.11/VBAExpressions.oxt

src/UDFunctions.cls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Attribute VB_Exposed = True
1010
Option Explicit
1111
'#
1212
'////////////////////////////////////////////////////////////////////////////////////////////
13-
' Copyright © 2022-2024 W. García
13+
' Copyright © 2022-2025 W. García
1414
' GPL-3.0 license | https://www.gnu.org/licenses/gpl-3.0.html/
1515
' https://ingwilfredogarcia.wordpress.com
1616
'////////////////////////////////////////////////////////////////////////////////////////////

src/VBAcallBack.cls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Attribute VB_Exposed = True
1010
Option Explicit
1111
'#
1212
'////////////////////////////////////////////////////////////////////////////////////////////
13-
' Copyright © 2022-2024 W. García
13+
' Copyright © 2022-2025 W. García
1414
' GPL-3.0 license | https://www.gnu.org/licenses/gpl-3.0.html/
1515
' https://ingwilfredogarcia.wordpress.com
1616
'////////////////////////////////////////////////////////////////////////////////////////////

src/VBAexpressions.cls

Lines changed: 146 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Option Explicit
1212
Option Base 0
1313
'#
1414
'///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
15-
' Copyright © 2022-2024 W. García
15+
' Copyright © 2022-2025 W. García
1616
' GPL-3.0 license | https://www.gnu.org/licenses/gpl-3.0.html/
1717
' https://ingwilfredogarcia.wordpress.com
1818
'///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -312,7 +312,7 @@ Private Sub Class_Initialize()
312312
P_SEPARATORCHAR = d_Semicolon
313313
P_DEC_SYMBOL = dsDot
314314
AscDecSymbol = 46
315-
P_GALLOPING_MODE = True
315+
P_GALLOPING_MODE = False
316316
P_FORMATRESULT = False
317317
BuildinFunctIDList = "abs;floor;achisq;asin;acos;aerf;afishf;agauss;asc;anorm;atn;astudt;array;avg;beta.dist" & _
318318
";betainv;ceil;chisq;cholesky;cholinverse;cholsolve;chr;cos;choose;date;dateadd;datediff" & _
@@ -2888,10 +2888,10 @@ err_Handler:
28882888
End Function
28892889

28902890
''' <summary>
2891-
''' Returns the distance between two given points. The points
2892-
''' must be given each one in array format, ex.:
2893-
''' {{x1;y1}};{{x2;y2}}
2891+
''' Returns the distance between two given points.
28942892
''' </summary>
2893+
''' <param name="Point1">Array of coordinates in format {{x1;y1}}.</param>
2894+
''' <param name="Point2">Array of coordinates in format {{x2;y2}}.</param>
28952895
Private Function Distance(ByRef expression As String, ByRef fName As String) As String
28962896
Dim argsCount As Long
28972897
Dim tmpData() As String
@@ -3105,7 +3105,9 @@ Private Function EvalFunction(ByRef Argument As String, ByRef FunctionName As St
31053105
Case "aNow": EvalFunction = Now_(Argument, FunctionName)
31063106
Case "aNPER": EvalFunction = NPER_(Argument, FunctionName)
31073107
Case "aNPV": EvalFunction = NPV_(Argument, FunctionName)
3108+
Case "ParallelLine": EvalFunction = ParallelLine(Argument, FunctionName)
31083109
Case "Percent": EvalFunction = Percent(Argument, FunctionName)
3110+
Case "PerpendicularLine": EvalFunction = PerpendicularLine(Argument, FunctionName)
31093111
Case "aPMT": EvalFunction = PMT_(Argument, FunctionName)
31103112
Case "aPPMT": EvalFunction = PPMT_(Argument, FunctionName)
31113113
Case "Power": EvalFunction = Power(Argument, FunctionName)
@@ -3670,7 +3672,6 @@ Private Function fZeroMBM(ByRef aFunction As String, ByVal A As Double, _
36703672
aZero = 10 * epsilon
36713673
With fEvalHelper
36723674
.Create aFunction
3673-
.GallopingMode = False
36743675
tmpVar() = Split(.CurrentVariables, "; ")
36753676
varLB = LBound(tmpVar)
36763677
If UBound(tmpVar) - varLB > 0 Then 'Reject multivariate functions
@@ -3787,7 +3788,6 @@ Private Function fZeroMRF(ByRef aFunction As String, ByVal A As Double, _
37873788
Set fEvalHelper = New VBAexpressions
37883789
aZero = 10 * epsilon
37893790
With fEvalHelper
3790-
.GallopingMode = False
37913791
.Create aFunction
37923792
tmpVar() = Split(.CurrentVariables, "; ")
37933793
varLB = LBound(tmpVar)
@@ -5883,10 +5883,9 @@ End Function
58835883

58845884
''' <summary>
58855885
''' Returns the intersection point for two lines.
5886-
''' The lines must be given by two crossing points each
5887-
''' in array format, ex.:
5888-
''' {{x1;y1};{x2;y2}}; {{x3;y3};{x4;y4}}
58895886
''' </summary>
5887+
''' <param name="Line1">Array of coordinates in format {{x1;y1};{x2;y2}}.</param>
5888+
''' <param name="Line2">Array of coordinates in format {{x3;y3};{x4;y4}}.</param>
58905889
Private Function LinesIntersect(ByRef expression As String, ByRef fName As String) As String
58915890
Dim argsCount As Long
58925891
Dim tmpData() As String
@@ -5906,14 +5905,16 @@ Private Function LinesIntersect(ByRef expression As String, ByRef fName As Strin
59065905
aArray(0) = ToDblArray(ArrayFromString(tmpData(LB)))
59075906
aArray(1) = ToDblArray(ArrayFromString(tmpData(UB)))
59085907
tmpEval = LinesIntersection(aArray(0), aArray(1))
5909-
If IsArray(tmpEval) Then
5910-
tmpEval = ArrayToString(tmpEval)
5911-
End If
59125908
Case Else
59135909
tmpEval = e_ValueError
59145910
BuildErrMessage errMissingArgsOrTooManyArgs, d_lCurly & fName & d_rCurly
59155911
End Select
5916-
LinesIntersect = tmpEval: Erase tmpData
5912+
If IsArray(tmpEval) Then
5913+
LinesIntersect = ArrayToString(tmpEval)
5914+
Else
5915+
LinesIntersect = tmpEval
5916+
End If
5917+
Erase tmpData
59175918
Exit Function
59185919
err_Handler:
59195920
LinesIntersect = e_ValueError
@@ -7547,6 +7548,66 @@ Private Function PatternToCheckOn(ByRef ArgDefStr As String) As String
75477548
End If
75487549
End Function
75497550

7551+
''' <summary>
7552+
''' Returns two points representing a line parallel to the given one and
7553+
''' containing the given point.
7554+
''' </summary>
7555+
''' <param name="Line">Array of coordinates in format {{x1;y1};{x2;y2}}.</param>
7556+
''' <param name="Point">Array of coordinates in format {{x;y}}.</param>
7557+
Private Function ParallelLine(ByRef expression As String, ByRef fName As String) As String
7558+
Dim argsCount As Long
7559+
Dim tmpData() As String
7560+
Dim tmpEval As String
7561+
Dim LB As Long, UB As Long
7562+
7563+
On Error GoTo err_Handler
7564+
tmpData() = SplitArgs(expression)
7565+
LB = LBound(tmpData)
7566+
UB = UBound(tmpData)
7567+
argsCount = UB - LB + 1
7568+
Select Case argsCount
7569+
Case 2
7570+
Dim aArray() As Variant
7571+
Dim aTerm As Double
7572+
Dim bTerm As Double
7573+
Dim cTerm As Double
7574+
Dim pointArr(0 To 1) As Variant
7575+
Dim tmpArr(0 To 1) As Double
7576+
ReDim aArray(0 To 1)
7577+
7578+
aArray(0) = ToDblArray(ArrayFromString(tmpData(LB)))
7579+
aArray(1) = ToDblArray(ArrayFromString(tmpData(UB)))
7580+
aTerm = aArray(0)(0, 1) - aArray(0)(1, 1) 'y1-y2
7581+
bTerm = aArray(0)(1, 0) - aArray(0)(0, 0) 'x2-x1
7582+
cTerm = aArray(0)(0, 0) * aArray(0)(1, 1) _
7583+
- aArray(0)(1, 0) * aArray(0)(0, 1) 'x1*y2-x2*y1
7584+
pointArr(0) = aArray(1)
7585+
If aTerm <> 0 And bTerm <> 0 Then
7586+
tmpArr(0) = 0
7587+
tmpArr(1) = (aTerm * aArray(1)(0) + bTerm * aArray(1)(1)) / bTerm
7588+
Else
7589+
If aTerm = 0 Then 'Horizontal line
7590+
tmpArr(0) = aArray(1)(0) - aArray(1)(1) + 1
7591+
tmpArr(1) = aArray(1)(1)
7592+
Else 'Vertical line
7593+
tmpArr(0) = aArray(1)(0)
7594+
tmpArr(1) = aArray(1)(0) - aArray(1)(1) + 1
7595+
End If
7596+
End If
7597+
pointArr(1) = tmpArr
7598+
tmpEval = ArrayToString(pointArr)
7599+
Case Else
7600+
tmpEval = e_ValueError
7601+
BuildErrMessage errMissingArgsOrTooManyArgs, d_lCurly & fName & d_rCurly
7602+
End Select
7603+
ParallelLine = tmpEval: Erase tmpData
7604+
Exit Function
7605+
err_Handler:
7606+
ParallelLine = e_ValueError
7607+
BuildErrMessage errEvalError, d_lCurly & fName & d_rCurly & " | Error#: " & err.Number & d_Space & _
7608+
d_lParenthesis & err.Description & d_rParenthesis
7609+
End Function
7610+
75507611
Private Function Percent(ByRef expression As String, ByRef fName As String) As String
75517612
On Error GoTo err_Handler
75527613
Percent = CDbl(expression) / 100
@@ -7557,6 +7618,77 @@ err_Handler:
75577618
d_lParenthesis & err.Description & d_rParenthesis
75587619
End Function
75597620

7621+
''' <summary>
7622+
''' Returns two points representing a line perpendicular to the
7623+
''' given one and containing the given point.
7624+
''' </summary>
7625+
''' <param name="Line">Array of coordinates in format {{x1;y1};{x2;y2}}.</param>
7626+
''' <param name="Point">Array of coordinates in format {{x;y}}.</param>
7627+
Private Function PerpendicularLine(ByRef expression As String, ByRef fName As String) As String
7628+
Dim argsCount As Long
7629+
Dim tmpData() As String
7630+
Dim tmpEval As String
7631+
Dim LB As Long, UB As Long
7632+
7633+
On Error GoTo err_Handler
7634+
tmpData() = SplitArgs(expression)
7635+
LB = LBound(tmpData)
7636+
UB = UBound(tmpData)
7637+
argsCount = UB - LB + 1
7638+
Select Case argsCount
7639+
Case 2
7640+
Dim aArray() As Variant
7641+
Dim aTerm As Double
7642+
Dim bTerm As Double
7643+
Dim cTerm As Double
7644+
Dim pointArr(0 To 1) As Variant
7645+
Dim tmpArr(0 To 1) As Double
7646+
ReDim aArray(0 To 1)
7647+
7648+
aArray(0) = ToDblArray(ArrayFromString(tmpData(LB)))
7649+
aArray(1) = ToDblArray(ArrayFromString(tmpData(UB)))
7650+
aTerm = aArray(0)(0, 1) - aArray(0)(1, 1) 'y1-y2
7651+
bTerm = aArray(0)(1, 0) - aArray(0)(0, 0) 'x2-x1
7652+
cTerm = aArray(0)(0, 0) * aArray(0)(1, 1) _
7653+
- aArray(0)(1, 0) * aArray(0)(0, 1) 'x1*y2-x2*y1
7654+
pointArr(0) = aArray(1)
7655+
If aTerm <> 0 And bTerm <> 0 Then
7656+
' (-c*a+b(b*x3-a*y3))/(a^2 + b^2)
7657+
tmpArr(0) = (-cTerm * aTerm + bTerm * (bTerm * aArray(1)(0) - aTerm * aArray(1)(1))) _
7658+
/ _
7659+
(aTerm ^ 2 + bTerm ^ 2)
7660+
' (-a(b*x3-a*y3)-b*c)/(a^2 + b^2)
7661+
tmpArr(1) = (-aTerm * (bTerm * aArray(1)(0) - aTerm * aArray(1)(1)) - bTerm * cTerm) _
7662+
/ _
7663+
(aTerm ^ 2 + bTerm ^ 2)
7664+
If pointArr(0)(0) = tmpArr(0) And _
7665+
pointArr(0)(1) = tmpArr(1) Then 'Known point is the intersection
7666+
tmpArr(0) = pointArr(0)(0) + 1
7667+
tmpArr(1) = pointArr(0)(1) + bTerm / aTerm
7668+
End If
7669+
Else
7670+
If aTerm = 0 Then 'Horizontal line
7671+
tmpArr(0) = aArray(1)(0)
7672+
tmpArr(1) = aArray(1)(0) - aArray(1)(1) + 1
7673+
Else 'Vertical line
7674+
tmpArr(0) = aArray(1)(0) - aArray(1)(1) + 1
7675+
tmpArr(1) = aArray(1)(1)
7676+
End If
7677+
End If
7678+
pointArr(1) = tmpArr
7679+
tmpEval = ArrayToString(pointArr)
7680+
Case Else
7681+
tmpEval = e_ValueError
7682+
BuildErrMessage errMissingArgsOrTooManyArgs, d_lCurly & fName & d_rCurly
7683+
End Select
7684+
PerpendicularLine = tmpEval: Erase tmpData
7685+
Exit Function
7686+
err_Handler:
7687+
PerpendicularLine = e_ValueError
7688+
BuildErrMessage errEvalError, d_lCurly & fName & d_rCurly & " | Error#: " & err.Number & d_Space & _
7689+
d_lParenthesis & err.Description & d_rParenthesis
7690+
End Function
7691+
75607692
Private Function PMT_(ByRef expression As String, ByRef fName As String) As String
75617693
Dim argsCount As Long
75627694
Dim tmpData() As String

src/VBAexpressionsScope.cls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Option Explicit
1111
Option Base 0
1212
'#
1313
'///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
14-
' Copyright © 2022-2024 W. García
14+
' Copyright © 2022-2025 W. García
1515
' GPL-3.0 license | https://www.gnu.org/licenses/gpl-3.0.html/
1616
' https://ingwilfredogarcia.wordpress.com
1717
'///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)