Delegate
This class module defines what I'm calling, in this context, a Delegate - here a function that can take a number of parameters, evaluate a result, and return a value. Close enough to the actual "delegate" thing I find.
Example usage
Set x = Delegate.Create("(x) => MsgBox(""Hello, "" & x
Public Function Where(ByVal predicate As Delegate) As Enumerable
Dim result As New Collection
Dim element As Variant
For Each element In this.Encapsulated
If predicate.Execute(element) Then result.Add element
Next
Set Where = Enumerable.FromCollection(result)
End Function
Public Function FirstWhere(ByVal predicate As Delegate) As Variant
Dim element As Variant
For Each element In this.Encapsulated
If predicate.Execute(element) Then
If IsObject(element) Then
?Enumerable.FromEnumerable(List.Create(10,12,4321,4324,324,324,320,2,32,54,99).ToEnumerable).CountIf(Delegate.Create("(x) => x < 100"))
NOTE - if you decide to stick with paramArray() it wouldn't be a bad idea to check the boundaries of the paramArray() before going any further -> into Select case in the Execute(). Application.Run() is capable to take up to 30 parameters so a quick check that your Ubound(params)) < 30 would proba...
I am still kind of thinking if paramArray actually isn't better in this case :/ hm....
I am trying to get the best way to pass a Range to .net
so like I can do nice stuff like convert it to a List<T> and call .Distinct() to remove duplicates, or .Reverse() to reverse it etc... and pass it back to VBA as Range object
but I am not sure what the "best" or even just a good way would be... pass it as an Excel.Range and convert it to something else in .NET probably....
Background
Kind of a follow up - slightly related to my other SO question.
I thought that if somehow I find a way in VBA to pass a single column to .NET and convert it to a native .NET type then I could finally overcome the mystery of explicitly looping on objects via COM (which is super slow a...
This is a follow up to Extending the VBAExtensibility Library. It turns out that code had a really nasty bug. Anytime vbeProcedure.StartLine got called, I was running the risk of hitting runtime error 35 because CodeModule.ProcStartLine has to be told what kind of procedure it's looking for. Ever...
You're right. You need a better regex, but not exactly for the reason you mentioned. The one you're using is indeed very permissive. It misses many of the cases that need to be checked for.
Use the following rules when you name procedures, constants,
variables, and arguments in a Visual Ba...
@Mat'sMug I'm attempting to work Delegate.Create("ExistingFunctionSignature") into delegate. That way we don't need to use Delegate.Create("(x1, x2) => ExisitingFunctionSigature(x1, x2)")
anyway I think I'm going to make a bunch of little private functions and work with InStr and Mid and Left and other string-helpers, to extract the good stuff and flag the bad stuff. will be more readable than that regex
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Why?
oh and this too
Me.SqlDataAdapter3 = New System.Data.SqlClient.SqlDataAdapter
Me.SqlDeleteCommand2 = New System.Data.SqlClient.SqlCommand
Me.SqlInsertCommand2 = New System.Data.SqlClient.SqlCommand
Me.SqlSelectCommand3 = New System.Data.SqlClient.SqlCommand
Me.SqlUpdateCommand2 = New System.Data.SqlClient.SqlCommand
Me.SqlDataAdapter4 = New System.Data.SqlClient.SqlDataAdapter
Me.SqlDeleteCommand3 = New System.Data.SqlClient.SqlCommand
Me.SqlInsertCommand3 = New System.Data.SqlClient.SqlCommand
wait there's more
Me.SqlSelectCommand6 = New System.Data.SqlClient.SqlCommand
Me.SqlInsertCommand5 = New System.Data.SqlClient.SqlCommand
Me.SqlUpdateCommand5 = New System.Data.SqlClient.SqlCommand
Me.SqlDeleteCommand5 = New System.Data.SqlClient.SqlCommand
Me.SqlDataAdapter6 = New System.Data.SqlClient.SqlDataAdapter
Me.SqlDataAdapter7 = New System.Data.SqlClient.SqlDataAdapter
Me.SqlDeleteCommand6 = New System.Data.SqlClient.SqlCommand
Me.SqlInsertCommand6 = New System.Data.SqlClient.SqlCommand
and
Me.SqlDataAdapter8 = New System.Data.SqlClient.SqlDataAdapter
Me.SqlDeleteCommand7 = New System.Data.SqlClient.SqlCommand
Me.SqlInsertCommand7 = New System.Data.SqlClient.SqlCommand
Me.SqlSelectCommand8 = New System.Data.SqlClient.SqlCommand
Me.SqlUpdateCommand7 = New System.Data.SqlClient.SqlCommand
Me.SqlConnection2 = New System.Data.SqlClient.SqlConnection
there is like 4 connections in there somewhere too. this is one code file......
Well using an existing function as a delegate will be hard; you don't get any help from the compiler here, so you'll have to traverse every single module in every VBAProject in sight, and then hope only 1 function goes by that name - then generate the function call.. but may I ask why you'd want to call a statically declared function this way? I can't think of a use case :(
Or maybe the compiler can help, and resolve the call alone....
Hmm
TBH I wrote this specifically so I could write some LINQ-like code that can "query" an Enumerable that would contain objects. Like (x) => Left(x.Name, 3) = ""vba""" to get all elements where the Name property started with "vba"
...but without enforcing anything but the fact that the function takes an element from the enumerable, and returns a Booean.
It would feel weird having a module exposing functions like NameStartsWithVba(ByVal row As SqlResultRow) As Boolean...