« first day (130 days earlier)      last day (3050 days later) » 

00:03
That would be cheating!
@enderland I'm putting it up for review on the main site when I'm done implementing it all :)
No such thing as cheating.
you'd have to expose a wrapper around it though
00:26
ooh this is sooooo cool
Public Function AnonymousMethod(ByVal x As Variant, ByVal y As Variant) As Variant
MsgBox "Hello " & x & " from anonymous method!" & y
End Function
set x = Delegate.Create("(x,y) => MsgBox ""Hello "" & x & "" from anonymous method!"" & y")
x.execute "Mug", "it works!"
now return values
oh this is more complicated than I thought
only because there's no return statement in VBA :(
Public Function AnonymousMethod(ByVal x As Variant) As Variant
x > 10
End Function
^^ won't compile
ok got it.
writing up the post
00:45
Awesome
01:09
I feel like creating the tag
0
Q: Generating and calling code on the fly

Mat's MugDelegate 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

needs better title I think
oh I can't have a Where method on my System.Enumerable class
...
I need to implement an Enumerable class in my Reflection project instead.
01:24
I don't think our mods would like that tag much... But at least one of them would get a good laugh out of it.
I'm not even going to try to digest that until morning.
I'm sure it's easier to grok than the fancypants WinAPI solutions you've been looking at ;)
01:41
I'm sure. I'm just brain dead atm.
02:16
so cool
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"))
^^ prints 6
03:00
great, I can now persist the anonymous method between calls, and still have 20 delegate instances alive :)
03:45
ugh. nevermind that. doesn't work.
not cleanly that is
 
5 hours later…
08:25
I see where you're going with this

`?Enumerable.FromEnumerable(List.Create(10,12,4321,4324,324,324,320,2,32,54,99).ToEnumerable).CountIf(Delegate.Create("(x) => x < 100"))`
thats awesome actually...
 
1 hour later…
09:52
just an idea... feel free to tell me im stupid if I am hehe
0
A: Generating and calling code on the fly

vba4allNOTE - 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....
 
2 hours later…
11:47
I think you covered it in either approach. Personally, I like the optional args because it cleans up that nasty switch.
yeah that select case hurt my eyes :P
> In the static Range() you should at least check that the endValue > startValue, and Repeat() the times > 1
In the current version, it actually runs backwards if endValue > startValue =;)-
Good call though.
backwards?
oh you meant "current" version
@RubberDuck are you any good with COM/.NET ?
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....
12:17
Hmm...
Interesting question. I've not done a whole lot of com stuff with .Net
as of now I am just passing it as Excel.Range then in .NET converting to either System.Array or object[,]
but then ... i want object[x] where x is the entire column
obviously without looping
that's the whole point
hm wait what does Range.Columns(1) return?
ehh seems like Range/Range not a one dimensional array ;/
What about a reference to .Net System?
you mean mscorlib.dll?
Yeah. I have no idea, just grasping at straws. Maybe you can get to List<T> with a reference to it.
but now I am just trying to initialize a 1d array based on a column from a Range object
so basically how to dimension a 1d array from Range("A1:A10")
so in VBA i think this would work
Dim arr1D As Variant
arr1D = Application.Transpose(Range("A1:A10").Value)

Dim v() As Variant
v = arr1D
but .Net doesn't understand Variant :P
12:34
But it understands Object, no?
Hmmm... Idk @vba4all. A bit over my head.
ok no worries thanks
oh yea
got it!!!!!!!!!!!
finally!
Oh! Good!
yeah i'll post my progress and ask for tips later
13:44
lol anyone ever thought about rewriting the Range class? :P
addings things like Range().RemoveDuplicates() ?
14:39
what I was talking about earlier
0
Q: Passing a 1D array (single column of a Range object) to .NET to manipulate it without loops and returning it back to VBA

vba4allBackground 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...

 
1 hour later…
15:49
That's almost exactly why I created that "Enumerable" class. So I could pass a range in and call Distinct on it.
haha
i prefer passing it to .NET and using ready-to-go sweets on it rather than rewritting it all :P
i have written my own enumerable class a few years ago
I am going to have to take a look at that later when I get home if I have time.... (LOL have time, there is a thought from a pipe dream)
who just left?
the more time i spend with C# the more I hate VBA
3
anyhow i am off for the night
16:10
@Malachi Probably enderman
yep the smiley face.
 
1 hour later…
17:11
If line Like "[!']* Property *" Then
Yeah...... That works like a charm.
17:25
@RubberDuck interesting.. could I use Like instead of a regex?
(it's Enderland ;)
@Mat'sMug Ooops...... Sorry @enderland!
Ummmm...... regex has it's strengths too, but Like makes it a whole lot easier to negate.
Well C# regex are nice.. scripting/vba regex are a PITA
Finally undeleted this one
2
Q: Ugly workaround to get the vbext_ProcKind of a procedure is breaking encapsulation

RubberDuckThis 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...

Nice!
Between you & I, I'm not sure I'm catching all of the edge cases, but I've not had any issues with this version yet.
17:32
I have a different approach to wrapping VBE, should I also put it up for review?
That's up to you, but I wouldn't mind seeing it. I really don't like how much my CodeModule now knows about Procedures.
But if I don't grep it up front, errors ensue.
time to take a break. bbiab
17:46
ahhhhhhh much better
18:23
@RubberDuck :D
@Mat'sMug yeah they are way limited and slightly different, just for fun!
19:10
I hate regular expressions. The devil himself must have spec'd that syntax.
1
A: Generating and calling code on the fly

RubberDuckYou'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...

Mwahahaha
@RubberDuck the shitty part is dealing with SubMatches in-code.. drives you nutz!
I hate regex too because so often they are an easy and good solution
19:33
@enderland That's exactly the problem. They're a great tool for the job, but grokking the syntax is a nightmare.
@ptwales I fixed the directory case issue. You should be able to sync now.
I also fixed the bugs that have been driving me nuts.
20:24
@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)")
20:41
Might work, with a global-scope function (i.e. not an object method)
true nor a builtin function Trim won't work
What is the case for If regexMatch.SubMatches(0) = vbNullString Then in Create?
Parameterless function :)
I really feel like didtching the regex altogether
what would that look like?
I can't get it to trigger. Though I am using rubberducks regex
it might have broken it
I had a more "specs-compliant" regex before, but couldn't extract the groups properly
so I ended up with that "anything goes" regex
yeah its "(([a-Z]][a-zA-Z0-9_]*))\s\=\>\s(.*)" that breaks it
the first [a-Z] require at least 1 instance.
20:51
shouldn't it be [a-zA-Z]?
Ummm yup. It should.
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
Isn't the same effect?
I wouldn't trust VBA regex to be too clever ;)
Ditching regex would be the best solution.
20:53
^^ that
 
1 hour later…
21:55
Check this out
'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......
22:15
This code is horrible!
22:29
Step 1: take a deep breath ;)
Step 2: extract the data access code into its own class!
Step 3: refactor ADO.NET crap to Entity Framework
Or LINQ-toSQL at least
ADO.NET is tech from 10 years ago...
(says the mug writing stuff with tech from 20 years ago)
@ptwales why wouldn't Trim work? MsgBox works just fine?!
22:59
Oh, wait.. nevermind.
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...

« first day (130 days earlier)      last day (3050 days later) »