├── .gitignore ├── LICENSE ├── README.md ├── docs └── assets │ └── img │ ├── Concept example.pdf │ ├── ConceptExample.png │ ├── GeoProblem.png │ ├── VBA Expressions-NewLogo.png │ ├── VBA Expressions.png │ └── VBAExprManual.pdf ├── src ├── LO Basic │ ├── VBAExpressions.update.xml │ ├── VBAExpressionsLib │ │ ├── TestRunner.xba │ │ ├── UDFunctions.xba │ │ ├── VBAcallBack.xba │ │ ├── VBAexpressions.xba │ │ ├── VBAexpressionsScope.xba │ │ ├── VBAstrHelper.xba │ │ ├── dialog.xlb │ │ └── script.xlb │ └── release-notes_en.txt ├── Tests │ └── TestRunner.bas ├── UDFunctions.cls ├── VBAcallBack.cls ├── VBAexpressions.cls └── VBAexpressionsScope.cls └── testing └── tests └── Test runner.xlsm /.gitignore: -------------------------------------------------------------------------------- 1 | *.mdk 2 | *.zip 3 | *.oxt 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # VBA Expressions 2 | ## ![VBA Expressions](/docs/assets/img/VBA%20Expressions-NewLogo.png) 3 | [![GitHub](https://img.shields.io/github/license/ws-garcia/VBA-Expressions?style=plastic)](https://github.com/ws-garcia/VBA-Expressions/blob/master/LICENSE) [![GitHub release (latest by date)](https://img.shields.io/github/v/release/ws-garcia/VBA-Expressions?style=plastic)](https://github.com/ws-garcia/VBA-Expressions/releases/latest) [![Mentioned in Awesome VBA](https://awesome.re/mentioned-badge.svg)](https://github.com/sancarn/awesome-vba) 4 | 5 | ## Introductory words 6 | Welcome to VBA Expressions, a powerful library designed to extend the capabilities of Visual Basic for Applications (VBA) within Microsoft Office and [LibreOffice environments](https://extensions.libreoffice.org/en/extensions/show/70059). This tool enriches the standard VBA language and LO BASIC with an extensive set of functions for data manipulation, calculation, and analysis, making it ideal for users needing to perform complex operations directly within their spreadsheets, documents, presentatios and much more. 7 | ## ![User Manual](/docs/assets/img/VBAExprManual.pdf) 8 | ## Key features 9 | * __Extensive Function Library__: Includes over 100 functions spanning: 10 | * Mathematical operations 11 | * Statistical analysis 12 | * Financial calculations 13 | * String and date-time manipulations 14 | * __User-Defined Functions (UDFs)__: Create custom functions to meet specific business or analytical needs. 15 | * __Matrix Support__: Handle matrices for advanced mathematical computations or data transformations. 16 | * __Seamless VBA and LO BASIC Integration__: Works directly within VBA and LO BASIC scripts, allowing for automation of complex tasks in Microsoft Excel, Access, Word, and LibreOffice. 17 | 18 | ## Use cases 19 | ### Data Management and Analysis 20 | * __CSV Data Processing__: 21 | * Filter, join, and transform CSV data directly within VBA and LO BASIC scripts, as seen with the [CSV Interface library](https://github.com/ws-garcia/VBA-CSV-interface) 22 | * __Dynamic Reporting__: 23 | * Generate dynamic reports by combining data from multiple sources and applying complex filters or calculations. 24 | ### Financial Analysis 25 | * __Investment Analysis__: Use financial functions for NPV, IRR, or other investment metrics calculations directly within your code on all supported office ecosystem. 26 | * __Portfolio Management__: Manage and analyze financial data sets with custom calculations for performance metrics. 27 | ### Scientific and Engineering Calculations 28 | * __Matrix Operations__: Solve linear systems, perform matrix multiplication for data modeling or simulation. 29 | * __Statistical Analysis__: Conduct statistical tests or data fitting within your Office tools without external software. 30 | ### Educational and Technical Documentation 31 | * __Interactive Documents__: Embed calculations or data transformations in educational materials or technical documentation for live demos or explanations. 32 | ### Automation of Repetitive Tasks 33 | * __Data Cleaning__: Automate data normalization, cleaning, or validation processes. 34 | * __Batch Processing__: Handle batch operations on data, like updating datasets with new calculations or conditions. 35 | 36 | ## Advantages 37 | * __Easy to use and integrate__. 38 | * __Basic math operators__: `+` `-` `*` `/` `\` `^` `!` 39 | * __Logical expressions__: `&` (AND), `|` (OR), `||` (XOR) 40 | * __Binary relations__: `<`, `<=`, `<>`, `>=`, `=`, `==`, `>`, `$` (LIKE) 41 | * __Outstanding matrix and statistical functions__: `CHOLESKY`, `MLR` (Multivariate Linear Regression), `FIT` (Curve fitting), `INVERSE`, and a lot more! 42 | * __More than 100 built-in functions__: `Max`, `Sin`, `IRR`, `GAUSS`, `LSQRSOLVE`, `Switch`, `Iff`, `DateDiff`, `Solve`, `fZero`, `Format`... 43 | * __Very flexible and powerful__: variables, constants and user-defined functions (UDFs) support. 44 | * __Implied multiplication for variables, constants and functions__: `5avg(2;abs(-3-7tan(5));9)`, `5(x)` and `x(2)(3)` are valid expressions. 45 | * __Evaluation of arrays of expressions given as text strings, as in Java__: curly brackets must be used to define arrays`{{...};{...}}` 46 | * __Floating point notation input support__: `-5E-5`, `(1.434E3+1000)*2/3.235E-5` are valid inputs. 47 | * __Free of external VBA dependencies__: does not use dll. 48 | 49 | ## Let's prove it! 50 | ## ![Let's prove it!](/docs/assets/img/GeoProblem.png) 51 | The versatility of VBA Expressions allows its users to apply their creativity to solve a wide variety of geometrical problems in anautomated way. To demonstrate this we will solve the problem shown in the figure shown above. We are asked to calculate the area of the largest square inscribed in a right triangle of legs _a_ and _b_. The square corners confguration is: one corner intersecting the leg _a_, another with intersection on leg _b_ and the others corners intersecting the hypotenuse _c_. First, we define the point _O_ as the square's intersection in leg _b_. The right angle is assumed to be located at the origin of Cartesian plane. In the same way we define _P_ as one intersection of the square with the hypotenuse and _Q_ as the intersection with the leg _a_. Since the figure we are looking for is a square, all sides have a dimension _s_, hence the problem is reduced to ensuring that the magnitudes _OP_ and _OQ_ have the same value. The code to solve the problem is shown below 52 | 53 | ```vb 54 | Public Function LargestSquareInRATriangle(A As Double, B As Double) As String 55 | Dim contFunct As String 56 | Dim evalHelper As VBAexpressions 57 | Dim xVal As String 58 | Dim Area As String 59 | 60 | contFunct = "FZERO('DISTANCE(LINESINTERSECT(PERPENDICULAR(" _ 61 | & "{{" & B & ";0};{0;" & A & "}};{{x;0}})" _ 62 | & ";{{" & B & ";0};{0;" & A & "}})" _ 63 | & ";{{x;0}})" & "-" _ 64 | & "DISTANCE(LINESINTERSECT(PERPENDICULAR(PERPENDICULAR(" _ 65 | & "{{" & B & ";0};{0;" & A & "}};{{x;0}})" _ 66 | & ";{{x;0}})" _ 67 | & ";{{0;0};{0;" & A & "}})" _ 68 | & ";{{x;0}})'" _ 69 | & ";0;" & B & ")" 70 | Set evalHelper = New VBAexpressions 71 | With evalHelper 72 | .Create contFunct 73 | .Eval 74 | If .ErrorType = errNone Then 75 | xVal = Mid(.Result, 2, Len(.Result) - 2) 76 | .Create "(DISTANCE(LINESINTERSECT(PERPENDICULAR(" _ 77 | & "{{" & B & ";0};{0;" & A & "}};{{x;0}})" _ 78 | & ";{{" & B & ";0};{0;" & A & "}})" _ 79 | & ";{{x;0}}))^2", False 80 | .Eval xVal 81 | If .ErrorType = errNone Then 82 | Area = "Area = " & .Result 83 | LargestSquareInRATriangle = xVal & "; " & Area 84 | End If 85 | End If 86 | End With 87 | End Function 88 | ``` 89 | Since the magnitude of the segments _OP_ and _OQ_ must be the same, the `FZERO` function can be used to determine the coordinate _O = (x, 0)_ by iteratively computing the value of _x_ that satisfies the continuous equality _OP−OQ = 0_. After execute the call `LargestSquareInRATriangle(5,12)`, the result returned is 90 | 91 | ```vb 92 | x = 3.14410480351349; Area = 11.6016094276853 93 | ``` 94 | Another problem that can be solved is shown in the figure below. 95 | 96 | ![Let's prove it!](/docs/assets/img/ConceptExample.png) 97 | 98 | The code solution for the above problem is 99 | 100 | ```vb 101 | Public Function IncribedCSCcentersDistance(squareSide As Double) As String 102 | Dim evalHelper As VBAexpressions 103 | 104 | Set evalHelper = New VBAexpressions 105 | With evalHelper 106 | .Create "GET('s';" & CStr(squareSide) & ")": .Eval 107 | .Create "GET('upper.triangle';{{s;0}};{{s;s}};{{0;s}})", False: .Eval 108 | .Create "GET('lower.triangle';{{0;s}};{{0;-s}};{{s;0}})", False: .Eval 109 | .Create "GET('ut.inctr';INCENTER(upper.triangle))", False: .Eval 110 | .Create "GET('lt.inctr';INCENTER(lower.triangle))", False: .Eval 111 | .Create "GET('inc.dist';ROUND(DISTANCE(ut.inctr;lt.inctr);4))", False: .Eval 112 | .Create "MROUND(INCIRCLE(upper.triangle);4)", False: .Eval 113 | Debug.Print "Inscribed upper circle: " & .result 114 | .Create "MROUND(INCIRCLE(lower.triangle);4)", False: .Eval 115 | Debug.Print "Inscribed lower circle: " & .result 116 | IncribedCSCcentersDistance = .VarValue("inc.dist") 117 | End With 118 | End Function 119 | ``` 120 | After executing the code, in the console is also printed the inscribed circle center point coordinates and radius magnitudes. 121 | 122 | ```vb 123 | Inscribed upper circle: {{8.4853;8.4853};{3.5147;3.5147}} 124 | Inscribed lower circle: {{4.9706;0};{4.9706;4.9706}} 125 | ``` 126 | 127 | These UDF's are masterpieces demonstrating the power and versatility offered by the latest versions of VBA Expressions! 128 | 129 | ## Supported expressions 130 | 131 | The evaluation approach used is similar to the one we humans use: divide the function into sub-expressions, create a symbolic string to build an expression evaluation flow, split the sub-expressions into chunks of operations (tokens) by tokenization, evaluate all the tokens. 132 | 133 | The module can evaluate mathematical expressions such as: 134 | 135 | + `5*avg(2;abs(-3-7*tan(5));9)-12*pi-e+(7/sin(30)-4!)*min(cos(30);cos(150))` 136 | + `min(cos(sin(30))+2^2;1)` 137 | + \* `GCD(1280;240;100;30*cos(0);10*DET({{sin(atn(1)*2); 0; 0}; {0; 2; 0}; {0; 0; 3}}))` 138 | 139 | \*`GCD` is an user-defined function (UDF). 140 | 141 | Allowed expressions must follow the following grammar: 142 | 143 | ``` 144 | Expression = ([{"("}] SubExpr [{Operator [{"("}] SubExpr [{")"}]}] [{")"}] | {["("] ["{"] List [{";" List}] ["}"] [")"]}) 145 | SubExpr = Token [{Operator Token}] 146 | Token = [{Unary}] Argument [(Operator | Function) ["("] [{Unary}] [Argument] [")"]] 147 | Argument = (List | Variable | Operand | Literal) 148 | List = ["{"] ["{"] SubExpr [{";" SubExpr}] ["}"] ["}"] 149 | Unary = "-" | "+" | ~ 150 | Literal = (Operand | "'"Alphabet"'") 151 | Operand = ({Digit} [Decimal] [{Digit}] ["E"("-" | "+"){Digit}] | (True | False)) 152 | Variable = Alphabet [{Decimal}] [{(Digit | Alphabet)}] 153 | Alphabet = "A-Z" | "a-z" 154 | Decimal = "." | "," 155 | Digit = "0-9" 156 | Operator = "+" | "-" | "*" | "/" | "\" | "^" | "%" | "!" | "<" | "<=" | "<>" | ">" | ">=" | "=" | "$" | "&" | "|" | "||" 157 | Function = "abs" | "sin" | "cos" | "min" |...|[UDF] 158 | ``` 159 | 160 | ## Operators precedence 161 | VBA expressions uses the following precedence rules to evaluate mathematical expressions: 162 | 163 | 1. `()` Grouping: evaluates functions arguments as well. 164 | 2. `! - +` Unary operators: exponentiation is the only operation that violates this. Ex.: `-2 ^ 2 = -4 | (-2) ^ 2 = 4`. 165 | 3. `^` Exponentiation: Although Excel and Matlab evaluate nested exponentiations from left to right, Google, mathematicians and several modern programming languages, such as Perl, Python and Ruby, evaluate this operation from right to left. VBA expressions also evals in Python way: a^b^c = a^(b^c). 166 | 4. `\* / % ` Multiplication, division, modulo: from left to right. 167 | 5. `+ -` Addition and subtraction: from left to right. 168 | 6. `< <= <> >= = == > $` Binary relations. 169 | 7. `~` Logical negation. 170 | 8. `&` Logical AND. 171 | 9. `||` Logical XOR. 172 | 10. `|` Logical OR. 173 | 174 | ## Variables 175 | Users can enter variables and set/assign their values for the calculations. Variable names must meet the following requirements: 176 | 1. Start with a letter. 177 | 2. End in a letter or number. `"x.1"`, `"number1"`, `"value.a"` are valid variable names. 178 | 3. A variable named `"A"` is distinct from another variable named `"a"`, since variables are case-sensitive. This rule is broken by the constant `PI`, since `PI=Pi=pi=pI`. 179 | 4. The token `"E"` cannot be used as variable due this token is reserved for floating point computation. For example, the expression `"2.5pi+3.5e"` will be evaluated to `~17.3679680`, but a expression like `"2.5pi+3.5E"` will return an error. 180 | 181 | ## User-defined functions (UDF) 182 | Users can register custom modules to expose and use their functions through the VBAcallBack.cls module. All UDFs must have a single Variant argument that will receive an one-dimensional array of strings (one element for each function argument). 183 | 184 | Here is a working example of UDF function creation 185 | ``` 186 | Sub AddingNewFunctions() 187 | Dim Evaluator As VBAexpressions 188 | Dim UDFnames() As Variant 189 | Dim Result As String 190 | 191 | Set Evaluator = New VBAexpressions 192 | UDFnames() = Array("GCD") 193 | With Evaluator 194 | .DeclareUDF UDFnames, "UserDefFunctions" 'Declare the Greatest Common Divisor function 195 | 'defined in the UDfunctions class module. This need 196 | 'an instance in the VBAcallBack class module. 197 | ' The determinant of a diagonal matrix. It is defined 198 | ' as the product of the elements in its diagonal. 199 | ' For our case: 1*2*3=6. (Note that sin(atn(1)*2)=sin(pi/2)=1) 200 | .Create "GCD(1280;240;100;30*cos(0);10*DET({{sin(atn(1)*2); 0; 0}; {0; 2; 0}; {0; 0; 3}}))" 201 | Result = .Eval 202 | End With 203 | End Sub 204 | ``` 205 | ## Working with arrays 206 | VBA expressions can evaluate matrix functions whose arguments are given as arrays/vectors, using a syntax like [Java](https://www.w3schools.com/java/java_arrays.asp). The following expression will calculate, and format to percentage, the internal rate of return (`IRR`) of a cash flow described using a one dimensional array with 5 entries: 207 | 208 | `FORMAT(IRR({{-70000;12000;15000;18000;21000}});'Percent')` 209 | 210 | However, user-defined array functions need to take care of creating arrays from a string, the `ArrayFromString` method can be used for this purpose. 211 | 212 | ## Using the code 213 | VBA Expressions is an easy-to-use library, this section shows some examples of how to use the most common properties and methods 214 | 215 | $\color{D29922}\textsf{\Large Warning:}$ 216 | >[The library](https://extensions.libreoffice.org/en/extensions/show/70059) only works on LibreOffice version 7.5 or higher and, since there is no 1-1 compatibility between VBA and LO Basic, users must be aware of certain changes required to recover some properties functionality. This applies mainly to those properties related to accessing variables, which were converted into functions to overcome the one-parameter limitation imposed by LO Basic when accessing them, as well as to other properties deprecated due to LO Basic's behaviour in handling class modules. An example of this is the `VarValue` property which was split into two procedures: `GetVarValue` and `LetVarValue`. The rest of the syntax is shared between the two implementations. 217 | 218 | ``` 219 | Sub SimpleMathEval() 220 | Dim Evaluator As VBAexpressions 221 | Set Evaluator = New VBAexpressions 222 | With Evaluator 223 | .Create "(((((((((((-123.456-654.321)*1.1)*2.2)*3.3)+4.4)+5.5)+6.6)*7.7)*8.8)+9.9)+10.10)" 224 | If .ReadyToEval Then 'Evaluates only if the expression was successfully parsed. 225 | .Eval 226 | End If 227 | End With 228 | End Sub 229 | Sub LateVariableAssignment() 230 | Dim Evaluator As VBAexpressions 231 | Set Evaluator = New VBAexpressions 232 | With Evaluator 233 | .Create "Pi.e * 5.2Pie.1 + 3.1Pie" 234 | If .ReadyToEval Then 235 | Debug.Print "Variables: "; .CurrentVariables 'Print the list of parsed variables 236 | .Eval ("Pi.e=1; Pie.1=2; Pie=3") 'Late variable assignment 237 | Debug.Print .Expression; " = "; .Result; _ 238 | "; for: "; .CurrentVarValues 'Print stored result, expression and values used in evaluation 239 | End If 240 | End With 241 | End Sub 242 | Sub EarlyVariableAssignment() 243 | Dim Evaluator As VBAexpressions 244 | Set Evaluator = New VBAexpressions 245 | With Evaluator 246 | .Create "Pi.e * 5.2Pie.1 + 3.1Pie" 247 | If .ReadyToEval Then 248 | Debug.Print "Variables: "; .CurrentVariables 249 | .VarValue("Pi.e") = 1 250 | .ImplicitVarValue("Pie.1") = "2*Pi.e" 251 | .ImplicitVarValue("Pie") = "Pie.1/3" 252 | .Eval 253 | Debug.Print .Expression; " = "; .Result; _ 254 | "; for: "; .CurrentVarValues 255 | End If 256 | End With 257 | End Sub 258 | Sub TrigFunctions() 259 | Dim Evaluator As VBAexpressions 260 | Set Evaluator = New VBAexpressions 261 | With Evaluator 262 | .Create "asin(sin(30))" 263 | If .ReadyToEval Then 264 | .Degrees = True 'Eval in degrees 265 | .Eval 266 | End If 267 | End With 268 | End Sub 269 | Sub StringFunctions() 270 | Dim Evaluator As VBAexpressions 271 | Set Evaluator = New VBAexpressions 272 | 273 | With Evaluator 274 | .Create "CONCAT(CHOOSE(1;x;'2nd';'3th';'4th';'5th');'Element';'selected';'/')" 275 | .Eval ("x='1st'") 276 | End With 277 | End Sub 278 | Sub LogicalFunctions() 279 | Dim Evaluator As VBAexpressions 280 | Set Evaluator = New VBAexpressions 281 | 282 | With Evaluator 283 | .Create "IFF(x > y & x > 0; x; y)" 284 | .Eval("x=70;y=15") 'This will be evaluated to 70 285 | End With 286 | End Sub 287 | Sub SolveSystemOfLinearEquations() 288 | Dim Evaluator As VBAexpressions 289 | 290 | Set Evaluator = New VBAexpressions 291 | With Evaluator 292 | 'Create an array of vectors a, b, c, d and e 293 | .Create "SOLVE(ARRAY(a;b;c;d;e);{{'x1';'x2';'x3';'x4';'x5'}};{{100;100;100;100;100}};True)" 294 | 295 | 'Define coeficient vectors 296 | .VarValue("a") = "{4;-1;0;1;0}" 297 | .VarValue("b") = "{-1;4;-1;0;1}" 298 | .VarValue("c") = "{0;-1;4;-1;0}" 299 | .VarValue("d") = "{1;0;-1;4;-1}" 300 | .VarValue("e") = "{0;1;0;-1;4}" 301 | .Eval 'Evaluates to [x1 = 25; x2 = 35.7142857143; x3 = 42.8571428571; x4 = 35.7142857143; x5 = 25] 302 | End With 303 | End Sub 304 | 305 | '@------------------------------------------------------ 306 | ' Here a list of the new functions and its results 307 | '***********************************ADVANCED MATH FUNCTIONS*************************************************************** 308 | ''' A={{-2;40};{-1;50};{0;62};{1;58};{2;60}} 309 | ''' B={{0;0.1};{0.5;0.45};{1;2.15};{1.5;9.15};{2;40.35};{2.5;180.75}} 310 | ''' C={{1;0.01};{2;1};{3;1.15};{4;1.3};{5;1.52};{6;1.84};{7;2.01};{8;2.05};{9;2.3};{10;2.25}} 311 | ''' ---------------------------------------------------------------------------- 312 | ''' | Fitting data model with a 4th degree polynomial | 313 | ''' | FIT(A;1;4) : {{62 + 3.6667*x -9.6667*x^2 + 0.3333*x^3 + 1.6667*x^4};{1}} | 314 | ''' | | 315 | ''' | Exponential Fitting | 316 | ''' | FIT(B;2) : {{0.102*e^(2.9963*x)};{0.9998}} | 317 | ''' | | 318 | ''' | Logarithmic Fitting | 319 | ''' | FIT(C;5) : {{0.9521*ln(x)+0.1049};{0.9752}} | 320 | ''' ---------------------------------------------------------------------------- 321 | ''' 322 | ''' X={{1;1};{2;2};{3;3};{4;4};{5;1};{6;2};{7;3};{8;4}} 323 | ''' Y={{2;4.1;5.8;7.8;5.5;5.2;8.2;11.1}} 324 | ''' ------------------------------------------------------------------------------------------ 325 | ''' | Multivariate Linear Regression with regressors/predictors interaction. | 326 | ''' | | 327 | ''' | MLR(X;Y;True;'X1:X2') : {{0.8542 + 0.4458*X1 + 0.945*X2 + 0.0792*X1*X2};{0.947;0.9072}} | 328 | ''' ------------------------------------------------------------------------------------------ 329 | ''' 330 | ''' ---------------------------------------------------------------- 331 | ''' | Finding a zero for the given function in the interval -2<=x<=3 | 332 | ''' | | 333 | ''' | FZERO('2x^2+x-12';-2;3) : x = 2.21221445045296 | 334 | ''' ---------------------------------------------------------------- 335 | ''' 336 | ''' a = {1;0;4}; b = {1;1;6}; c = {-3;0;-10}; d = {2;3;4} 337 | ''' ------------------------------------------------------------------------------------------------ 338 | ''' | Using LU decomposition for a given matrix | 339 | ''' | | 340 | ''' | LUDECOMP(ARRAY(a;b;c)) : | 341 | ''' | | 342 | ''' | {{-3;0;-10};{-0.333333333333333;1;2.66666666666667};{-0.333333333333333;0;0.666666666666667}} | 343 | ''' ------------------------------------------------------------------------------------------------ 344 | ''' 345 | ''' ---------------------------------------------------------------------------------- 346 | ''' | Using LU decomposition for solve linear equations system | 347 | ''' | | 348 | ''' | LUSOLVE(ARRAY(a;b;c);{{'x';'y';'z'}};{{2;3;4}};True) : x = -18; y = -9; z = 5 | 349 | ''' ---------------------------------------------------------------------------------- 350 | ''' 351 | ''' --------------------------------------------------------------------------- 352 | ''' | Using matrix multiplication for solve a linear equations system | 353 | ''' | | 354 | ''' | MMULT(INVERSE(ARRAY(a;b;c));ARRAY(d)) : {{-18};{-9};{5}} | 355 | ''' | MMULT(ARRAY(a;b;c);INVERSE(ARRAY(a;b;c))) : {{1;0;0};{0;1;0};{0;0;1}} | 356 | ''' --------------------------------------------------------------------------- 357 | ''' 358 | ''' A={{2;4};{-5;1},{3;-8}};b={{10;-9.5;12}} 359 | ''' -------------------------------------------------------------------- 360 | ''' | Solving overdetermined system of equations using least squares and | 361 | ''' | the QR decomposition | 362 | ''' | | 363 | ''' | MROUND(LSQRSOLVE(A;b);4) : {{2.6576;-0.1196}} | 364 | ''' -------------------------------------------------------------------- 365 | ''' 366 | '***********************************GEOMETRICAL FUNCTIONS******************************************************************************* 367 | ''' DISTANCE({{3.1441;0}};{{4.45415;3.1441}}) = 3.40611153847022 368 | ''' LINESINTERSECT({{3.1441;0};{0;1.31004}};{{0;3};{-3;3}}) = {{-4.05590916002565;3}} 369 | ''' PARALLEL({{12;0};{0;5}};{{3.1441;0}}) = {{3.1441;0};{0;1.31004166666667}} 370 | ''' PERPENDICULAR({{12;0};{0;5}};{{0;0}}) = {{0;0};{1.77514792899408;4.2603550295858}} 371 | ''' MROUND(BISECTOR({{-4;-2}};{{-2;6}});4) = {{-3;2};{-2;1.75}} 372 | ''' MROUND(INCENTER({{0;0}};{{-4;-2}};{{-2;6}});4) = {{-1.7982;0.7448}} 373 | ''' MROUND(INCIRCLE({{0;0}};{{-4;-2}};{{-2;6}});4) = {{-1.7982;0.7448};{1.4704;1.4704}} 374 | ''' MROUND(CIRCUMCIRCLE({{0;0}};{{-4;-2}};{{-2;6}});4) = {{-3.5714;2.1429};{4.165;4.165}} 375 | ''' MROUND(CIRCLETANG({{-4;3}};SQRT(17);{{2;5}});4) = {{-2.4387;6.8161};{2;5}};{{2;5};{-0.4613;0.8839}} 376 | '***********************************STATISTICAL FUNCTIONS******************************************************************************* 377 | ''' ROUND(NORM(0.05);8) = 0.96012239 378 | ''' ROUND(CHISQ(4;15);8) = 0.99773734 379 | ''' ROUND(GAUSS(0.05);8) = 0.01993881 380 | ''' ROUND(ERF(0.05);8) = 0.05637198 381 | ''' ROUND(STUDT(0.8;15);8) = 0.43619794 382 | ''' ROUND(ANORM(0.75);8) = 0.31863936 383 | ''' ROUND(AGAUSS(0.75);8) = 0.67448975 384 | ''' ROUND(AERF(0.95);8) = 1.38590382 385 | ''' ROUND(ACHISQ(0.75;15);8) = 11.03653766 386 | ''' ROUND(FISHF(5.5;1.5;3);8) = 0.21407698 387 | ''' ROUND(ASTUDT(0.05;15);8) = 2.13144955 388 | ''' ROUND(AFISHF(0.05;1.5;3);8) = 18.55325631 389 | ''' ROUND(iBETA(0.5;1;3);8) = 0.875 390 | ''' ROUND(BETAINV(0.5;1;3);8) = 0.20629947 391 | '***********************************FINANTIAL FUNCTIONS********************************************************************************* 392 | ''' FORMAT(SYD(10000;5000;5;2);'Currency') = '$1,333.33' 393 | ''' FORMAT(SLN(10000;0;5);'Currency') = '$2,000.00' 394 | ''' FORMAT(RATE(2*12; -250; 5000; 0; 1);'Percent') = '1.66%' 395 | ''' FORMAT(PV(0.075/12; 2*12; 250; 0; 0);'Currency') = '($5,555.61)' 396 | ''' FORMAT(PPMT(0.06/52; 20; 4*52; 8000; 0; 0);'Currency') = '($34.81)' 397 | ''' FORMAT(PMT(0.075/12; 2*12; 5000; 0; 1);'Currency') = '($223.60)' 398 | ''' FORMAT(NPV(0.1;{{-10000;3000;4200;6800}});'Currency') = '$1,188.44' 399 | ''' FORMAT(NPER(0.0525/1; -200; 1500);'0.00') = '9.78' 400 | ''' FORMAT(MIRR({{-7500;3000;5000;1200;4000}};0.05;0.08);'Percent') = '18.74%' 401 | ''' 402 | ''' Microsoft example. VBA Expressions use a custom solver to compute IRR 403 | ''' FORMAT(IRR({{-70000;12000;15000;18000;21000}});'Percent') = '-2.12%' 404 | ''' FORMAT(IRR({{-70000;12000;15000;18000;21000;26000}});'Percent') = '8.66%' 405 | ''' FORMAT(IRR({{-70000;12000;15000}};true);'Percent') = '-44.35%' 'Find a solution with negative values for IRR 406 | ''' 407 | ''' FORMAT(IPMT(0.0525/1; 4; 10*1; 6500);'Currency') = '($256.50)' 408 | ''' FORMAT(FV(0.0525/1; 10*1; -100; -6500; 0);'Currency') = '$12,115.19' 409 | ''' FORMAT(DDB(10000; 5000; 5; 2);'Currency') = '$1,000.00' 410 | '***********************************DATE AND TIME FUNCTIONS***************************************************************************** 411 | ''' YEAR(NOW()) = 2022 412 | ''' WEEKDAYNAME(1;true;2) = 'lun.' 413 | ''' WEEKDAY(NOW()) = 2 414 | ''' TIMEVALUE(NOW()) = '7:53:00 a. m.' 415 | ''' TIMESERIAL(x;y;z) = '6:45:50 a. m.' for x = 7; y = -15; z = 50 416 | ''' MONTH(NOW()) = 10 417 | ''' MONTHNAME(x;y) = 'marzo' for x = 3; y = false 418 | ''' MONTH(x) = 10 for x = '10/10/2022 7:53:10 a. m.' 419 | ''' MINUTE(x) = 53 for x = '10/10/2022 7:53:12 a. m.' 420 | ''' HOUR(x) = 7 for x = '10/10/2022 7:53:15 a. m.' 421 | ''' DAY(DATE()) = 10 422 | ''' DATEVALUE(DATE()) = '10/10/2022' 423 | ''' DATESERIAL(2022;x+2;3y) = '21/12/2022' for x = 10; y = 7 424 | ''' DATEPART(x;DATE()) = 2022 for x = 'yyyy' 425 | ''' DATEPART(x;DATE()) = 10 for x = 'm' 426 | ''' DATEPART(x;DATE()) = 10 for x = 'd' 427 | ''' DATEPART(x;DATE()) = 4 for x = 'q' 428 | ''' DATEDIFF(x;DATE();DATEADD(x;y;DATE())) = 3 for x = 'yyyy'; y = 3 429 | ''' DATEDIFF(x;DATE();DATEADD(x;y;DATE())) = 2 for x = 'q'; y = 2 430 | ''' DATEDIFF(x;DATE();DATEADD(x;y;DATE())) = 5 for x = 'm'; y = 5 431 | ''' DATEDIFF(x;DATE();DATEADD(x;y;DATE())) = 10 for x = 'd'; y = 10 432 | ''' DATEADD(x;y;DATE()) = 10/10/2025 for x = 'yyyy'; y = 3 433 | ''' DATEADD(x;y;DATE()) = 10/4/2023 for x = 'q'; y = 2 434 | ''' DATEADD(x;y;DATE()) = 10/3/2023 for x = 'm'; y = 5 435 | ''' DATEADD(x;y;DATE()) = 20/10/2022 for x = 'd'; y = 10 436 | ''' DATE() = '10/10/2022' 437 | '***********************************STRING FUNCTIONS****************************************************************************** 438 | ''' UCASE(x) = ' THIS STRING ' for x = ' This String ' 439 | ''' TRIM(x) = 'Capi tal' for x = ' Capi tal ' 440 | ''' RIGHT(2x+20-5+x;2) = '90' for x = 25 441 | ''' RIGHT(2x+20-5+x;2) = '09' for x = 98 442 | ''' REPLACE(x;'a';'A';1;2) = 'CApitAl' for x = 'Capital' 443 | ''' MID(x;4;3) = 'ion' for x = 'Region' 444 | ''' LEN(x) = 6 for x = 'Region' 445 | ''' LEFT(2x+20-5+x;2) = '90' for x = 25 446 | ''' LEFT(2x+20-5+x;2) = '30' for x = 98 447 | ''' LCASE(x) = 'this string' for x = 'This String' 448 | ''' LCASE(x) = '98' for x = 98 449 | ''' FORMAT(x;'Percent') = '98.10%' for x = 0.981 450 | ''' CHR(x) = ';' for x = 59 451 | ''' ASC(x) = 82 for x = 'Region' 452 | ''' SWITCH(x='Asia';1;x='Africa';2;x='Oceania';3) = 1 for x = 'Asia' 453 | '@------------------------------------------------------ 454 | ``` 455 | ## Contributing 456 | We welcome contributions to enhance VBA Expressions. Whether it's new functions, bug fixes, or documentation improvements, your input can help make this tool even more powerful: 457 | * Fork the repository. 458 | * Make your changes or additions. 459 | * Submit a pull request. 460 | ## Support 461 | For issues, feature requests, or questions, please use the issue tracker on GitHub. We're also open to discussions or contributions to our wiki for more use cases and tutorials. 462 | ## Credits 463 | - [x] **Inquisitive knight**: new logo design. Awesome job! 464 | 465 | ## Tested 466 | [![Rubberduck](https://user-images.githubusercontent.com/5751684/48656196-a507af80-e9ef-11e8-9c09-1ce3c619c019.png)](https://github.com/rubberduck-vba/Rubberduck/) 467 | 468 | ## Licence 469 | 470 | Copyright: © 2022-2025 [W. García](https://github.com/ws-garcia/). 471 | 472 | This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. 473 | 474 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 475 | 476 | You should have received a copy of the GNU General Public License along with this program. If not, see . 477 | 478 | -------------------------------------------------------------------------------- /docs/assets/img/Concept example.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ECP-Solutions/VBA-Expressions/538a1962e6992d652f833bc3a20657188f5aa455/docs/assets/img/Concept example.pdf -------------------------------------------------------------------------------- /docs/assets/img/ConceptExample.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ECP-Solutions/VBA-Expressions/538a1962e6992d652f833bc3a20657188f5aa455/docs/assets/img/ConceptExample.png -------------------------------------------------------------------------------- /docs/assets/img/GeoProblem.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ECP-Solutions/VBA-Expressions/538a1962e6992d652f833bc3a20657188f5aa455/docs/assets/img/GeoProblem.png -------------------------------------------------------------------------------- /docs/assets/img/VBA Expressions-NewLogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ECP-Solutions/VBA-Expressions/538a1962e6992d652f833bc3a20657188f5aa455/docs/assets/img/VBA Expressions-NewLogo.png -------------------------------------------------------------------------------- /docs/assets/img/VBA Expressions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ECP-Solutions/VBA-Expressions/538a1962e6992d652f833bc3a20657188f5aa455/docs/assets/img/VBA Expressions.png -------------------------------------------------------------------------------- /docs/assets/img/VBAExprManual.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ECP-Solutions/VBA-Expressions/538a1962e6992d652f833bc3a20657188f5aa455/docs/assets/img/VBAExprManual.pdf -------------------------------------------------------------------------------- /src/LO Basic/VBAExpressions.update.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/LO Basic/VBAExpressionsLib/TestRunner.xba: -------------------------------------------------------------------------------- 1 | 2 | 3 | Option Explicit 4 | Private Evaluator As Object 5 | Private actual As String 6 | Private sAcum As Long 7 | Private tTotal As Long 8 | 9 | '# 10 | '//////////////////////////////////////////////////////////////////////////////////////////// 11 | ' Copyright © 2024-2025 W. García 12 | ' GPL-3.0 license | https://www.gnu.org/licenses/gpl-3.0.html/ 13 | ' https://github.com/ws-garcia 14 | '//////////////////////////////////////////////////////////////////////////////////////////// 15 | '# 16 | ' GENERAL INFO: 17 | ' Class module developed for testing the library. 18 | '/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 19 | '# 20 | Private Function GetResult(expression As String _ 21 | , Optional VariablesValues As String) As String 22 | On Error Resume Next 23 | Set Evaluator = New VBAexpressions 24 | 25 | With Evaluator 26 | .Create expression 27 | GetResult = .Eval(VariablesValues) 28 | End With 29 | End Function 30 | 31 | Sub RunAllTests 32 | GlobalScope.BasicLibraries.loadLibrary("VBAExpressionsLib") 33 | GlobalScope.BasicLibraries.loadLibrary("ScriptForge") 34 | createscriptservice("Exception") 35 | SF_Exception.consoleClear() 36 | 'CODE HERE 37 | Run( _ 38 | "Parentheses", _ 39 | "(((((((((((-123.456-654.321)*1.1)*2.2)*3.3)+4.4)+5.5)+6.6)*7.7)*8.8)+9.9)+10.10)", _ 40 | "-419741.48578672" _ 41 | ) 42 | Run( _ 43 | "Parentheses and Single Function", _ 44 | "(1+(2-5)*3+8/(5+3)^2)/sqr(4^2+3^2)", _ 45 | "-1.575" _ 46 | ) 47 | Run( _ 48 | "Functions with More than One Argument", _ 49 | "min(5;6;max(-0.6;-3))", _ 50 | "-0.6" _ 51 | ) 52 | Run( _ 53 | "Nested Functions", _ 54 | "tan(sqr(abs(ln(x))))", _ 55 | "1.5574077246549", _ 56 | "x = " & Exp(1) _ 57 | ) 58 | Run( _ 59 | "Floating Point Arithmetic", _ 60 | "(1.434E3+1000)*2/3.235E-5", _ 61 | "150479134.46677" _ 62 | ) 63 | Run( _ 64 | "Exponentiation Precedence", _ 65 | "4^3^2", _ 66 | "262144" _ 67 | ) 68 | Run( _ 69 | "Factorials", _ 70 | "25!/(24!)", _ 71 | "25" _ 72 | ) 73 | Run( _ 74 | "Precedence", _ 75 | "5avg(2;abs(-3-7tan(5));9)-12pi-e+(7/sin(30)-4!)*min(cos(30);cos(150))", _ 76 | "7.56040693890688" _ 77 | ) 78 | Run( _ 79 | "Variables", _ 80 | "Pi.e * 5.2Pie.1 + 3.1Pie", _ 81 | "19.7", _ 82 | "Pi.e = 1; Pie.1 = 2; Pie = 3" _ 83 | ) 84 | Run( _ 85 | "UDFs and Basic Array Functions", _ 86 | "GCD(1280;240;100;30*cos(0);10*DET({{sin(atn(1)*2); 0; 0}; {0; 2; 0}; {0; 0; 3}}))", _ 87 | "10" _ 88 | ) 89 | Run( _ 90 | "Logical Operators with Numeric Output", _ 91 | "(x<=0)* x^2 + (x>0 & x<=1)* Ln(x+1) + (x>1)* Sqr(x-Ln(2))", _ 92 | "2.30366074313039", _ 93 | "x = 6" _ 94 | ) 95 | Run( _ 96 | "Logical Operators with Boolean Output", _ 97 | "x>0 & Sqr(x-Ln(2))>=3 | tan(x)<0", _ 98 | "True", _ 99 | "x = 6" _ 100 | ) 101 | Run( _ 102 | "Trig Functions", _ 103 | "ROUND(tan(pi/4)^3-((3*sin(pi/4)-sin(3*pi/4))/(3*cos(pi/4)+cos(3*pi/4)));14)", _ 104 | "0" _ 105 | ) 106 | Run( _ 107 | "Mod Function", _ 108 | "- (-1) + (+1) + 1.000 / 1.000 + 1 * (1) * (0.2) * (5) * (-1) * (--1) + 4 % 5 % 45 % 1 ", _ 109 | "2" _ 110 | ) 111 | Run( _ 112 | "String Arguments and Parameters", _ 113 | "Region = 'Central America'", _ 114 | "False", _ 115 | "Region = 'Asia'" _ 116 | ) 117 | Run( _ 118 | "String Arguments and Parameters-2", _ 119 | "REPLACE(x;'a';'A';1;2)", _ 120 | "'CApitAl'", _ 121 | "x = 'Capital'" _ 122 | ) 123 | Run( _ 124 | "Implied Multiplication", _ 125 | "5(2)(3)(4)", _ 126 | "120" _ 127 | ) 128 | Run( _ 129 | "Support of equality == symbol", _ 130 | "(a + b == c) & (a + b = c)", _ 131 | "True", _ 132 | "a = -1; b = -2; c = -3" _ 133 | ) 134 | ArrayConstructorsAndParsers ("Array Constructors And Parsers") 135 | Run( _ 136 | "Matrices: sum", _ 137 | "MSUM(f;g)", _ 138 | "{{-2;0;-6};{3;4;10}}", _ 139 | "f = {{1;0;4};{1;1;6}}; g = {{-3;0;-10};{2;3;4}}" _ 140 | ) 141 | Run( _ 142 | "Matrices: sum-2", _ 143 | "MSUM({{1;0;4};{1;1;6}};{{-3;0;-10};{2;3;4}})", _ 144 | "{{-2;0;-6};{3;4;10}}" _ 145 | ) 146 | Run( _ 147 | "Matrices: multiplication", _ 148 | "MMULT({{1;0;4}};{{1;1;6}})", _ 149 | "25" _ 150 | ) 151 | Run( _ 152 | "Matrices: multiplication 2", _ 153 | "MMULT(A;B)", _ 154 | "{{12}}", _ 155 | "A={{1;-2;4}};B={{2};{1};{3}}" _ 156 | ) 157 | Run( _ 158 | "Matrices: multiplication-3", _ 159 | "MMULT(A;B)", _ 160 | "{{2;-4;8};{1;-2;4};{3;-6;12}}", _ 161 | "A={{2};{1};{3}};B={{1;-2;4}}" _ 162 | ) 163 | Run( _ 164 | "Matrices: multiplication-4", _ 165 | "MMULT(A;B)", _ 166 | "{{16};{-21};{21}}", _ 167 | "A={{2;1;4};{1;5;-3};{5;-2;3}};B={{1};{-2};{4}}" _ 168 | ) 169 | Run( _ 170 | "Matrices: multiplication-5", _ 171 | "MMULT(A;B)", _ 172 | "{{-1;13};{6;15}}", _ 173 | "A={{2;1;3};{3;-2;-1}};B={{2;3};{1;-5};{-2;4}}" _ 174 | ) 175 | Run( _ 176 | "Statistical Functions: NORM", _ 177 | "ROUND(NORM(0.05);8)", _ 178 | "0.96012239" _ 179 | ) 180 | Run( _ 181 | "Statistical Functions: CHISQ", _ 182 | "ROUND(CHISQ(4;15);8)", _ 183 | "0.99773734" _ 184 | ) 185 | Run( _ 186 | "Statistical Functions: GAUSS", _ 187 | "ROUND(GAUSS(0.05);8)", _ 188 | "0.01993881" _ 189 | ) 190 | Run( _ 191 | "Statistical Functions: ERF", _ 192 | "ROUND(ERF(0.05);8)", _ 193 | "0.05637198" _ 194 | ) 195 | Run( _ 196 | "Statistical Functions: STUDT", _ 197 | "ROUND(STUDT(0.8;15);8)", _ 198 | "0.43619794" _ 199 | ) 200 | Run( _ 201 | "Statistical Functions: ANORM", _ 202 | "ROUND(ANORM(0.75);8)", _ 203 | "0.31863936" _ 204 | ) 205 | Run( _ 206 | "Statistical Functions: AGAUSS", _ 207 | "ROUND(AGAUSS(0.75);8)", _ 208 | "0.67448975" _ 209 | ) 210 | Run( _ 211 | "Statistical Functions: AERF", _ 212 | "ROUND(AERF(0.95);8)", _ 213 | "1.38590382" _ 214 | ) 215 | Run( _ 216 | "Statistical Functions: ACHISQ", _ 217 | "ROUND(ACHISQ(0.75;15);8)", _ 218 | "11.03653766" _ 219 | ) 220 | Run( _ 221 | "Statistical Functions: FISHF", _ 222 | "ROUND(FISHF(5.5;1.5;3);8)", _ 223 | "0.21407698" _ 224 | ) 225 | Run( _ 226 | "Statistical Functions: ASTUDT", _ 227 | "ROUND(ASTUDT(0.05;15);8)", _ 228 | "2.13144955" _ 229 | ) 230 | Run( _ 231 | "Statistical Functions: AFISHF", _ 232 | "ROUND(AFISHF(0.05;1.5;3);8)", _ 233 | "18.55325631" _ 234 | ) 235 | Run( _ 236 | "Statistical Functions: iBETA", _ 237 | "ROUND(iBETA(0.5;1;3);8)", _ 238 | "0.875" _ 239 | ) 240 | Run( _ 241 | "Statistical Functions: BETAINV", _ 242 | "ROUND(BETAINV(0.5;1;3);8)", _ 243 | "0.20629947" _ 244 | ) 245 | Run( _ 246 | "Statistical Functions: BETA.DIST", _ 247 | "ROUND(BETA.DIST(2;8;10;False;1;3);7)", _ 248 | "1.4837646" _ 249 | ) 250 | QRdec("Linear Algebra Functions: QR decomposition") 251 | Run( _ 252 | "Linear Algebra Functions: Cholesky", _ 253 | "MROUND(MTRANSPOSE(CHOLESKY({{2.5;1.1;0.3};{2.2;1.9;0.4};{1.8;0.1;0.3}}));4)", _ 254 | "{{1.5811;0.6957;0.1897};{0;1.19;0.2252};{0;0;0.4618}}" _ 255 | ) 256 | Run( _ 257 | "Linear Algebra Functions: Cholesky solve", _ 258 | "MROUND(CHOLSOLVE(ARRAY(a;b;c);{{'x';'y';'z'}};{{76;295;1259}};False);4)", _ 259 | "{{1;1;1}}", _ 260 | "a={6;15;55};b={15;55;225};c={55;225;979}" _ 261 | ) 262 | Run( _ 263 | "Linear Algebra Functions: Cholesky Inverse", _ 264 | "MROUND(CHOLINVERSE(ARRAY(a;b;c));4)", _ 265 | "{{0.8214;-0.5893;0.0893};{-0.5893;0.7268;-0.1339};{0.0893;-0.1339;0.0268}}", _ 266 | "a={6;15;55};b={15;55;225};c={55;225;979}" _ 267 | ) 268 | Run( _ 269 | "Linear Algebra Functions: Least Square Solve", _ 270 | "MROUND(LSQRSOLVE(A;b);4)", _ 271 | "{{2.6576};{-0.1196}}", _ 272 | "A={{2;4};{-5;1};{3;-8}};b={{10;-9.5;12}}" _ 273 | ) 274 | Run( _ 275 | "Linear Algebra Functions: LU Solve", _ 276 | "LUSOLVE(ARRAY(a;b;c);{{'x';'y';'z'}};{{2;3;4}};True)", _ 277 | "x = -18; y = -9; z = 5", _ 278 | "a={1;0;4};b={1;1;6};c={-3;0;-10}" _ 279 | ) REM: Fail by machine rounding error. 280 | Run( _ 281 | "Curve fitting: lineal fit", _ 282 | "FIT(A;1)", _ 283 | "{{54 + 4.8*x};{0.7024}}", _ 284 | "A={{-2;40};{-1;50};{0;62};{1;58};{2;60}}" _ 285 | ) 286 | Run( _ 287 | "Curve fitting: polynomial fit", _ 288 | "FIT(A;1;4)", _ 289 | "{{62 + 3.6667*x -9.6667*x^2 + 0.3333*x^3 + 1.6667*x^4};{1}}", _ 290 | "A={{-2;40};{-1;50};{0;62};{1;58};{2;60}}" _ 291 | ) 292 | Run( _ 293 | "Curve fitting: exponential fit", _ 294 | "FIT(A;2)", _ 295 | "{{0.102*e^(2.9963*x)};{0.9998}}", _ 296 | "A={{0;0.1};{0.5;0.45};{1;2.15};{1.5;9.15};{2;40.35};{2.5;180.75}}" _ 297 | ) 298 | Run( _ 299 | "Curve fitting: exponential fit-2", _ 300 | "FIT(A;3)", _ 301 | "{{10.4992*(1.7959^x)};{0.9906}}", _ 302 | "A={{0;10};{1;21};{2;35};{3;59};{4;92};{5;200};{6;400};{7;610}}" _ 303 | ) 304 | Run( _ 305 | "Curve fitting: power fit", _ 306 | "FIT(A;4)", _ 307 | "{{7.3799*x^1.9302};{0.9977}}", _ 308 | "A={{2;27.8};{3;62.1};{4;110};{5;161}}" _ 309 | ) 310 | Run( _ 311 | "Curve fitting: logarithmic fit", _ 312 | "FIT(A;5)", _ 313 | "{{0.9521*ln(x)+0.1049};{0.9752}}", _ 314 | "A={{1;0.01};{2;1};{3;1.15};{4;1.3};{5;1.52};{6;1.84};{7;2.01};{8;2.05};{9;2.3};{10;2.25}}" _ 315 | ) 316 | Run( _ 317 | "Multi-variate Linear Regression: nominal predictors with interactions", _ 318 | "MLR(X;Y;True;'X1:X2')", _ 319 | "{{0.8542 + 0.4458*X1 + 0.945*X2 + 0.0792*X1*X2};{0.947;0.9072}}", _ 320 | "X={{1;1};{2;2};{3;3};{4;4};{5;1};{6;2};{7;3};{8;4}};Y={{2;4.1;5.8;7.8;5.5;5.2;8.2;11.1}}" _ 321 | ) 322 | Run( _ 323 | "Multi-variate Linear Regression: nominal predictors with interactions-2", _ 324 | "MLR(X;Y;False;'X1:X2')", _ 325 | "{{{{0.8542};{0.4458};{0.945};{0.0792}}};{0.947;0.9072}}", _ 326 | "X={{1;1};{2;2};{3;3};{4;4};{5;1};{6;2};{7;3};{8;4}};Y={{2;4.1;5.8;7.8;5.5;5.2;8.2;11.1}}" _ 327 | ) 328 | Run( _ 329 | "Multi-variate Linear Regression: named predictors with interactions", _ 330 | "MLR(X;Y;True;'Height:Width;Height:Height';'Height;Width')", _ 331 | "{{2.0875 + 2.08*Height -2.1075*Width -0.37*Height*Height + 0.7575*Height*Width};{0.9638;0.9155}}", _ 332 | "X={{1;1};{2;2};{3;3};{4;4};{5;1};{6;2};{7;3};{8;4}};Y={{2;4.1;5.8;7.8;5.5;5.2;8.2;11.1}}" _ 333 | ) 334 | Run( _ 335 | "Multi-variate Linear Regression: named predictors with interactions-2", _ 336 | "MLR(X;Y;False;'Height:Width;Height:Height';'Height;Width')", _ 337 | "{{{{2.0875};{2.08};{-2.1075};{-0.37};{0.7575}}};{0.9638;0.9155}}", _ 338 | "X={{1;1};{2;2};{3;3};{4;4};{5;1};{6;2};{7;3};{8;4}};Y={{2;4.1;5.8;7.8;5.5;5.2;8.2;11.1}}" _ 339 | ) 340 | Run( _ 341 | "Variables overloading", _ 342 | "SUM(C[0;0];C[1;1])", _ 343 | "14", _ 344 | "C = {{-1;13};{6;15}}" _ 345 | ) 346 | VarOverload("Variables overloading: indirect assignment") 347 | Run( _ 348 | "Excel BETA.DIST function test", _ 349 | "ROUND(IBETA((2-1)/(3-1);8;10);4)", _ 350 | "0.6855" _ 351 | ) 352 | Run( _ 353 | "Excel T.INV function test", _ 354 | "ROUND(TINV(0.75;2;1);8)", _ 355 | "0.81649658" _ 356 | ) 357 | Run( _ 358 | "IRR_ function test", _ 359 | "FORMAT(IRR({{-70000;12000;15000}};true);'Percent')", _ 360 | "'-44.35%'" _ 361 | ) 362 | Run( _ 363 | "INSTR function test", _ 364 | "INSTR('Gear';'e')", _ 365 | "2" _ 366 | ) 367 | 'Analytical Geometry 368 | Run( _ 369 | "Distance between two points", _ 370 | "ROUND(DISTANCE({{3.1441;0}};{{4.45415;3.1441}});4)", _ 371 | "3.4061" _ 372 | ) 373 | Run( _ 374 | "Lines intersection", _ 375 | "MROUND(LINESINTERSECT({{12;0};{0;5}};{{0;1.31004};{0.79693;3.22267}});2)", _ 376 | "{{1.31;4.45}}" _ 377 | ) 378 | Run( _ 379 | "Parallel line", _ 380 | "MROUND(PARALLEL({{12;0};{0;5}};{{3.1441;0}});2)", _ 381 | "{{3.14;0};{0;1.31}}" _ 382 | ) 383 | Run( _ 384 | "Perpendicular line", _ 385 | "MROUND(PERPENDICULAR({{12;0};{0;5}};{{3.1441;0}});2)", _ 386 | "{{3.14;0};{4.45;3.14}}" _ 387 | ) 388 | Run( _ 389 | "Segment Bisector", _ 390 | "MROUND(BISECTOR({{-4;-2}};{{-2;6}});4)", _ 391 | "{{-3;2};{-2;1.75}}" _ 392 | ) 393 | Run( _ 394 | "Angle Bisector", _ 395 | "MROUND(BISECTOR({{-2.4387;6.8161}};{{-4;3}};{{-0.4613;0.8839}});4)", _ 396 | "{{-4;3};{-3.0513;3.3162}}" _ 397 | ) 398 | Run( _ 399 | "Triangle incenter", _ 400 | "MROUND(INCENTER({{0;0}};{{-4;-2}};{{-2;6}});4)", _ 401 | "{{-1.7982;0.7448}}" _ 402 | ) 403 | Run( _ 404 | "Inscribed circle", _ 405 | "MROUND(INCIRCLE({{0;0}};{{-4;-2}};{{-2;6}});4)", _ 406 | "{{-1.7982;0.7448};{1.4704;1.4704}}" _ 407 | ) 408 | Run( _ 409 | "Circumscribed circle", _ 410 | "MROUND(CIRCUMCIRCLE({{0;0}};{{-4;-2}};{{-2;6}});4)", _ 411 | "{{-3.5714;2.1429};{4.165;4.165}}" _ 412 | ) 413 | Run( _ 414 | "Two tangents of a circle", _ 415 | "MROUND(CIRCLETANG({{-4;3}};SQRT(17);{{2;5}});4)", _ 416 | "{{-2.4387;6.8161};{2;5}};{{2;5};{-0.4613;0.8839}}" _ 417 | ) 418 | Run( _ 419 | "Tangent for a point on a circle", _ 420 | "MROUND(CIRCLETANG({{-4;3}};SQRT(17);{{0;4}});4)", _ 421 | "{{0;4};{1;0}}" _ 422 | ) 423 | VALIDATEcircleTangents("Validate circle's computed tangent") 424 | 425 | SF_Exception.debugprint("Passed tests:",sAcum) 426 | SF_Exception.debugprint("Failed tests:",tTotal - sAcum) 427 | SF_Exception.debugprint("Passed tests Ratio:",Round(100*sAcum/tTotal,2) &"%") 428 | SF_Exception.console() 429 | End Sub 430 | 431 | Private Sub Run(testName As String,expr As String, _ 432 | expect As String, Optional varval As String) 433 | On Error GoTo TestFail 434 | 435 | tTotal=tTotal+1 436 | actual = GetResult( _ 437 | expr, varval _ 438 | ) 439 | If expect <> actual Then 440 | SF_Exception.debugprint("x Failed test-> " & testName, expect,"<>",actual) 441 | Else 442 | sAcum=sAcum+1 443 | SF_Exception.debugprint("+ Success test-> " & testName) 444 | End If 445 | 446 | TestExit: 447 | Exit Sub 448 | TestFail: 449 | SF_Exception.debugprint("Test " & testName & " raised an error: #" & err.Number & " - " & err.Description) 450 | Resume TestExit 451 | End Sub 452 | 453 | Private Sub QRdec(testName As String) 454 | On Error GoTo TestFail 455 | Dim expect As String 456 | Dim QRstr As String 457 | Dim QRarr As Variant 458 | Dim oHelper As Object 459 | 460 | tTotal=tTotal+1 461 | 462 | QRstr = GetResult("QR({{12;-51;4};{6;167;-68};{-4;24;-41}})") 463 | Set oHelper = New VBAexpressions 464 | With oHelper 465 | QRarr = .ArrayFromString2(QRstr) 466 | actual = GetResult("MROUND(MMULT(A;B);0)", "A=" & .ArrayToString(QRarr(0)) & ";" & "B=" & .ArrayToString(QRarr(1))) 467 | End With 468 | Set oHelper = Nothing 469 | expect = "{{12;-51;4};{6;167;-68};{-4;24;-41}}" 470 | 471 | If expect <> actual Then 472 | SF_Exception.debugprint("x Failed test " & testName, expect,"<>",actual) 473 | Else 474 | sAcum=sAcum+1 475 | SF_Exception.debugprint("+ Success test " & testName) 476 | End If 477 | 478 | TestExit: 479 | Exit Sub 480 | TestFail: 481 | SF_Exception.debugprint("Test " & testName & " raised an error: #" & err.Number & " - " & err.Description) 482 | Resume TestExit 483 | End Sub 484 | Private Sub VarOverload(testName As String) 485 | On Error GoTo TestFail 486 | Dim expect As String 487 | 488 | tTotal=tTotal+1 489 | Set Evaluator = New VBAexpressions 490 | With Evaluator 491 | .Create "GET('A';{{2;1;3};{3;-2;-1}}); GET('B';{{2;3};{1;-5};{-2;4}})": .Eval 492 | .Create "GET('C';MMULT(A;B))", False: .Eval 493 | .Create "ROUND(SUM(SIN(C[0;0]);SIN(C[1;1]));4)", False: .Eval 494 | actual = .Result 495 | End With 496 | expect = "-0.1912" 497 | 498 | If expect <> actual Then 499 | SF_Exception.debugprint("x Failed test " & testName, expect,"<>",actual) 500 | Else 501 | sAcum=sAcum+1 502 | SF_Exception.debugprint("+ Success test " & testName) 503 | End If 504 | 505 | TestExit: 506 | Exit Sub 507 | TestFail: 508 | SF_Exception.debugprint("Test " & testName & " raised an error: #" & err.Number & " - " & err.Description) 509 | Resume TestExit 510 | End Sub 511 | Private Sub ArrayConstructorsAndParsers(testName As String) 512 | On Error GoTo TestFail 513 | Dim expect As String 514 | Dim jaggedArr() As Variant 515 | 516 | tTotal=tTotal+1 517 | Set Evaluator = New VBAexpressions 518 | With Evaluator 519 | jaggedArr() = .ArrayFromString2("{{1;0;4};{{1;1;6};{2;3}};{3};{2;5}}") 520 | actual = .ArrayToString(jaggedArr) 521 | End With 522 | expect = "{{1;0;4};{{1;1;6};{2;3}};{3};{2;5}}" 523 | 524 | If expect <> actual Then 525 | SF_Exception.debugprint("x Failed test " & testName, expect,"<>",actual) 526 | Else 527 | sAcum=sAcum+1 528 | SF_Exception.debugprint("+ Success test " & testName) 529 | End If 530 | 531 | TestExit: 532 | Exit Sub 533 | TestFail: 534 | SF_Exception.debugprint("Test " & testName & " raised an error: #" & err.Number & " - " & err.Description) 535 | Resume TestExit 536 | End Sub 537 | Private Sub DEVZONE() 538 | GlobalScope.BasicLibraries.loadLibrary("VBAExpressionsLib") 539 | GlobalScope.BasicLibraries.loadLibrary("ScriptForge") 540 | createscriptservice("Exception") 541 | SF_Exception.consoleClear() 542 | 'CODE HERE 543 | 544 | SF_Exception.console() 545 | End Sub 546 | 547 | ''' <summary> 548 | ''' The tangents of a circle are, in fact, perperdicular to 549 | ''' circles's radius. So we can check the computations. 550 | ''' </summary> 551 | Private Sub VALIDATEcircleTangents(testName As String) 552 | On Error GoTo TestFail 553 | Dim expect As String 554 | 555 | tTotal=tTotal+1 556 | Set Evaluator = New VBAexpressions 557 | With Evaluator 558 | .Create "GET('tangentLine';" _ 559 | & "GETFROMLIST(CIRCLETANG(GET(" _ 560 | & "'point';{{-4;3}});GET('radius';ROUND(SQRT(17);4));{{2;5}})" _ 561 | & ";0))": .Eval 562 | 'select one on the tangent lines and compute a perpendicular 563 | 'passing through <<point>> 564 | .Create "GET('perpLine';PERPENDICULAR(tangentLine;point))", False: .Eval 565 | .Create "GET('intersection';LINESINTERSECT(tangentLine;perpLine))", False: .Eval 566 | .Create "GET('distance.point.intersection';ROUND(DISTANCE(point;intersection);4))", False: .Eval 567 | .Create "GET('valid.tangent';distance.point.intersection=radius)", False: .Eval 568 | actual = .result 569 | End With 570 | expect = "True" 571 | 572 | If expect <> actual Then 573 | SF_Exception.debugprint("x Failed test " & testName, expect,"<>",actual) 574 | Else 575 | sAcum=sAcum+1 576 | SF_Exception.debugprint("+ Success test " & testName) 577 | End If 578 | 579 | TestExit: 580 | Exit Sub 581 | TestFail: 582 | SF_Exception.debugprint("Test " & testName & " raised an error: #" & err.Number & " - " & err.Description) 583 | Resume TestExit 584 | End Sub 585 | -------------------------------------------------------------------------------- /src/LO Basic/VBAExpressionsLib/UDFunctions.xba: -------------------------------------------------------------------------------- 1 | 2 | 3 | Option Explicit 4 | option Compatible 5 | Option VBASupport 1 6 | option ClassModule 7 | '# 8 | '//////////////////////////////////////////////////////////////////////////////////////////// 9 | ' Copyright © 2024-2025 W. García 10 | ' GPL-3.0 license | https://www.gnu.org/licenses/gpl-3.0.html/ 11 | ' https://github.com/ws-garcia 12 | '//////////////////////////////////////////////////////////////////////////////////////////// 13 | '# 14 | ' GENERAL INFO: 15 | ' Class module developed to provide samples of user defined functions (UDF). 16 | '/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 17 | '# 18 | Private Const Apostrophe As String = "'" 19 | Private strVBA As New VBAstrHelper 20 | 21 | Public Function GCD(ByRef aValues As Variant) As Long 'Expected an array 22 | Dim i As Long 23 | Dim tmpResult As Long 24 | 25 | tmpResult = 0 26 | For i = LBound(aValues) To UBound(aValues) 27 | tmpResult = getGCD(tmpResult, CLng(aValues(i))) 28 | Next i 29 | GCD = tmpResult 30 | End Function 31 | 32 | Private Function getGCD(a As Long, b As Long) As Long 33 | Do while (a > 0 And b > 0) 34 | If (a > b) Then 35 | a = a Mod b 36 | Else 37 | b = b Mod a 38 | End If 39 | Loop 40 | If a = 0 Then 41 | getGCD = b: Exit Function 42 | End If 43 | getGCD = a 44 | End Sub 45 | 46 | ''' <summary> 47 | ''' List is expected to be an array. The last element will be used as 48 | ''' the concatenation string. 49 | ''' </summary> 50 | Public Function Concat(List As Variant) As String 51 | Dim startIdx As Long 52 | Dim endIdx As Long 53 | Dim i As Long 54 | Dim tmpResult As String 55 | Dim joinString As String 56 | 57 | startIdx = LBound(List) 58 | endIdx = UBound(List) 59 | joinString = strVBA.MidB(List(endIdx), 3, strVBA.LenB2(List(endIdx)) - 4) 60 | tmpResult = strVBA.MidB(List(startIdx), 3, strVBA.LenB2(List(startIdx)) - 4) 61 | For i = startIdx + 1 To endIdx - 1 62 | If AscW(List(i)) = 39 Then ' ['] 63 | tmpResult = tmpResult & _ 64 | joinString & _ 65 | strVBA.MidB(List(i), 3, strVBA.LenB2(List(i)) - 4) 66 | Else 67 | tmpResult = tmpResult & _ 68 | joinString & _ 69 | List(i) 70 | End If 71 | Next i 72 | Concat = Apostrophe & tmpResult & Apostrophe 73 | End Function 74 | Public Function SimpleProduct(ByRef aValues As Variant) As Double 75 | Dim firstNumber As Double 76 | Dim secondNumber As Double 77 | 78 | firstNumber = CDbl(aValues(LBound(aValues))) 79 | secondNumber = CDbl(aValues(UBound(aValues))) 80 | SimpleProduct = firstNumber * secondNumber 81 | End Function 82 | -------------------------------------------------------------------------------- /src/LO Basic/VBAExpressionsLib/VBAcallBack.xba: -------------------------------------------------------------------------------- 1 | 2 | 3 | Option Explicit 4 | option Compatible 5 | option ClassModule 6 | '# 7 | '//////////////////////////////////////////////////////////////////////////////////////////// 8 | ' Copyright © 2024-2025 W. García 9 | ' GPL-3.0 license | https://www.gnu.org/licenses/gpl-3.0.html/ 10 | ' https://github.com/ws-garcia 11 | '//////////////////////////////////////////////////////////////////////////////////////////// 12 | '# 13 | ' GENERAL INFO: 14 | ' Class module developed to provide a way to extend the VBAexpression.cls and allow methods 15 | ' call back for user defined functions. See: https://stackoverflow.com/a/48372415 16 | ' 17 | ' Users can register custom modules to expose and use their functions for throght the 18 | ' VBAcallBack.cls module. All UDFs must have a single Variant argument that will receive a 19 | ' one-dimensional array of strings (one element for each function argument). 20 | ' 21 | ' For example, if the functions to be used are in a class module called UDFunctions.cls, the 22 | ' line ['Public UserDefFunctions As New UDFunctions'] will be sufficient to expose all its 23 | ' internal functions. 24 | ' 25 | ' After doing this, the user must "bind" a procedure to the desired methods through the 26 | ' DeclareUDF method of the VBAexpression.cls: 27 | ' 28 | ' DeclareUDF UDFname, UDFlib 29 | ' 30 | ' In the above expression, the UDFname parameter can be an array of function names or a 31 | ' string function name. The UDFlib is a string with the name of the class module to be linked. 32 | '//////////////////////////////////////////////////////////////////////////////////////////// 33 | '@-------------------------------------------------------------------- 34 | ' Expose functions defined in the UDFunctions.cls 35 | Public UserDefFunctions As New UDFunctions 36 | -------------------------------------------------------------------------------- /src/LO Basic/VBAExpressionsLib/VBAexpressionsScope.xba: -------------------------------------------------------------------------------- 1 | 2 | 3 | Option Explicit 4 | option Compatible 5 | Option VBASupport 1 6 | option ClassModule 7 | Option Base 0 8 | '# 9 | '/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 10 | ' Copyright © 2024-2025 W. García 11 | ' GPL-3.0 license | https://www.gnu.org/licenses/gpl-3.0.html/ 12 | ' https://github.com/ws-garcia 13 | '/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 14 | '# 15 | ' INFO: 16 | ' Class module developed to define constants and variable scopes for expressions, so that several expressions 17 | ' can share the same variables without the need to redefine each of them. 18 | ' 19 | '/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 20 | '# 21 | '/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 22 | ' VARIABLES: 23 | Private e As Double 24 | Private pi As Double 25 | Private P_CONSTANTS As ClusterBuffer 26 | Private P_EXPR_VARIABLES As ClusterBuffer 27 | Private arrHelper As Object 28 | Private strVBA As New VBAstrHelper 29 | '/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 30 | '# 31 | '/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 32 | 'TYPES: 33 | Type ClusterBuffer 34 | Capacity As Long 35 | aindex As Long 36 | Storage As Variant '() As ClusterItem 37 | End Type ' ClusterBuffer 38 | Type ClusterItem 39 | aindex As Long 40 | aName As String 41 | value As String 42 | Assigned As Boolean 43 | value2 As Variant 'Array representation for the value 44 | IsArray As Boolean 45 | End Type ' ClusterBuffer 46 | '/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 47 | '# 48 | '/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 49 | ' PROPERTIES: 50 | 51 | ''' <summary> 52 | ''' Returns True if the given variable has an array assigned 53 | ''' </summary> 54 | 'Public Property Get AssignedArray(aVarKey As Variant) As Boolean 55 | Public Function GetAssignedArray(aVarKey As Variant) As Boolean 56 | If Not IsNumeric(aVarKey) Then 57 | Dim ValueIdx As Long 58 | 59 | ValueIdx = GetCBItemIdx(P_EXPR_VARIABLES, CStr(aVarKey)) 60 | If ValueIdx > -1 Then 61 | GetAssignedArray = P_EXPR_VARIABLES.Storage(ValueIdx).IsArray 62 | End If 63 | Else 64 | GetAssignedArray = P_EXPR_VARIABLES.Storage(CLng(aVarKey)).IsArray 65 | End If 66 | End Function 67 | 68 | ''' <summary> 69 | ''' Gets the constants collection. By default this is pre-populated with PI and e. 70 | ''' </summary> 71 | Public Property Get Constants() As Collection 72 | Dim i As Long 73 | 74 | Set Constants = New Collection 75 | For i = 0 To P_CONSTANTS.aindex 76 | Constants.Add (P_CONSTANTS.Storage(i).value, P_CONSTANTS.Storage(i).aName) 77 | Next i 78 | End Property 79 | 80 | ''' <summary> 81 | ''' Gets a string with the variables values used for the last evaluation. 82 | ''' </summary> 83 | Public Property Get CurrentVarValues() As String 84 | Dim i As Long 85 | Dim tmpResult As String 86 | 87 | For i = 0 To P_EXPR_VARIABLES.aindex 88 | If tmpResult = vbNullString Then 89 | tmpResult = P_EXPR_VARIABLES.Storage(i).aName & " = " & _ 90 | P_EXPR_VARIABLES.Storage(i).value 91 | Else 92 | tmpResult = tmpResult & "; " & P_EXPR_VARIABLES.Storage(i).aName & " = " & _ 93 | P_EXPR_VARIABLES.Storage(i).value 94 | End If 95 | Next i 96 | CurrentVarValues = tmpResult 97 | End Property 98 | 99 | ''' <summary> 100 | ''' Gets a string with the variables values used for the last evaluation. 101 | ''' </summary> 102 | Public Property Get CurrentVariables() As String 103 | Dim i As Long 104 | Dim tmpResult As String 105 | 106 | For i = 0 To P_EXPR_VARIABLES.aindex 107 | If tmpResult = vbNullString Then 108 | tmpResult = P_EXPR_VARIABLES.Storage(i).aName 109 | Else 110 | tmpResult = tmpResult & "; " & P_EXPR_VARIABLES.Storage(i).aName 111 | End If 112 | Next i 113 | CurrentVariables = tmpResult 114 | End Property 115 | 116 | ''' <summary> 117 | ''' Returns 'True' if all stored variables have a value or when there 118 | ''' are no stored variables, 'False' when the value of any variable is missing. 119 | ''' </summary> 120 | Public Function DefinedScope() As Boolean 121 | If P_EXPR_VARIABLES.aindex > -1 Then 122 | Dim i As Long 123 | Dim cviCounter As Long 124 | 125 | For i = 0 To P_EXPR_VARIABLES.aindex 126 | If P_EXPR_VARIABLES.Storage(i).Assigned Then 127 | cviCounter = cviCounter + 1 128 | End If 129 | Next i 130 | DefinedScope = (cviCounter = P_EXPR_VARIABLES.aindex + 1) 131 | Else 132 | DefinedScope = True 133 | End If 134 | End Function 135 | 136 | ''' <summary> 137 | ''' Gets the count of stored variable. 138 | ''' </summary> 139 | Public Property Get VariablesCount() As Long 140 | VariablesCount = P_EXPR_VARIABLES.aindex + 1 141 | End Property 142 | 143 | ''' <summary> 144 | ''' Gets or sets the current value from/to the given variable. 145 | ''' If 'aVarKey' is numeric, the argument is treated as an index. 146 | ''' </summary> 147 | 'Public Property Get VarValue(aVarKey As Variant) As String 148 | Public Function GetVarValue(aVarKey As Variant) As String 149 | If Not IsNumeric(aVarKey) Then 150 | Dim ValueIdx As Long 151 | 152 | ValueIdx = GetCBItemIdx(P_EXPR_VARIABLES, CStr(aVarKey)) 153 | If ValueIdx > -1 Then 154 | GetVarValue = P_EXPR_VARIABLES.Storage(ValueIdx).value 155 | End If 156 | Else 157 | GetVarValue = P_EXPR_VARIABLES.Storage(CLng(aVarKey)).value 158 | End If 159 | End Function 160 | 161 | 'Public Property Let VarValue(aVarKey As Variant, aVarValue As String) 162 | Public Sub LetVarValue(aVarKey As Variant, aVarValue As String) 163 | Dim ValueIdx As Long 164 | Dim ConstKey As String 165 | If Not IsNumeric(aVarKey) Then 166 | ValueIdx = GetCBItemIdx(P_EXPR_VARIABLES, CStr(aVarKey)) 167 | If ValueIdx > -1 Then 168 | P_EXPR_VARIABLES.Storage(ValueIdx).value = aVarValue 169 | P_EXPR_VARIABLES.Storage(ValueIdx).Assigned = True 170 | Else 171 | AddVariable CStr(aVarKey), ConstKey 172 | Me.LetVarValue(aVarKey,aVarValue) 173 | End If 174 | Else 175 | ValueIdx = CLng(aVarKey) 176 | If ValueIdx > -1 And ValueIdx <= P_EXPR_VARIABLES.aindex Then 177 | P_EXPR_VARIABLES.Storage(ValueIdx).value = aVarValue 178 | P_EXPR_VARIABLES.Storage(ValueIdx).Assigned = True 179 | End If 180 | End If 181 | End Sub 182 | 183 | ''' <summary> 184 | ''' Gets the current value from an instance for the given variable. 185 | ''' If 'aVarKey' is numeric, the argument is treated as an index. 186 | ''' 187 | ''' NOTE: this version use Variant data type to handle arrays. 188 | ''' The string array representation is retrieved as usual if the 189 | ''' parameter "treatAsArray" is set to False, an array is returned 190 | ''' otherwise. 191 | ''' </summary> 192 | 'Public Property Get VarValue2(aVarKey As Variant, treatAsArray As Boolean) As Variant 193 | Public Function GetVarValue2(aVarKey As Variant, treatAsArray As Boolean) As Variant 194 | If Not IsNumeric(aVarKey) Then 195 | Dim ValueIdx As Long 196 | 197 | ValueIdx = GetCBItemIdx(P_EXPR_VARIABLES, CStr(aVarKey)) 198 | If ValueIdx > -1 Then 199 | If treatAsArray Then 200 | If P_EXPR_VARIABLES.Storage(ValueIdx).IsArray Then 201 | GetVarValue2 = P_EXPR_VARIABLES.Storage(ValueIdx).value2 202 | End If 203 | Else 204 | GetVarValue2 = P_EXPR_VARIABLES.Storage(ValueIdx).value 205 | End If 206 | End If 207 | Else 208 | If treatAsArray Then 209 | If P_EXPR_VARIABLES.Storage(CLng(aVarKey)).IsArray Then 210 | GetVarValue2 = P_EXPR_VARIABLES.Storage(CLng(aVarKey)).value2 211 | End If 212 | Else 213 | GetVarValue2 = P_EXPR_VARIABLES.Storage(CLng(aVarKey)).value 214 | End If 215 | End If 216 | End Function 217 | 218 | ''' <summary> 219 | ''' Gets or sets the current value from/to the given variable. 220 | ''' If 'aVarKey' is numeric, the argument is treated as an index. 221 | ''' 222 | ''' NOTE: this version use variant data type to handle arrays. 223 | ''' The array string is stored as usual, but a conversion is 224 | ''' also perfomed to allocate an array created by parsing the 225 | ''' given string when the parameter "treatAsArray" is set to True. 226 | ''' </summary> 227 | 'Public Property Let VarValue2(aVarKey As Variant, treatAsArray As Boolean, aVarValue As Variant) 228 | Public Sub LetVarValue2(aVarKey As Variant, treatAsArray As Boolean, aVarValue As Variant) 229 | If arrHelper Is Nothing Then Set arrHelper = New VBAexpressions 230 | If Not IsNumeric(aVarKey) Then 231 | Dim ValueIdx As Long 232 | Dim ConstKey As String 233 | 234 | ValueIdx = GetCBItemIdx(P_EXPR_VARIABLES, CStr(aVarKey)) 235 | If ValueIdx > -1 Then 236 | P_EXPR_VARIABLES.Storage(ValueIdx).IsArray = treatAsArray 237 | P_EXPR_VARIABLES.Storage(ValueIdx).value = aVarValue 238 | P_EXPR_VARIABLES.Storage(ValueIdx).Assigned = True 239 | If treatAsArray Then 240 | P_EXPR_VARIABLES.Storage(ValueIdx). _ 241 | value2 = arrHelper.ArrayFromString(CStr(aVarValue)) 242 | End If 243 | Else 244 | AddVariable CStr(aVarKey), ConstKey 245 | Me.LetVarValue2(aVarKey, treatAsArray, aVarValue) 246 | End If 247 | Else 248 | ValueIdx = CLng(aVarKey) 249 | If ValueIdx > -1 And ValueIdx <= P_EXPR_VARIABLES.aindex Then 250 | P_EXPR_VARIABLES.Storage(ValueIdx).IsArray = treatAsArray 251 | P_EXPR_VARIABLES.Storage(ValueIdx).value = aVarValue 252 | P_EXPR_VARIABLES.Storage(ValueIdx).Assigned = True 253 | If treatAsArray Then 254 | P_EXPR_VARIABLES.Storage(ValueIdx). _ 255 | value2 = arrHelper.ArrayFromString(CStr(aVarValue)) 256 | End If 257 | End If 258 | End If 259 | End Sub 260 | 261 | '/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 262 | '# 263 | '/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 264 | ' METHODS: 265 | 266 | Public Sub AddConstant(aValue As String, aKey As String) 267 | Dim ConstIdx As Long 268 | 269 | ConstIdx = GetCBItemIdx(P_CONSTANTS, aKey) 270 | If ConstIdx = -1 Then 'Ensure uniqueness 271 | AppendToCBbuffer P_CONSTANTS, aKey, aValue 272 | End If 273 | End Sub 274 | 275 | Public Sub AddVariable(ByRef variable As String, ByRef aKey As String) 276 | Dim varIdx As Long 277 | 278 | aKey = Cast(variable) 279 | varIdx = GetCBItemIdx(P_EXPR_VARIABLES, aKey) 280 | If varIdx = -1 Then 'Ensure uniqueness 281 | AppendToCBbuffer P_EXPR_VARIABLES, aKey 282 | varIdx = GetCBItemIdx(P_CONSTANTS, aKey) 283 | If varIdx > -1 Then 'Assign the value from constants 284 | P_EXPR_VARIABLES.Storage(P_EXPR_VARIABLES.aindex).value = P_CONSTANTS.Storage(varIdx).value 285 | P_EXPR_VARIABLES.Storage(P_EXPR_VARIABLES.aindex).Assigned = True 286 | End If 287 | End If 288 | End Sub 289 | 290 | Private Sub AppendToCBbuffer(ByRef aBuffer As ClusterBuffer, ByRef ItemName As String, Optional ByRef ItemValue As String = vbNullString) 291 | aBuffer.aindex = aBuffer.aindex + 1 292 | If aBuffer.aindex = aBuffer.Capacity Then ExpandBuffer(aBuffer) 293 | aBuffer.Storage(aBuffer.aindex).aindex = aBuffer.aindex 294 | aBuffer.Storage(aBuffer.aindex).Assigned = (ItemValue <> vbNullString) 295 | aBuffer.Storage(aBuffer.aindex).aName = ItemName 296 | aBuffer.Storage(aBuffer.aindex).value = ItemValue 297 | End Sub 298 | 299 | Private Function Cast(ByRef expression As String) As String 300 | If IsPI(expression) Then 301 | Cast = LCase$(expression) 'Case insensitive for PI 302 | Else 303 | Cast = expression 304 | End If 305 | End Function 306 | 307 | Public Sub ConstantsInit() 308 | InitCBbuffer P_CONSTANTS 309 | '@-------------------------------------------------------------------- 310 | ' Save predefined constants 311 | AppendToCBbuffer P_CONSTANTS, "pi", CStr(pi) 312 | AppendToCBbuffer P_CONSTANTS, "e", CStr(e) 313 | End Sub 314 | 315 | Public Function CopyScope(ByRef sourceScope As Object) As Object 316 | Dim i As Long 317 | Dim tmpValue As String 318 | Dim tmpIdx As Long 319 | 320 | If TypeName(sourceScope)=TypeName(me) Then 321 | For i = 0 To P_EXPR_VARIABLES.aindex 322 | tmpIdx = sourceScope.VarIndex(P_EXPR_VARIABLES.Storage(i).aName) 323 | If tmpIdx > -1 Then 324 | tmpValue = sourceScope.GetVarValue(tmpIdx) 325 | If tmpValue <> vbNullString Then 326 | me.LetVarValue(i, tmpValue) 327 | End If 328 | End If 329 | Next 330 | Set CopyScope = Me 331 | End If 332 | End Function 333 | 334 | Public Function CopyToScope() As Object 335 | Dim i As Long 336 | Dim tmpValue As String 337 | Dim tmpName As String 338 | Dim tmpScope As VBAexpressionsScope 339 | 340 | Set tmpScope = New VBAexpressionsScope 341 | For i = 0 To P_EXPR_VARIABLES.aindex 342 | tmpName = P_EXPR_VARIABLES.Storage(i).aName 343 | tmpValue = P_EXPR_VARIABLES.Storage(i).value 344 | If tmpValue <> vbNullString Then 345 | tmpScope.LetVarValue(tmpName, tmpValue) 346 | End If 347 | Next 348 | Set CopyToScope = tmpScope 349 | End Function 350 | 351 | Private Sub ExpandCBbuffer(ByRef aBuffer As ClusterBuffer) 352 | Dim tmpBuffer() As ClusterItem 353 | 354 | aBuffer.Capacity = 2 * (aBuffer.Capacity + 1) 355 | tmpBuffer = aBuffer.Storage 356 | ReDim Preserve tmpBuffer(0 To aBuffer.Capacity - 1) 357 | aBuffer.Storage = tmpBuffer 358 | End Sub 359 | 360 | Public Sub FillPredefinedVars() 361 | Dim i As Long 362 | Dim tmpIdx As Long 363 | 364 | For i = 0 To P_EXPR_VARIABLES.aindex 365 | tmpIdx = GetCBItemIdx(P_CONSTANTS, P_EXPR_VARIABLES.Storage(i).aName) 366 | If tmpIdx > -1 Then 'The variable is a defined constant 367 | P_EXPR_VARIABLES.Storage(i).value = P_CONSTANTS.Storage(tmpIdx).value 368 | P_EXPR_VARIABLES.Storage(i).Assigned = True 369 | End If 370 | Next i 371 | End Sub 372 | Private Function GetCBItemIdx(ByRef cbBuffer As ClusterBuffer, ByRef ItemName As String) As Long 373 | Dim i As Long 374 | Dim tmpResult As Boolean 375 | Dim tmpItemName As String 376 | 377 | If strVBA.LenB2(ItemName) Then 378 | Select Case AscW(ItemName) 379 | Case 43, 45 'Unary expression 380 | tmpItemName = strVBA.MidB(ItemName, 3) 381 | Case Else 382 | tmpItemName = ItemName 383 | End Select 384 | If cbBuffer.aindex > -1 Then 385 | i = 0 386 | Do 387 | tmpResult = (cbBuffer.Storage(i).aName = tmpItemName) 388 | i = i + 1 389 | Loop While i <= cbBuffer.aindex And Not tmpResult 390 | End If 391 | If tmpResult Then 392 | GetCBItemIdx = i - 1 393 | Else 394 | GetCBItemIdx = -1 395 | End If 396 | Else 397 | GetCBItemIdx = -1 398 | End If 399 | End Function 400 | 401 | Private Sub InitCBbuffer(ByRef aBuffer As ClusterBuffer) 402 | Dim tmpBuffer() As ClusterItem 403 | 404 | aBuffer.Capacity = 128 405 | ReDim tmpBuffer(0 To aBuffer.Capacity - 1) 406 | Set aBuffer.Storage = tmpBuffer 407 | aBuffer.aindex = -1 408 | End Sub 409 | 410 | Public Function IsConstant(aVarName As String) As Boolean 411 | IsConstant = GetCBItemIdx(P_CONSTANTS, aVarName) > -1 412 | End Function 413 | 414 | Private Function IsPI(ByRef varName As String) As Boolean 415 | IsPI = (varName Like "[Pp][Ii]") 416 | End Function 417 | 418 | Public Sub VariablesInit() 419 | InitCBbuffer P_EXPR_VARIABLES 420 | End Sub 421 | 422 | ''' <summary> 423 | ''' Returns the index of a given variable or constant named 'ItemName' 424 | ''' </summary> 425 | Public Function VarIndex(ByRef ItemName As String, _ 426 | Optional findConstant As Boolean = False) As Long 427 | If Not findConstant Then 428 | VarIndex = GetCBItemIdx(P_EXPR_VARIABLES, ItemName) 429 | Else 430 | VarIndex = GetCBItemIdx(P_CONSTANTS, ItemName) 431 | End If 432 | End Function 433 | '/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 434 | '# 435 | '/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 436 | ''' <summary> 437 | ''' Initializes this instance. 438 | ''' </summary> 439 | Private Sub Class_Initialize() 440 | pi = 4 * Atn(1) 441 | e = Exp(1) 442 | ConstantsInit 443 | VariablesInit 444 | End Sub 445 | -------------------------------------------------------------------------------- /src/LO Basic/VBAExpressionsLib/VBAstrHelper.xba: -------------------------------------------------------------------------------- 1 | 2 | 3 | Option Explicit 4 | option Compatible 5 | Option VBASupport 1 6 | option ClassModule 7 | Option Base 0 8 | '# 9 | '/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 10 | ' Copyright © 2024-2025 W. García 11 | ' GPL-3.0 license | https://www.gnu.org/licenses/gpl-3.0.html/ 12 | ' https://github.com/ws-garcia 13 | '/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 14 | '# 15 | ' INFO: 16 | ' Class module developed to define string functions missing in LO BASIC. 17 | ' 18 | '/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 19 | '# 20 | '/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 21 | ' VBA STRING HELPERS: 22 | Public Function InStrB(aStart As Long, aString1 As String, aString2 As String) As Long 23 | Dim tmpResult As Long 24 | Dim fStart As Long 25 | 26 | If aStart And 1 Then 27 | fStart = (aStart + 1) / 2 28 | Else 29 | fStart = aStart / 2 + 1 30 | End If 31 | tmpResult = InStr(fStart, aString1, aString2) * 2 32 | If tmpResult > 0 Then 33 | InStrB = tmpResult - 1 34 | Else 35 | InStrB = tmpResult 36 | End If 37 | End Function 38 | Public Function MidB(aString As String, aStart As Long, Optional aLength As Long = -1) As String 39 | If aLength >= 0 Then 40 | MidB = Mid(aString, (aStart + 1) / 2, aLength / 2) 41 | Else 42 | MidB = Mid(aString, (aStart + 1) / 2) 43 | End If 44 | End Function 45 | Public Function LenB2(aString As String) As Long 46 | LenB2 = Len(aString)*2 47 | End Function 48 | -------------------------------------------------------------------------------- /src/LO Basic/VBAExpressionsLib/dialog.xlb: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /src/LO Basic/VBAExpressionsLib/script.xlb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/LO Basic/release-notes_en.txt: -------------------------------------------------------------------------------- 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. 11 | 12 | ## Download 13 | https://github.com/ws-garcia/VBA-Expressions/releases/download/v3.2.11/VBAExpressions.oxt -------------------------------------------------------------------------------- /src/Tests/TestRunner.bas: -------------------------------------------------------------------------------- 1 | Attribute VB_Name = "TestRunner" 2 | Option Explicit 3 | Option Private Module 4 | Private Evaluator As VBAexpressions 5 | Private expected As String 6 | Private actual As String 7 | 8 | '@TestModule 9 | '@Folder("Tests") 10 | 11 | Private Assert As Object 12 | Private Fakes As Object 13 | 14 | Public Sub ShowEvalForm(control As IRibbonControl) 15 | EvalForm_frm.Show False 16 | End Sub 17 | 18 | '@ModuleInitialize 19 | Private Sub ModuleInitialize() 20 | 'this method runs once per module. 21 | Set Assert = CreateObject("Rubberduck.AssertClass") 22 | Set Fakes = CreateObject("Rubberduck.FakesProvider") 23 | End Sub 24 | 25 | '@ModuleCleanup 26 | Private Sub ModuleCleanup() 27 | 'this method runs once per module. 28 | Set Assert = Nothing 29 | Set Fakes = Nothing 30 | End Sub 31 | 32 | '@TestInitialize 33 | Private Sub TestInitialize() 34 | 'This method runs before every test in the module.. 35 | End Sub 36 | 37 | '@TestCleanup 38 | Private Sub TestCleanup() 39 | 'this method runs after every test in the module. 40 | End Sub 41 | 42 | Private Function GetResult(expression As String _ 43 | , Optional VariablesValues As String = vbNullString) As String 44 | On Error Resume Next 45 | Set Evaluator = New VBAexpressions 46 | 47 | With Evaluator 48 | .Create expression 49 | GetResult = .Eval(VariablesValues) 50 | End With 51 | End Function 52 | 53 | '@TestMethod("Parentheses") 54 | Private Sub Parentheses() 55 | On Error GoTo TestFail 56 | 57 | actual = GetResult( _ 58 | "(((((((((((-123.456-654.321)*1.1)*2.2)*3.3)+4.4)+5.5)+6.6)*7.7)*8.8)+9.9)+10.10)" _ 59 | ) 60 | expected = "-419741.48578672" 61 | Assert.AreEqual expected, actual 62 | 63 | TestExit: 64 | Exit Sub 65 | TestFail: 66 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 67 | Resume TestExit 68 | End Sub 69 | '@TestMethod("Parentheses and Single Function") 70 | Private Sub ParenthesesAndSingleFunction() 71 | On Error GoTo TestFail 72 | 73 | actual = GetResult( _ 74 | "(1+(2-5)*3+8/(5+3)^2)/sqr(4^2+3^2)" _ 75 | ) 76 | expected = "-1.575" 77 | Assert.AreEqual expected, actual 78 | 79 | TestExit: 80 | Exit Sub 81 | TestFail: 82 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 83 | Resume TestExit 84 | End Sub 85 | '@TestMethod("Functions with More than One Argument") 86 | Private Sub FunctionsWithMoreThanOneArgument() 87 | On Error GoTo TestFail 88 | 89 | actual = GetResult( _ 90 | "min(5;6;max(-0.6;-3))" _ 91 | ) 92 | expected = "-0.6" 93 | Assert.AreEqual expected, actual 94 | 95 | TestExit: 96 | Exit Sub 97 | TestFail: 98 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 99 | Resume TestExit 100 | End Sub 101 | '@TestMethod("Nested Functions") 102 | Private Sub NestedFunctions() 103 | On Error GoTo TestFail 104 | 105 | actual = GetResult( _ 106 | "tan(sqr(abs(ln(x))))" _ 107 | , "x = " & Exp(1) _ 108 | ) 109 | expected = "1.5574077246549" 110 | Assert.AreEqual expected, actual 111 | 112 | TestExit: 113 | Exit Sub 114 | TestFail: 115 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 116 | Resume TestExit 117 | End Sub 118 | '@TestMethod("Floating Point Arithmetic") 119 | Private Sub FloatingPointArithmetic() 120 | On Error GoTo TestFail 121 | 122 | actual = GetResult( _ 123 | "(1.434E3+1000)*2/3.235E-5" _ 124 | ) 125 | expected = "150479134.46677" 126 | Assert.AreEqual expected, actual 127 | 128 | TestExit: 129 | Exit Sub 130 | TestFail: 131 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 132 | Resume TestExit 133 | End Sub 134 | '@TestMethod("Exponentiation Precedence") 135 | Private Sub ExponentiationPrecedence() 136 | On Error GoTo TestFail 137 | 138 | actual = GetResult( _ 139 | "4^3^2" _ 140 | ) 141 | expected = "262144" 142 | Assert.AreEqual expected, actual 143 | 144 | TestExit: 145 | Exit Sub 146 | TestFail: 147 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 148 | Resume TestExit 149 | End Sub 150 | '@TestMethod("Factorials") 151 | Private Sub Factorials() 152 | On Error GoTo TestFail 153 | 154 | actual = GetResult( _ 155 | "25!/(24!)" _ 156 | ) 157 | expected = "25" 158 | Assert.AreEqual expected, actual 159 | 160 | TestExit: 161 | Exit Sub 162 | TestFail: 163 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 164 | Resume TestExit 165 | End Sub 166 | '@TestMethod("Precedence") 167 | Private Sub Precedence() 168 | On Error GoTo TestFail 169 | 170 | actual = GetResult( _ 171 | "5avg(2;abs(-3-7tan(5));9)-12pi-e+(7/sin(30)-4!)*min(cos(30);cos(150))" _ 172 | ) 173 | expected = "7.56040693890688" 174 | Assert.AreEqual expected, actual 175 | 176 | TestExit: 177 | Exit Sub 178 | TestFail: 179 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 180 | Resume TestExit 181 | End Sub 182 | '@TestMethod("Variables") 183 | Private Sub Variables() 184 | On Error GoTo TestFail 185 | 186 | actual = GetResult( _ 187 | "Pi.e * 5.2Pie.1 + 3.1Pie" _ 188 | , "Pi.e = 1; Pie.1 = 2; Pie = 3" _ 189 | ) 190 | expected = "19.7" 191 | Assert.AreEqual expected, actual 192 | 193 | TestExit: 194 | Exit Sub 195 | TestFail: 196 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 197 | Resume TestExit 198 | End Sub 199 | '@TestMethod("UDFs and Basic Array Functions") 200 | Private Sub UDFsAndArrays() 201 | On Error GoTo TestFail 202 | '/////////////////////////////////////////////////////////////////////////////////// 203 | ' For illustrative purposes only. These UDFs are already implemented. 204 | ' 205 | ' Dim UDFnames() As Variant 206 | ' UDFnames() = Array("GCD", "DET") 207 | ' 208 | ' Evaluator.DeclareUDF UDFnames, "UserDefFunctions" 'Declaring the UDFs. This need 209 | 'an instance in the VBAcallBack 210 | 'class module. 211 | ' 212 | '/////////////////////////////////////////////////////////////////////////////////// 213 | actual = GetResult( _ 214 | "GCD(1280;240;100;30*cos(0);10*DET({{sin(atn(1)*2); 0; 0}; {0; 2; 0}; {0; 0; 3}}))" _ 215 | ) 216 | expected = "10" 217 | Assert.AreEqual expected, actual 218 | 219 | TestExit: 220 | Exit Sub 221 | TestFail: 222 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 223 | Resume TestExit 224 | End Sub 225 | '@TestMethod("Logical Operators with Numeric Output") 226 | Private Sub LogicalOperatorsNumericOutput() 227 | On Error GoTo TestFail 228 | 229 | actual = GetResult( _ 230 | "(x<=0)* x^2 + (x>0 & x<=1)* Ln(x+1) + (x>1)* Sqr(x-Ln(2))" _ 231 | , "x = 6" _ 232 | ) 233 | expected = "2.30366074313039" 234 | Assert.AreEqual expected, actual 235 | 236 | TestExit: 237 | Exit Sub 238 | TestFail: 239 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 240 | Resume TestExit 241 | End Sub 242 | '@TestMethod("Logical Operators with Boolean Output") 243 | Private Sub TestLogicalOperatorsBooleanOutput() 244 | On Error GoTo TestFail 245 | 246 | actual = GetResult( _ 247 | "x>0 & Sqr(x-Ln(2))>=3 | tan(x)<0" _ 248 | , "x = 6" _ 249 | ) 250 | expected = "True" 251 | Assert.AreEqual expected, actual 252 | 253 | TestExit: 254 | Exit Sub 255 | TestFail: 256 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 257 | Resume TestExit 258 | End Sub 259 | '@TestMethod("Trig Functions") 260 | Private Sub TestTrigFunctions() 261 | On Error GoTo TestFail 262 | 263 | actual = GetResult( _ 264 | "ROUND(tan(pi/4)^3-((3*sin(pi/4)-sin(3*pi/4))/(3*cos(pi/4)+cos(3*pi/4)));14)" _ 265 | ) 266 | expected = "0" 267 | Assert.AreEqual expected, actual 268 | 269 | TestExit: 270 | Exit Sub 271 | TestFail: 272 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 273 | Resume TestExit 274 | End Sub 275 | '@TestMethod("Mod Function") 276 | Private Sub TestModFunction() 277 | On Error GoTo TestFail 278 | 279 | actual = GetResult( _ 280 | "- (-1) + (+1) + 1.000 / 1.000 + 1 * (1) * (0.2) * (5) * (-1) * (--1) + 4 % 5 % 45 % 1 " _ 281 | ) 282 | expected = "2" 283 | Assert.AreEqual expected, actual 284 | 285 | TestExit: 286 | Exit Sub 287 | TestFail: 288 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 289 | Resume TestExit 290 | End Sub 291 | '@TestMethod("String Arguments and Parameters") 292 | Private Sub testStringComp() 293 | On Error GoTo TestFail 294 | 295 | actual = GetResult( _ 296 | "Region = 'Central America'" _ 297 | , "Region = 'Asia'" _ 298 | ) 299 | expected = "False" 300 | Assert.AreEqual expected, actual 301 | 302 | TestExit: 303 | Exit Sub 304 | TestFail: 305 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 306 | Resume TestExit 307 | End Sub 308 | '@TestMethod("String Arguments and Parameters") 309 | Private Sub testStringArgumentes() 310 | On Error GoTo TestFail 311 | 312 | actual = GetResult( _ 313 | "REPLACE(x;'a';'A';1;2)" _ 314 | , "x = 'Capital'" _ 315 | ) 316 | expected = "'CApitAl'" 317 | Assert.AreEqual expected, actual 318 | 319 | TestExit: 320 | Exit Sub 321 | TestFail: 322 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 323 | Resume TestExit 324 | End Sub 325 | '@TestMethod("Implied Multiplication") 326 | Private Sub ImpliedMultiplication() 327 | On Error GoTo TestFail 328 | 329 | actual = GetResult( _ 330 | "5(2)(3)(4)" _ 331 | ) 332 | expected = "120" 333 | Assert.AreEqual expected, actual 334 | 335 | TestExit: 336 | Exit Sub 337 | TestFail: 338 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 339 | Resume TestExit 340 | End Sub 341 | '@TestMethod("Array Arguments And Variables") 342 | Private Sub DirectArrayVariableAssignment() 343 | On Error GoTo TestFail 344 | 345 | actual = GetResult( _ 346 | "MSUM(f;g)" _ 347 | , "f = {{1;0;4};{1;1;6}}; g = {{-3;0;-10};{2;3;4}}") 348 | expected = "{{-2;0;-6};{3;4;10}}" 349 | Assert.AreEqual expected, actual 350 | 351 | TestExit: 352 | Exit Sub 353 | TestFail: 354 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 355 | Resume TestExit 356 | End Sub 357 | '@TestMethod("Assign Value To 2nd Order Variable") 358 | Private Sub AssignValueTo2ndOrderVariable() 359 | Dim expr As VBAexpressions 360 | 361 | Set expr = New VBAexpressions 362 | With expr 363 | .Create "MMULT(f;g)" 364 | .VarValue("a") = "{1;0;4}" 365 | .VarValue("b") = "{1;1;6}" 366 | .VarValue("c") = "{-3;0;-10}" 367 | .ImplicitVarValue("f") = "ARRAY(a;b;c)" 368 | .ImplicitVarValue("g") = "INVERSE(f)" 369 | actual = .Eval 370 | End With 371 | expected = "{{1;0;0};{0;1;0};{0;0;1}}" 372 | Assert.AreEqual expected, actual 373 | 374 | TestExit: 375 | Exit Sub 376 | TestFail: 377 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 378 | Resume TestExit 379 | End Sub 380 | '@TestMethod("Array Constructors And Parsers") 381 | Private Sub ArrayConstructorsAndParsers() 382 | Dim expr As VBAexpressions 383 | Dim jaggedArr() As Variant 384 | 385 | Set expr = New VBAexpressions 386 | With expr 387 | jaggedArr() = .ArrayFromString2("{{1;0;4};{{1;1;6};{2;3}};{3};{2;5}}") 388 | actual = .ArrayToString(jaggedArr) 389 | End With 390 | expected = "{{1;0;4};{{1;1;6};{2;3}};{3};{2;5}}" 391 | Assert.AreEqual expected, actual 392 | 393 | TestExit: 394 | Exit Sub 395 | TestFail: 396 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 397 | Resume TestExit 398 | End Sub 399 | '@TestMethod("Array Arguments And Variables") 400 | Private Sub DirectArrayArguments() 401 | On Error GoTo TestFail 402 | 403 | actual = GetResult( _ 404 | "MSUM({{1;0;4};{1;1;6}};{{-3;0;-10};{2;3;4}})" _ 405 | ) 406 | expected = "{{-2;0;-6};{3;4;10}}" 407 | Assert.AreEqual expected, actual 408 | TestExit: 409 | Exit Sub 410 | TestFail: 411 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 412 | Resume TestExit 413 | End Sub 414 | '@TestMethod("Array Arguments And Variables") 415 | Private Sub MatrixNegation() 416 | On Error GoTo TestFail 417 | 418 | actual = GetResult( _ 419 | "MNEG({{1;0;4};{1;1;6}})" _ 420 | ) 421 | expected = "{{-1;0;-4};{-1;-1;-6}}" 422 | Assert.AreEqual expected, actual 423 | TestExit: 424 | Exit Sub 425 | TestFail: 426 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 427 | Resume TestExit 428 | End Sub 429 | '@TestMethod("Matrices") 430 | Private Sub VectorsMultiplication() 431 | On Error GoTo TestFail 432 | 433 | actual = GetResult( _ 434 | "MMULT({{1;0;4}};{{1;1;6}})" _ 435 | ) 436 | expected = "25" 437 | Assert.AreEqual expected, actual 438 | TestExit: 439 | Exit Sub 440 | TestFail: 441 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 442 | Resume TestExit 443 | End Sub 444 | 445 | '@TestMethod("Matrices") 446 | Private Sub VectorByNxMmatrix() 447 | On Error GoTo TestFail 448 | 449 | actual = GetResult( _ 450 | "MMULT(A;B)" _ 451 | , "A={{1;-2;4}};B={{2};{1};{3}}") 452 | expected = "{{12}}" 453 | Assert.AreEqual expected, actual 454 | TestExit: 455 | Exit Sub 456 | TestFail: 457 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 458 | Resume TestExit 459 | End Sub 460 | 461 | '@TestMethod("Matrices") 462 | Private Sub NxMmatrixByVector() 463 | On Error GoTo TestFail 464 | 465 | actual = GetResult( _ 466 | "MMULT(A;B)" _ 467 | , "A={{2};{1};{3}};B={{1;-2;4}}") 468 | expected = "{{2;-4;8};{1;-2;4};{3;-6;12}}" 469 | Assert.AreEqual expected, actual 470 | TestExit: 471 | Exit Sub 472 | TestFail: 473 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 474 | Resume TestExit 475 | End Sub 476 | 477 | '@TestMethod("Matrices") 478 | Private Sub NxMmatrixByColumnVector() 479 | On Error GoTo TestFail 480 | 481 | actual = GetResult( _ 482 | "MMULT(A;B)" _ 483 | , "A={{2;1;4};{1;5;-3};{5;-2;3}};B={{1};{-2};{4}}") 484 | expected = "{{16};{-21};{21}}" 485 | Assert.AreEqual expected, actual 486 | TestExit: 487 | Exit Sub 488 | TestFail: 489 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 490 | Resume TestExit 491 | End Sub 492 | 493 | '@TestMethod("Matrices") 494 | Private Sub NxMmatrixByMxNmatrix() 495 | On Error GoTo TestFail 496 | 497 | actual = GetResult( _ 498 | "MMULT(A;B)" _ 499 | , "A={{2;1;3};{3;-2;-1}};B={{2;3};{1;-5};{-2;4}}") 500 | expected = "{{-1;13};{6;15}}" 501 | Assert.AreEqual expected, actual 502 | TestExit: 503 | Exit Sub 504 | TestFail: 505 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 506 | Resume TestExit 507 | End Sub 508 | 509 | '@TestMethod("Statistical Functions") 510 | Private Sub NORM() 511 | On Error GoTo TestFail 512 | 513 | actual = GetResult( _ 514 | "ROUND(NORM(0.05);8)" _ 515 | ) 516 | expected = "0.96012239" 517 | Assert.AreEqual expected, actual 518 | TestExit: 519 | Exit Sub 520 | TestFail: 521 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 522 | Resume TestExit 523 | End Sub 524 | '@TestMethod("Statistical Functions") 525 | Private Sub CHISQ() 526 | On Error GoTo TestFail 527 | 528 | actual = GetResult( _ 529 | "ROUND(CHISQ(4;15);8)" _ 530 | ) 531 | expected = "0.99773734" 532 | Assert.AreEqual expected, actual 533 | TestExit: 534 | Exit Sub 535 | TestFail: 536 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 537 | Resume TestExit 538 | End Sub 539 | '@TestMethod("Statistical Functions") 540 | Private Sub GAUSS() 541 | On Error GoTo TestFail 542 | 543 | actual = GetResult( _ 544 | "ROUND(GAUSS(0.05);8)" _ 545 | ) 546 | expected = "0.01993881" 547 | Assert.AreEqual expected, actual 548 | TestExit: 549 | Exit Sub 550 | TestFail: 551 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 552 | Resume TestExit 553 | End Sub 554 | '@TestMethod("Statistical Functions") 555 | Private Sub ERF() 556 | On Error GoTo TestFail 557 | 558 | actual = GetResult( _ 559 | "ROUND(ERF(0.05);8)" _ 560 | ) 561 | expected = "0.05637198" 562 | Assert.AreEqual expected, actual 563 | TestExit: 564 | Exit Sub 565 | TestFail: 566 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 567 | Resume TestExit 568 | End Sub 569 | '@TestMethod("Statistical Functions") 570 | Private Sub STUDT() 571 | On Error GoTo TestFail 572 | 573 | actual = GetResult( _ 574 | "ROUND(STUDT(0.8;15);8)" _ 575 | ) 576 | expected = "0.43619794" 577 | Assert.AreEqual expected, actual 578 | TestExit: 579 | Exit Sub 580 | TestFail: 581 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 582 | Resume TestExit 583 | End Sub 584 | '@TestMethod("Statistical Functions") 585 | Private Sub anorm() 586 | On Error GoTo TestFail 587 | 588 | actual = GetResult( _ 589 | "ROUND(ANORM(0.75);8)" _ 590 | ) 591 | expected = "0.31863936" 592 | Assert.AreEqual expected, actual 593 | TestExit: 594 | Exit Sub 595 | TestFail: 596 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 597 | Resume TestExit 598 | End Sub 599 | '@TestMethod("Statistical Functions") 600 | Private Sub AGAUSS() 601 | On Error GoTo TestFail 602 | 603 | actual = GetResult( _ 604 | "ROUND(AGAUSS(0.75);8)" _ 605 | ) 606 | expected = "0.67448975" 607 | Assert.AreEqual expected, actual 608 | TestExit: 609 | Exit Sub 610 | TestFail: 611 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 612 | Resume TestExit 613 | End Sub 614 | '@TestMethod("Statistical Functions") 615 | Private Sub AERF() 616 | On Error GoTo TestFail 617 | 618 | actual = GetResult( _ 619 | "ROUND(AERF(0.95);8)" _ 620 | ) 621 | expected = "1.38590382" 622 | Assert.AreEqual expected, actual 623 | TestExit: 624 | Exit Sub 625 | TestFail: 626 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 627 | Resume TestExit 628 | End Sub 629 | '@TestMethod("Statistical Functions") 630 | Private Sub ACHISQ() 631 | On Error GoTo TestFail 632 | 633 | actual = GetResult( _ 634 | "ROUND(ACHISQ(0.75;15);8)" _ 635 | ) 636 | expected = "11.03653766" 637 | Assert.AreEqual expected, actual 638 | TestExit: 639 | Exit Sub 640 | TestFail: 641 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 642 | Resume TestExit 643 | End Sub 644 | '@TestMethod("Statistical Functions") 645 | Private Sub FISHF() 646 | On Error GoTo TestFail 647 | 648 | actual = GetResult( _ 649 | "ROUND(FISHF(5.5;1.5;3);8)" _ 650 | ) 651 | expected = "0.21407698" 652 | Assert.AreEqual expected, actual 653 | TestExit: 654 | Exit Sub 655 | TestFail: 656 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 657 | Resume TestExit 658 | End Sub 659 | '@TestMethod("Statistical Functions") 660 | Private Sub ASTUDT() 661 | On Error GoTo TestFail 662 | 663 | actual = GetResult( _ 664 | "ROUND(ASTUDT(0.05;15);8)" _ 665 | ) 666 | expected = "2.13144955" 667 | Assert.AreEqual expected, actual 668 | TestExit: 669 | Exit Sub 670 | TestFail: 671 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 672 | Resume TestExit 673 | End Sub 674 | '@TestMethod("Statistical Functions") 675 | Private Sub AFISHF() 676 | On Error GoTo TestFail 677 | 678 | actual = GetResult( _ 679 | "ROUND(AFISHF(0.05;1.5;3);8)" _ 680 | ) 681 | expected = "18.55325631" 682 | Assert.AreEqual expected, actual 683 | TestExit: 684 | Exit Sub 685 | TestFail: 686 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 687 | Resume TestExit 688 | End Sub 689 | '@TestMethod("Statistical Functions") 690 | Private Sub iBETA() 691 | On Error GoTo TestFail 692 | 693 | actual = GetResult( _ 694 | "ROUND(iBETA(0.5;1;3);8)" _ 695 | ) 696 | expected = "0.875" 697 | Assert.AreEqual expected, actual 698 | TestExit: 699 | Exit Sub 700 | TestFail: 701 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 702 | Resume TestExit 703 | End Sub 704 | '@TestMethod("Statistical Functions") 705 | Private Sub BETAINV() 706 | On Error GoTo TestFail 707 | 708 | actual = GetResult( _ 709 | "ROUND(BETAINV(0.5;1;3);8)" _ 710 | ) 711 | expected = "0.20629947" 712 | Assert.AreEqual expected, actual 713 | TestExit: 714 | Exit Sub 715 | TestFail: 716 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 717 | Resume TestExit 718 | End Sub 719 | 720 | '@TestMethod("Linear Algebra Functions") 721 | Private Sub QR() 722 | On Error GoTo TestFail 723 | Dim QRstr As String 724 | Dim QRarr As Variant 725 | 726 | Dim oHelper As VBAexpressions 727 | 728 | QRstr = GetResult("QR({{12;-51;4};{6;167;-68};{-4;24;-41}})") 729 | Set oHelper = New VBAexpressions 730 | With oHelper 731 | QRarr = .ArrayFromString2(QRstr) 732 | actual = GetResult("MROUND(MMULT(A;B);0)", "A=" & .ArrayToString(QRarr(0)) & ";" & "B=" & .ArrayToString(QRarr(1))) 733 | End With 734 | Set oHelper = Nothing 735 | expected = "{{12;-51;4};{6;167;-68};{-4;24;-41}}" 736 | Assert.AreEqual expected, actual 737 | TestExit: 738 | Exit Sub 739 | TestFail: 740 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 741 | Resume TestExit 742 | End Sub 743 | 744 | '@TestMethod("Linear Algebra Functions") 745 | Private Sub CholeskyDecomposition() 746 | On Error GoTo TestFail 747 | 748 | actual = GetResult("MROUND(MTRANSPOSE(CHOLESKY({{2.5;1.1;0.3};{2.2;1.9;0.4};{1.8;0.1;0.3}}));4)") 749 | expected = "{{1.5811;0.6957;0.1897};{0;1.19;0.2252};{0;0;0.4618}}" 'Octave output 750 | Assert.AreEqual expected, actual 751 | TestExit: 752 | Exit Sub 753 | TestFail: 754 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 755 | Resume TestExit 756 | End Sub 757 | 758 | '@TestMethod("Linear Algebra Functions") 759 | Private Sub CholeskySolve() 760 | On Error GoTo TestFail 761 | 762 | actual = GetResult( _ 763 | "MROUND(CHOLSOLVE(ARRAY(a;b;c);{{'x';'y';'z'}};{{76;295;1259}};False);4)" _ 764 | , "a={6;15;55};b={15;55;225};c={55;225;979}") 765 | expected = "{{1;1;1}}" 766 | Assert.AreEqual expected, actual 767 | TestExit: 768 | Exit Sub 769 | TestFail: 770 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 771 | Resume TestExit 772 | End Sub 773 | 774 | '@TestMethod("Linear Algebra Functions") 775 | Private Sub CholeskyInverse() 776 | On Error GoTo TestFail 777 | 778 | actual = GetResult( _ 779 | "MROUND(CHOLINVERSE(ARRAY(a;b;c));4)" _ 780 | , "a={6;15;55};b={15;55;225};c={55;225;979}") 781 | expected = "{{0.8214;-0.5893;0.0893};{-0.5893;0.7268;-0.1339};{0.0893;-0.1339;0.0268}}" 'Octave output 782 | Assert.AreEqual expected, actual 783 | TestExit: 784 | Exit Sub 785 | TestFail: 786 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 787 | Resume TestExit 788 | End Sub 789 | 790 | '@TestMethod("Linear Algebra Functions") 791 | Private Sub LSQRsolve() 792 | On Error GoTo TestFail 793 | 794 | actual = GetResult( _ 795 | "MROUND(LSQRSOLVE(A;b);4)" _ 796 | , "A={{2;4};{-5;1};{3;-8}};b={{10;-9.5;12}}") 797 | expected = "{{2.6576};{-0.1196}}" 798 | Assert.AreEqual expected, actual 799 | TestExit: 800 | Exit Sub 801 | TestFail: 802 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 803 | Resume TestExit 804 | End Sub 805 | 806 | '@TestMethod("Linear Algebra Functions") 807 | Private Sub LUsolve() 808 | On Error GoTo TestFail 809 | 810 | actual = GetResult( _ 811 | "LUSOLVE(ARRAY(a;b;c);{{'x';'y';'z'}};{{2;3;4}};True)" _ 812 | , "a={1;0;4};b={1;1;6};c={-3;0;-10}") 813 | expected = "x = -18; y = -9; z = 5" 814 | Assert.AreEqual expected, actual 815 | TestExit: 816 | Exit Sub 817 | TestFail: 818 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 819 | Resume TestExit 820 | End Sub 821 | 822 | '@TestMethod("Linear Algebra/Stats Functions") 823 | Private Sub StraightLineFit() 824 | On Error GoTo TestFail 825 | 826 | actual = GetResult( _ 827 | "FIT(A;1)" _ 828 | , "A={{-2;40};{-1;50};{0;62};{1;58};{2;60}}") 829 | expected = "{{54 + 4.8*x};{0.7024}}" 830 | Assert.AreEqual expected, actual 831 | TestExit: 832 | Exit Sub 833 | TestFail: 834 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 835 | Resume TestExit 836 | End Sub 837 | 838 | '@TestMethod("Linear Algebra/Stats Functions") 839 | Private Sub PolynomialFit() 840 | On Error GoTo TestFail 841 | 842 | actual = GetResult( _ 843 | "FIT(A;1;4)" _ 844 | , "A={{-2;40};{-1;50};{0;62};{1;58};{2;60}}") 845 | expected = "{{62 + 3.6667*x -9.6667*x^2 + 0.3333*x^3 + 1.6667*x^4};{1}}" 846 | Assert.AreEqual expected, actual 847 | TestExit: 848 | Exit Sub 849 | TestFail: 850 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 851 | Resume TestExit 852 | End Sub 853 | 854 | '@TestMethod("Linear Algebra/Stats Functions") 855 | Private Sub ExponentialFit() 856 | On Error GoTo TestFail 857 | 858 | actual = GetResult( _ 859 | "FIT(A;2)" _ 860 | , "A={{0;0.1};{0.5;0.45};{1;2.15};{1.5;9.15};{2;40.35};{2.5;180.75}}") 861 | expected = "{{0.102*e^(2.9963*x)};{0.9998}}" 862 | Assert.AreEqual expected, actual 863 | TestExit: 864 | Exit Sub 865 | TestFail: 866 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 867 | Resume TestExit 868 | End Sub 869 | 870 | '@TestMethod("Linear Algebra/Stats Functions") 871 | Private Sub ExponentialFit2() 872 | On Error GoTo TestFail 873 | 874 | actual = GetResult( _ 875 | "FIT(A;3)" _ 876 | , "A={{0;10};{1;21};{2;35};{3;59};{4;92};{5;200};{6;400};{7;610}}") 877 | expected = "{{10.4992*(1.7959^x)};{0.9906}}" 878 | Assert.AreEqual expected, actual 879 | TestExit: 880 | Exit Sub 881 | TestFail: 882 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 883 | Resume TestExit 884 | End Sub 885 | 886 | '@TestMethod("Linear Algebra/Stats Functions") 887 | Private Sub PowerFit() 888 | On Error GoTo TestFail 889 | 890 | actual = GetResult( _ 891 | "FIT(A;4)" _ 892 | , "A={{2;27.8};{3;62.1};{4;110};{5;161}}") 893 | expected = "{{7.3799*x^1.9302};{0.9977}}" 894 | Assert.AreEqual expected, actual 895 | TestExit: 896 | Exit Sub 897 | TestFail: 898 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 899 | Resume TestExit 900 | End Sub 901 | 902 | '@TestMethod("Linear Algebra/Stats Functions") 903 | Private Sub LogarithmicFit() 904 | On Error GoTo TestFail 905 | 906 | actual = GetResult( _ 907 | "FIT(A;5)" _ 908 | , "A={{1;0.01};{2;1};{3;1.15};{4;1.3};{5;1.52};{6;1.84};{7;2.01};{8;2.05};{9;2.3};{10;2.25}}") 909 | expected = "{{0.9521*ln(x)+0.1049};{0.9752}}" 910 | Assert.AreEqual expected, actual 911 | TestExit: 912 | Exit Sub 913 | TestFail: 914 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 915 | Resume TestExit 916 | End Sub 917 | '@TestMethod("Linear Algebra/Stats Functions") 918 | Private Sub testMLR_FNominal() 919 | On Error GoTo TestFail 920 | 921 | actual = GetResult( _ 922 | "MLR(X;Y;True)" _ 923 | , "X={{1;1};{2;2};{3;3};{4;4};{5;1};{6;2};{7;3};{8;4}};Y={{2;4.1;5.8;7.8;5.5;5.2;8.2;11.1}}") 924 | expected = "{{0.0625 + 0.6438*X1 + 1.3013*X2};{0.9415;0.9181}}" 925 | Assert.AreEqual expected, actual 926 | TestExit: 927 | Exit Sub 928 | TestFail: 929 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 930 | Resume TestExit 931 | End Sub 932 | 933 | '@TestMethod("Linear Algebra/Stats Functions") 934 | Private Sub testMLR_CFNominal() 935 | On Error GoTo TestFail 936 | 937 | actual = GetResult( _ 938 | "MLR(X;Y;False)" _ 939 | , "X={{1;1};{2;2};{3;3};{4;4};{5;1};{6;2};{7;3};{8;4}};Y={{2;4.1;5.8;7.8;5.5;5.2;8.2;11.1}}") 940 | expected = "{{{{0.0625};{0.6438};{1.3013}}};{0.9415;0.9181}}" 941 | Assert.AreEqual expected, actual 942 | TestExit: 943 | Exit Sub 944 | TestFail: 945 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 946 | Resume TestExit 947 | End Sub 948 | 949 | '@TestMethod("Linear Algebra/Stats Functions") 950 | Private Sub testMLR_FNominal_Interactions() 951 | On Error GoTo TestFail 952 | 953 | actual = GetResult( _ 954 | "MLR(X;Y;True;'X1:X2')" _ 955 | , "X={{1;1};{2;2};{3;3};{4;4};{5;1};{6;2};{7;3};{8;4}};Y={{2;4.1;5.8;7.8;5.5;5.2;8.2;11.1}}") 956 | expected = "{{0.8542 + 0.4458*X1 + 0.945*X2 + 0.0792*X1*X2};{0.947;0.9072}}" 957 | Assert.AreEqual expected, actual 958 | TestExit: 959 | Exit Sub 960 | TestFail: 961 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 962 | Resume TestExit 963 | End Sub 964 | 965 | '@TestMethod("Linear Algebra/Stats Functions") 966 | Private Sub testMLR_CFNominal_Interactions() 967 | On Error GoTo TestFail 968 | 969 | actual = GetResult( _ 970 | "MLR(X;Y;False;'X1:X2')" _ 971 | , "X={{1;1};{2;2};{3;3};{4;4};{5;1};{6;2};{7;3};{8;4}};Y={{2;4.1;5.8;7.8;5.5;5.2;8.2;11.1}}") 972 | expected = "{{{{0.8542};{0.4458};{0.945};{0.0792}}};{0.947;0.9072}}" 973 | Assert.AreEqual expected, actual 974 | TestExit: 975 | Exit Sub 976 | TestFail: 977 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 978 | Resume TestExit 979 | End Sub 980 | 981 | '@TestMethod("Linear Algebra/Stats Functions") 982 | Private Sub testMLR_FNamed_Interactions() 983 | On Error GoTo TestFail 984 | 985 | actual = GetResult( _ 986 | "MLR(X;Y;True;'Height:Width';'Height;Width')" _ 987 | , "X={{1;1};{2;2};{3;3};{4;4};{5;1};{6;2};{7;3};{8;4}};Y={{2;4.1;5.8;7.8;5.5;5.2;8.2;11.1}}") 988 | expected = "{{0.8542 + 0.4458*Height + 0.945*Width + 0.0792*Height*Width};{0.947;0.9072}}" 989 | Assert.AreEqual expected, actual 990 | TestExit: 991 | Exit Sub 992 | TestFail: 993 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 994 | Resume TestExit 995 | End Sub 996 | 997 | '@TestMethod("Linear Algebra/Stats Functions") 998 | Private Sub testMLR_CFNamed_Interactions() 999 | On Error GoTo TestFail 1000 | 1001 | actual = GetResult( _ 1002 | "MLR(X;Y;False;'Height:Width';'Height;Width')" _ 1003 | , "X={{1;1};{2;2};{3;3};{4;4};{5;1};{6;2};{7;3};{8;4}};Y={{2;4.1;5.8;7.8;5.5;5.2;8.2;11.1}}") 1004 | expected = "{{{{0.8542};{0.4458};{0.945};{0.0792}}};{0.947;0.9072}}" 1005 | Assert.AreEqual expected, actual 1006 | TestExit: 1007 | Exit Sub 1008 | TestFail: 1009 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 1010 | Resume TestExit 1011 | End Sub 1012 | 1013 | '@TestMethod("Linear Algebra/Stats Functions") 1014 | Private Sub testMLR_FNamed_MultiInteractions() 1015 | On Error GoTo TestFail 1016 | 1017 | actual = GetResult( _ 1018 | "MLR(X;Y;True;'Height:Width;Height:Height';'Height;Width')" _ 1019 | , "X={{1;1};{2;2};{3;3};{4;4};{5;1};{6;2};{7;3};{8;4}};Y={{2;4.1;5.8;7.8;5.5;5.2;8.2;11.1}}") 1020 | expected = "{{2.0875 + 2.08*Height -2.1075*Width -0.37*Height*Height + 0.7575*Height*Width};{0.9638;0.9155}}" 1021 | Assert.AreEqual expected, actual 1022 | TestExit: 1023 | Exit Sub 1024 | TestFail: 1025 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 1026 | Resume TestExit 1027 | End Sub 1028 | 1029 | '@TestMethod("Linear Algebra/Stats Functions") 1030 | Private Sub testMLR_CFname_MultiInteractions() 1031 | On Error GoTo TestFail 1032 | 1033 | actual = GetResult( _ 1034 | "MLR(X;Y;False;'Height:Width;Height:Height';'Height;Width')" _ 1035 | , "X={{1;1};{2;2};{3;3};{4;4};{5;1};{6;2};{7;3};{8;4}};Y={{2;4.1;5.8;7.8;5.5;5.2;8.2;11.1}}") 1036 | expected = "{{{{2.0875};{2.08};{-2.1075};{-0.37};{0.7575}}};{0.9638;0.9155}}" 1037 | Assert.AreEqual expected, actual 1038 | TestExit: 1039 | Exit Sub 1040 | TestFail: 1041 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 1042 | Resume TestExit 1043 | End Sub 1044 | 1045 | 1046 | '@TestMethod("Array elements retrieval") 1047 | Private Sub RetrieveArrayElement() 1048 | On Error GoTo TestFail 1049 | 1050 | actual = GetResult( _ 1051 | "SUM(C[0;0];C[1;1])" _ 1052 | , "C = {{-1;13};{6;15}}") 1053 | expected = "14" 1054 | Assert.AreEqual expected, actual 1055 | TestExit: 1056 | Exit Sub 1057 | TestFail: 1058 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 1059 | Resume TestExit 1060 | End Sub 1061 | 1062 | '@TestMethod("Array elements retrieval") 1063 | Private Sub VarOverloading() 1064 | On Error GoTo TestFail 1065 | 1066 | Set Evaluator = New VBAexpressions 1067 | With Evaluator 1068 | .Create "GET('A';{{2;1;3};{3;-2;-1}}); GET('B';{{2;3};{1;-5};{-2;4}})": .Eval 1069 | .Create "GET('C';MMULT(A;B))", False: .Eval 1070 | .Create "ROUND(SUM(SIN(C[0;0]);SIN(C[1;1]));4)", False: .Eval 1071 | actual = .result 1072 | End With 1073 | expected = "-0.1912" 1074 | Assert.AreEqual expected, actual 1075 | TestExit: 1076 | Exit Sub 1077 | TestFail: 1078 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 1079 | Resume TestExit 1080 | End Sub 1081 | 1082 | '@TestMethod("Linear Algebra/Stats Functions") 1083 | Private Sub testBetaInverse() 1084 | On Error GoTo TestFail 1085 | 1086 | actual = GetResult( _ 1087 | "ROUND(IBETA((2-1)/(3-1);8;10);4)" _ 1088 | ) 1089 | expected = "0.6855" 1090 | Assert.AreEqual expected, actual 1091 | TestExit: 1092 | Exit Sub 1093 | TestFail: 1094 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 1095 | Resume TestExit 1096 | End Sub 1097 | 1098 | '@TestMethod("Linear Algebra/Stats Functions") 1099 | Private Sub testBetaDist() 1100 | On Error GoTo TestFail 1101 | 1102 | actual = GetResult( _ 1103 | "ROUND(BETA.DIST(2;8;10;True;1;3);4)" _ 1104 | ) 1105 | expected = "0.6855" 1106 | Assert.AreEqual expected, actual 1107 | TestExit: 1108 | Exit Sub 1109 | TestFail: 1110 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 1111 | Resume TestExit 1112 | End Sub 1113 | 1114 | '@TestMethod("Linear Algebra/Stats Functions") 1115 | Private Sub testTINV() 1116 | On Error GoTo TestFail 1117 | 1118 | actual = GetResult( _ 1119 | "ROUND(TINV(0.75;2;1);8)" _ 1120 | ) 1121 | expected = "0.81649658" 1122 | Assert.AreEqual expected, actual 1123 | TestExit: 1124 | Exit Sub 1125 | TestFail: 1126 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 1127 | Resume TestExit 1128 | End Sub 1129 | 1130 | '@TestMethod("Finantial Functions") 1131 | Private Sub testIRR() 1132 | On Error GoTo TestFail 1133 | 1134 | actual = GetResult( _ 1135 | "FORMAT(IRR({{-70000;12000;15000}};true);'Percent')" _ 1136 | ) 1137 | expected = "'-44.35%'" 1138 | Assert.AreEqual expected, actual 1139 | TestExit: 1140 | Exit Sub 1141 | TestFail: 1142 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 1143 | Resume TestExit 1144 | End Sub 1145 | 1146 | '@TestMethod("Analytical Geometry") 1147 | Private Sub testTwoPointsDistance() 1148 | On Error GoTo TestFail 1149 | 1150 | actual = GetResult( _ 1151 | "ROUND(DISTANCE({{3.1441;0}};{{4.45415;3.1441}});4)" _ 1152 | ) 1153 | expected = "3.4061" 1154 | Assert.AreEqual expected, actual 1155 | TestExit: 1156 | Exit Sub 1157 | TestFail: 1158 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 1159 | Resume TestExit 1160 | End Sub 1161 | 1162 | '@TestMethod("Analytical Geometry") 1163 | Private Sub testLinesIntersection() 1164 | On Error GoTo TestFail 1165 | 1166 | actual = GetResult( _ 1167 | "MROUND(LINESINTERSECT({{12;0};{0;5}};{{0;1.31004};{0.79693;3.22267}});2)" _ 1168 | ) 1169 | expected = "{{1.31;4.45}}" 1170 | Assert.AreEqual expected, actual 1171 | TestExit: 1172 | Exit Sub 1173 | TestFail: 1174 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 1175 | Resume TestExit 1176 | End Sub 1177 | 1178 | '@TestMethod("Analytical Geometry") 1179 | Private Sub testParallelLine() 1180 | On Error GoTo TestFail 1181 | 1182 | actual = GetResult( _ 1183 | "MROUND(PARALLEL({{12;0};{0;5}};{{3.1441;0}});2)" _ 1184 | ) 1185 | expected = "{{3.14;0};{0;1.31}}" 1186 | Assert.AreEqual expected, actual 1187 | TestExit: 1188 | Exit Sub 1189 | TestFail: 1190 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 1191 | Resume TestExit 1192 | End Sub 1193 | 1194 | '@TestMethod("Analytical Geometry") 1195 | Private Sub testPerpendicularLine() 1196 | On Error GoTo TestFail 1197 | 1198 | actual = GetResult( _ 1199 | "MROUND(PERPENDICULAR({{12;0};{0;5}};{{3.1441;0}});2)" _ 1200 | ) 1201 | expected = "{{3.14;0};{4.45;3.14}}" 1202 | Assert.AreEqual expected, actual 1203 | TestExit: 1204 | Exit Sub 1205 | TestFail: 1206 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 1207 | Resume TestExit 1208 | End Sub 1209 | 1210 | '@TestMethod("Analytical Geometry") 1211 | Private Sub testBisectorLine() 1212 | On Error GoTo TestFail 1213 | 1214 | actual = GetResult( _ 1215 | "MROUND(BISECTOR({{-4;-2}};{{-2;6}});4)" _ 1216 | ) 1217 | expected = "{{-3;2};{-2;1.75}}" 1218 | Assert.AreEqual expected, actual 1219 | TestExit: 1220 | Exit Sub 1221 | TestFail: 1222 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 1223 | Resume TestExit 1224 | End Sub 1225 | 1226 | '@TestMethod("Analytical Geometry") 1227 | Private Sub testAngleBisectorLine() 1228 | On Error GoTo TestFail 1229 | 1230 | actual = GetResult( _ 1231 | "MROUND(BISECTOR({{-2.4387;6.8161}};{{-4;3}};{{-0.4613;0.8839}});4)" _ 1232 | ) 1233 | expected = "{{-4;3};{-3.0513;3.3162}}" 1234 | Assert.AreEqual expected, actual 1235 | TestExit: 1236 | Exit Sub 1237 | TestFail: 1238 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 1239 | Resume TestExit 1240 | End Sub 1241 | 1242 | '@TestMethod("Analytical Geometry") 1243 | Private Sub testTriangleIncenter() 1244 | On Error GoTo TestFail 1245 | 1246 | actual = GetResult( _ 1247 | "MROUND(INCENTER({{0;0}};{{-4;-2}};{{-2;6}});4)" _ 1248 | ) 1249 | expected = "{{-1.7982;0.7448}}" 1250 | Assert.AreEqual expected, actual 1251 | TestExit: 1252 | Exit Sub 1253 | TestFail: 1254 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 1255 | Resume TestExit 1256 | End Sub 1257 | 1258 | '@TestMethod("Analytical Geometry") 1259 | Private Sub testTriangleIncircle() 1260 | On Error GoTo TestFail 1261 | 1262 | actual = GetResult( _ 1263 | "MROUND(INCIRCLE({{0;0}};{{-4;-2}};{{-2;6}});4)" _ 1264 | ) 1265 | expected = "{{-1.7982;0.7448};{1.4704;1.4704}}" 1266 | Assert.AreEqual expected, actual 1267 | TestExit: 1268 | Exit Sub 1269 | TestFail: 1270 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 1271 | Resume TestExit 1272 | End Sub 1273 | 1274 | '@TestMethod("Analytical Geometry") 1275 | Private Sub testCircumcircle() 1276 | On Error GoTo TestFail 1277 | 1278 | actual = GetResult( _ 1279 | "MROUND(CIRCUMCIRCLE({{0;0}};{{-4;-2}};{{-2;6}});4)" _ 1280 | ) 1281 | expected = "{{-3.5714;2.1429};{4.165;4.165}}" 1282 | Assert.AreEqual expected, actual 1283 | TestExit: 1284 | Exit Sub 1285 | TestFail: 1286 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 1287 | Resume TestExit 1288 | End Sub 1289 | 1290 | '@TestMethod("Analytical Geometry") 1291 | Private Sub testTwoCircleTangents() 1292 | On Error GoTo TestFail 1293 | 1294 | actual = GetResult( _ 1295 | "MROUND(CIRCLETANG({{-4;3}};SQRT(17);{{2;5}});4)" _ 1296 | ) 1297 | expected = "{{-2.4387;6.8161};{2;5}};{{2;5};{-0.4613;0.8839}}" 1298 | Assert.AreEqual expected, actual 1299 | TestExit: 1300 | Exit Sub 1301 | TestFail: 1302 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 1303 | Resume TestExit 1304 | End Sub 1305 | 1306 | '@TestMethod("Analytical Geometry") 1307 | Private Sub testOneCircleTangent() 1308 | On Error GoTo TestFail 1309 | 1310 | actual = GetResult( _ 1311 | "MROUND(CIRCLETANG({{-4;3}};SQRT(17);{{0;4}});4)" _ 1312 | ) 1313 | expected = "{{0;4};{1;0}}" 1314 | Assert.AreEqual expected, actual 1315 | TestExit: 1316 | Exit Sub 1317 | TestFail: 1318 | Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description 1319 | Resume TestExit 1320 | End Sub 1321 | 1322 | -------------------------------------------------------------------------------- /src/UDFunctions.cls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ECP-Solutions/VBA-Expressions/538a1962e6992d652f833bc3a20657188f5aa455/src/UDFunctions.cls -------------------------------------------------------------------------------- /src/VBAcallBack.cls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ECP-Solutions/VBA-Expressions/538a1962e6992d652f833bc3a20657188f5aa455/src/VBAcallBack.cls -------------------------------------------------------------------------------- /src/VBAexpressions.cls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ECP-Solutions/VBA-Expressions/538a1962e6992d652f833bc3a20657188f5aa455/src/VBAexpressions.cls -------------------------------------------------------------------------------- /src/VBAexpressionsScope.cls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ECP-Solutions/VBA-Expressions/538a1962e6992d652f833bc3a20657188f5aa455/src/VBAexpressionsScope.cls -------------------------------------------------------------------------------- /testing/tests/Test runner.xlsm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ECP-Solutions/VBA-Expressions/538a1962e6992d652f833bc3a20657188f5aa455/testing/tests/Test runner.xlsm --------------------------------------------------------------------------------