« first day (129 days earlier)      last day (3051 days later) » 

00:28
VBE gotta be the way to do it right then ;)
 
14 hours later…
14:34
bump
 
2 hours later…
16:43
bump
 
1 hour later…
17:52
Looks like @vba4all dropped by with some solid advice.
1
A: Building a better Collection. Enumerable in VBA

vba4allOn top what other experts have mentioned already I would like to suggest an idea; Since you implementing wrapper functions you could also handle the really generic and ugly errors like when a user was trying to Enumerable.Remove 999 and 999 was an index out of bounds you could take a bet...

Oh. Hey! You found our chat room.
18:20
yeah
i have noticed you have been doing some pretty interesting things with VBA
haven't had much time to properly reply to every question but i enjoyed reading them + solutions
2
18:40
I'll be home in a few hours, will be working on a Delegate class :)
18:50
Hey I didn't realize there is a chat room for VBA
I've done a ton of VBA dev in the past few years. not sure I'm as experienced as you folks though...
 
4 hours later…
22:25
Hey @enderland! We actually just revived this room. Feel free to poke your head in. =)
I'm not all that experienced myself, so no worries.
well isn't this interesting ^^
I'll just call it Execute then :)
22:56
ugh.. I knew it wasn't going to be that easy.
I can generate the code:
Public Function Anonymous1() As Variant
MsgBox "Hello from anonymous method!"
End Function
..but I can't run it :(
@RubberDuck I've done a lot of Access vba recently and have done a fair bit of C++ back a few years ago, so I've got a bit of the "WHY CANT I DO THIS IN VBA" thing going
especially with custom structs :(
and the editor. zomg the editor
@enderland hi! Type in VBA is rather... limited - better off with a class :)
@Mat'sMug I know but it feels SO WRONG to have a class with all public variables :)
make 'em properties?
Mainly because I want to be able to put a bunch in one module so I don't clutter the stupid editor
There's not a way to add folders to the editor right?
I use MZtools which has a lot of nice features but that's not one of them
@Mat'sMug Yeah
23:01
hmm.. not folders, but...
I think that dictates more of my design than anything else, in my access work project I have too many modules (well more like 30 or so) which gets tricky
Some of them I've named in such a way to sort, too
VBA does reflection?
Or is that a "Mat's way" :)
nope. it's just a "Mat's way" wrapper around VBE ;)
I'm trying to emit code on-the-fly - that part works...
the part that doesn't, is the part that's trying to call that code :(
are you writing the module and then importing it?
I've got some stuff like that, too, overloading event handlers (my users want to push changes immediately for all textbox changes in Access on some of their forms - immediately - whatever, it's whatever they want even if it breaks part of the way access) which feels like a hack
Well I have this AnonymousMethod class that's basically just a placeholder for on-the-fly code
set x = Delegate.Create("() => MsgBox ""Hello from anonymous method!""")
x.execute
that generates a method in the AnonymousMethod class:
Public Function Anonymous1() As Variant
MsgBox "Hello from anonymous method!"
End Function
and then this fails:
Execute = CallByName(New AnonymousMethod, methodName, VbMethod, vbEmpty)
does it recompile at all?
23:07
that's exactly the problem
it thinks "Anonymous1" doesn't exist as a member of AnonymousMethod
I'd assume you cannot force a recompile during execution
looks like I'm F'd.
What is CallByName ?
Well depends on if you are ok with temporary files
I'd imagine you could write a .vbs file and then run it or something if you wanted to
23:08
CallByName lets you pass an object and specify the method name you want to call, pass it arguments, and retrieve a return value - i.e. exactly what I need!
oooh
I think I've used that or seen it before, I forget why though ha
Gotcha, so you're trying to use that so you don't have to get compile errors for "Anoynomous1" basically
only I pass a New AnonymousMethod that has no members because the member hasn't compiled yet
I was sort of relying on the "interpreted" nature of the language.. perhaps pushing it a little.
well VBA runs into weird quirks in that regard, I think activeX objects have similar problems with the "interpreted" part
I think it might work if I just leave a method stub in there
I imagine it would
I was just wondering if you could pull something similar off by removing option explicit and then trying to call Anonymous1 without having written it
23:11
...but I need the signature to be dynamic, too.. can't work.
but I'm pretty sure that will still be a compile runtime error
how do you run a .vbs file from VBA?
that might work
You can run shell commands and do all sorts of stuff with VBA
4
A: Calling a .vbs scipt from Excel VBA

Alex K.To run a file; Shell "wscript c:\null\a.vbs",vbNormalFocus replacing wscript with cscript if the VBS want to use the console. Or you can add a reference to the Microsoft Script Control and interact with the VBScript runtime directly to execute VBS strings, procedures etc; Dim scr As ScriptCo...

