GithubHelp home page GithubHelp logo

rubberduck203 / vbex Goto Github PK

View Code? Open in Web Editor NEW
96.0 27.0 24.0 491 KB

VBA Extension Library

License: GNU General Public License v3.0

Visual Basic 96.30% PowerShell 3.70%
vba vba-library enumerable vbide

vbex's Introduction

VBEX

VBA Extension Library

Intro

Ease production of VBA code with the VBEX library of rich idiomatic containers and some functional programing capabilities to bring VBA into the new millenium. With VBEX you can:

  1. Use Class Constructors for immutable classes.

  2. Print meaningful debug methods that reveal a datastructures contents

    Console.PrintLine List.Create(1, 2, 3, 4) ' Note usage of class constructors List(1, 2, 3, 4)

  3. Create functional objects to use with higher order functions. With those we have created some monadic classes (List, Maybe, Try) that implement the traditonal Map, FlatMap or Bind methods.

  4. Access a growing library of Containers.

  5. Perform file-system operations.

    • These will later be replaced or enhanced with an object-oriented model
  6. Later there will be APIs for ADODB (SQL) and Windows Scripting Host 2. ADODB/SQL implemented with SqlConnection, SqlCommand, and SqlResult!

Install

Once you acquire the source by either cloning this repo or downloading zip and extracting

  1. Run the Make.ps1 script to build VBEXsrc.xlam and VBEXtest.xlam.
    • VBEXtest.xlam contains unit-testing code and is only relevant to development.
  2. Reference VBEXsrc.xlam in projects to use VBEX
    • From the VBE from the menu tools >> References >> Browse.
  3. Enable "Programmatic access to Office VBA project"
    • This is required for the Lambda class as it auto-generates code in a blank module.

Usage

VBEX is not a normal VBA library, before you start using you should understand the following aspects about VBEX.

Predeclared Objects

All public classes have a predeclared instance of that class called the "predeclared object".

  • The predeclared object has the same name as the class, e.g.
Dim xs As List ' word "List" as a type
Set xs = List.Create(1, 2, 3) ' word "List" here is the predeclared object
  • All creatable classes are created from the predeclared object.
  • Predeclared objects of mutable classes can be mutated, but there is no reason for one to ever do so.

Inheritance

Since VBA has only Interface Inheritance, code that would be put in parent or abstract classesis instead put into def* modules. While this reduces code duplication, it only reduces it to trivial code like,

Public Function IsSubSetOf(ByVal other As SetLike) As Boolean
    
    IsSubSetOf = defSetLike.IsSubSetOf(Me, other)
    
End Function
Private Function SetLike_IsSubSetOf(ByVal other As SetLike) As Boolean

    SetLike_IsSubSetOf = IsSubSetOf(other)

End Function

This screams for some macro or preprocessing system, but that doesn't exist yet.

Applicable

Implementations of the Applicable interface allow methods and functions to be treated as objects.

  • All Applicable objects are immutable.
  • The Lambda class writes functions to a VBEX modules and allows you to execute that code.
    • Using the Lambda class will sometimes disable the debugger.
    • A lambda has no reference to environment in it was created.
      • Lambda.FromShort("_ + x") will always error even if x is in the current scope.
  • OnArgs and OnObject are complementary.
    • OnArgs.Make(myObject, "method", vbMethod) is (x) => myObject.method(x)
    • OnObject.Make("method", vbMethod, myArgs) is (o) => o.method(myArgs)
    • These are the only applicable objects that have references to the current environment.

vbex's People

Contributors

ptwales avatar rubberduck203 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vbex's Issues

Missing documentation

  • it would be nice, to have a documentation/wiki about whole process of setup/using this framework. With examples.
  • same for separated features/classes

getProcedures is inefficient

vbeCodeModule.getProcedures is inefficient.
It loops through each line in the module, but doesn't need to, because once the first procedure is retrieved, we theoretically already know where the next procedure begins thanks to vbeProcedure.EndLine.

vbeProcedure Only Works on Subs/Functions

'StartLine' uses vbext_pk_Proc to look up the start line for a method. This breaks when dealing with classes because CodeModule.procStartLine needs to know up front whether it is looking for a property getter, property setter, or a procedure.

Office 2018 Nov 2018 - Does not compile

The instructions for compiling this addin do not work as of Nov 12 2018. Using Office 365 (2016) 64 bit.

I changed the powershell execution policy to allow unrestricted running however for each source file I received a dialog box asking me to unblock the file.

PS C:\WINDOWS\system32> get-executionpolicy
Unrestricted

PS C:\WINDOWS\system32> G:\Download\Microsoft\Visual Basic stuff\VBEX-master\VBEX-master\Make.ps1
Will Build G:\Download\Microsoft\Visual Basic stuff\VBEX-master\VBEX-master\VBEXsrc.xlam
Converting 57 files to CRLF
The property 'Name' cannot be found on this object. Verify that the property exists and can be set.
At G:\Download\Microsoft\Visual Basic stuff\VBEX-master\VBEX-master\Build.ps1:64 char:5
+     $prj.Name = $name
+     ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound
 
=> Building VBProject VBEXsrc:
==> Importing 57 Modules:
---> G:\Download\Microsoft\Visual Basic stuff\VBEX-master\VBEX-master\src\Applicable.cls
You cannot call a method on a null-valued expression.
At G:\Download\Microsoft\Visual Basic stuff\VBEX-master\VBEX-master\Build.ps1:70 char:9
+         $prj.VBComponents.Import($moduleFile)
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.