I think that has what you are looking for
can that return me a value?
Not sure if you can return objects from a vbs script though
jinx ha
23:14
ugh this is so frustrating
I'm not sure how VBA handles that honestly, I don't think running a script using Shell would work but I do know you can link to native libraries and use their objects
but I don't think you'd be able to do that runtime?
I need to find a way. There has to be a way!
So you basically are looking to do custom methods on the fly right?
For example, you might have a database of different messagebox combinations you want to be able to generate as methods (granted you could do messageboxes really easily with storing text but it's a good example)
And you want to pass in the string text for the method and execute it -- realtime
well the msgbox is really just a "hello world".. the idea is to end up being able to write a predicate..
set x = Delegate.Create("(x) => x.Name = ""foo""")
and implement a Where(predicate As Delegate) method in my List class :)
Same idea, the messagebox is just an easy example, so you'd want basically to be able to have customized realtime code ?
23:18
yup
I honestly have no idea if you can basically add a vbs script as a reference to a VBA project to let you use it's objects
26
A: How to add a reference programmatically vba-Excel

Siddharth RoutOmmit There are two ways to add references via VBA to your projects 1) Using GUID 2) Directly referencing the dll. Let me cover both. But first these are 3 things you need to take care of a) Macros should be enabled b) In Security settings, ensure that "Trust Access To Visual Basic Project...

you can add references programmatically so presumably you could do something similar, if .VBS scripts can be added as references
that'd let you do what you want, you'd just have to write out your custom .vbs class/methods and then add them immediately afterwards
I've just never tried to reference a .VBS script - I normally reference system libraries or basically APIs
oh wait
Application.Run can return a value
So that should work?
Lots of speculation on my part ha!
hold on
That'd be easier though
Since you could write the .VBS (or any scripting language I guess, but might as well be VBS/VBA) and just return the object and use it
You wouldn't need to fuss with references at all then
I'd assume that would work for you though, it's probably the same idea as using any of the "CreateObject" methods for built-in objects
23:22
ah, but then the difficulty is to pass the parameters
Also is this just for fun? I'm trying to think of a good work-world use case for abusing VBA this bad ;)
just for fun indeed... but then if I get it to work, it becomes part of my toolbox, which I use at work :)
Hah! I have a harder time testing VBA at home since I use a mac, and the editor on mac for vba makes me cry
oh, the IDE makes me cry on Windows just as well, no worries :)
Try using the one on mac.. every dockable window from the editor is it's own floating window
23:27
they can't be docked?
No
Haha
try dragging them - they're "floatable" on ..oh
No I mean they are all separate windows and don't dock at all
ooooh fun
each of those windows (debug, editor, and project editor) are all. freaking. separate.
To make matters worse they don't always stack nicely either so sometimes it's a pain tracking one down
23:33
oh
set x = Delegate.Create("() => MsgBox ""Hello from anonymous method!""")
x.execute
^^ works!!!
So is that using .Run?
yeah
Public Function Execute(ParamArray params()) As Variant

    Const methodName As String = "AnonymousMethod"
    GenerateAnonymousMethod

    If UBound(params) = -1 Then

        Execute = Application.Run(methodName)

    Else

        Execute = Application.Run(methodName, params(0))

    End If

End Function
^^ gotta figure out how to pass parameters now
So you could theoretically construct really complicated code on the fly and use that, huh
well a whole theoretical world of possibilities has just opened right before my eyes
delegates & anonymous methods, ..in VBA.
wow
I can now write code that takes a Delegate parameter...
:)
So VBA realtime compiles the anoymousmethod?
23:38
no clue
I'm rather surprised that works
me too, but utterly happy about it!
what does your Create method look like?
Public Function Create(ByVal expression As String) As Delegate

    Dim result As New Delegate

    Dim regex As New RegExp
    regex.Pattern = "^\((([a-zA-Z][a-zA-Z0-9]*)(\,\s)?)*\)\s\=\>\s(.*)"

    Dim regexMatches As MatchCollection
    Set regexMatches = regex.Execute(expression)

    If regexMatches.Count = 0 Then
        Err.Raise 5, "Delegate", "Invalid anonymous method expression."
    End If

    Dim regexMatch As Match
    For Each regexMatch In regexMatches
        If IsEmpty(regexMatch.SubMatches(0)) Then
that too needs some fine-tuning
brb
How about the Delegate class?
23:52
I'm going to rename this room "Abusing VBA like a red headed step child"
I think I found a solution to my VBE problem by the way @Mat. Screw regex. I have the LIKE keyword.
I just need to find a little time to test it.
Wait... We can reference the .Net platform from VBA. I wonder if there's a way to access delegates...

« first day (129 days earlier)      last day (3051 days later) »