RubberDuck #40
Replies: 9 comments 14 replies
-
@MarkJohnstoneGitHub, thanks for the ideas/suggestions - will look into Rubberduck and the alternative Class creation method(s). On the MS Access compile issue - is the ThisWorkbook reference the only problem you ran into to get this to work in MS Access, or is it just the first? If you have time/interest to look into what changes would be needed in total to make this compatible with MS Access, I certainly would be willing to consider implementing those changes, as long as we can preserve the current Excel functionality. I just don't have the time to do the brute-force trail blazing for that kind of out-of-scope endeavor - I bet there will be many more than that one issue, which by itself, seems very fixable. If you are interested in making a contribution in that direction, would you be willing to open a new discussion on "MS Access Compatibility" and then use that to report on the problems/potential fixes encountered? That would be very useful and welcomed. Thanks again! |
Beta Was this translation helpful? Give feedback.
-
Wow - sounds like you have some work ahead of you. Why not see if you can get it to work first (at the most basic level), and then deal with the code "cleanup"? You may end up spending a lot of time cleaning, only to find that there are several functional aspects that won't translate to MS Access without major refactoring. Seems like the code cleaning would be wasted effort in that case.... I just took a quick look at your Dictionary wrapper - very cool - thanks for sharing... Like I said earlier, I will look into RD when I get time - it's not the highest priority since the code currently seems to work fine in Excel. But I do appreciate that it could be written better and may take that on (hopefully with the help of other contributors) when time permits. :-) I do appreciate any progress that you can make in assessing the feasibility of using this in MS Access. Thanks. |
Beta Was this translation helpful? Give feedback.
-
PS: As a first pass feasibility assessment, I would use either of the ThisWorkbook.Path reference solutions that were presented as the accepted answer in the StackOverflow link that you mentioned in your original post - either one of those would allow you to move forward, and then once you are functional, we can return to that issue to find the best generalized solution for Excel/Access. I'm going to open a discussion on MS Access Compatibility that I hope you will contribute to. I suggest we leave coding style/cleanup for this RubberDuck discussion and not mix the two.... |
Beta Was this translation helpful? Give feedback.
-
Hi @MarkJohnstoneGitHub, we put class constructors inside the SeleniumVBA addin module in order to be able to instantiate multiple objects of the same class, when keeping the SeleniumVBA addin module separate from the user code. RubberDuck: I already used it months ago to clean another project and it was very time consuming to spot the 5% good findings of the Code Inspector out of 95% junk or questionable findings, even after filtering only for Errors and Warnings (no Suggestions and Info). |
Beta Was this translation helpful? Give feedback.
-
I just used RubberDuck to add VB_Description attributes to all methods/properties in the WebActionChain class - very useful for that purpose indeed! As @6DiegoDiego9 mentioned, there were a lot of what seemed non-critical suggestions, some of which I implemented, and many that I deferred... Maybe the app would be useful in helping to enforce a coding-style standard, especially given the multiple contributors that the project enjoys. Something to consider... |
Beta Was this translation helpful? Give feedback.
-
WebKeyboard class could benefit to be predeclared and no need to instantiate and use the default instance. One of the rare times using the default instance might be appropriate. It appears to be a static class behaving similar to an Enum Type which can't store string literals. Other benefits might be some small performance gains. EG. From the test_SendKeys
|
Beta Was this translation helpful? Give feedback.
-
@MarkJohnstoneGitHub - makes sense. What would be the downside if user "unintentionally" or even intentionally instantiated your WebKeyboardPD class? The intentional case: I like the readability of keys.LeftKey over WebKeyboardPD.LeftKey, so I instantiate Dim keys as New WebKeyboardPD. Would that cause a problem? |
Beta Was this translation helpful? Give feedback.
-
@6DiegoDiego9, I could not get the "Dim keys as WebKeyboardPD" and you're ready to use "keys" to work. Here are my tests: 'Attribute VB_Name = "WebKeyboard"
'Attribute VB_GlobalNameSpace = False
'Attribute VB_Creatable = False
'Attribute VB_PredeclaredId = True
'Attribute VB_Exposed = True
Sub test_internally_referenced()
Dim keys As WebKeyboard
'Debug.Print keys.LeftKey 'this does not work
Set keys = New WebKeyboard
Debug.Print keys.LeftKey 'prints \ue012
Debug.Print WebKeyboard.LeftKey 'prints \ue012
End Sub
Sub test_externally_referenced()
Dim keys As WebKeyboard
'Debug.Print keys.LeftKey 'this does not work
Set keys = SeleniumVBA.New_WebKeyboard
Debug.Print keys.LeftKey 'prints \ue012
Debug.Print WebKeyboard.LeftKey 'prints \ue012
End Sub Anyway, I'm not feeling the compelling reason to pre-declare, but I don't as yet see a downside either. It would seem to add another modality for doing things without affecting a user that either intentionally or unintentionally instantiates the class. So I'm indifferent - if this change makes some current and/or future users happy, then we should probably make the change(?). |
Beta Was this translation helpful? Give feedback.
-
I will push a commit this week to predeclare, along with some more RD method descriptions. As for enforcing singleton... The reason I'm uncomfortable is because enforcement doesn't seem to protect the user from doing any self-harm, rather, at best it serves to educate the non-expert (like me!) about the advanced nuts and bolts of object instantiation, which I have personally enjoyed thank-you, but at worst will serve to confuse - how many users will know what a "predeclared instance" is? Seems like more potential downside than upside... What about WebJsonConverter - should we predeclare that one too? |
Beta Was this translation helpful? Give feedback.
-
I've had a brief look at your project it looks great. I would highly recommend using RubberDuck https://rubberduckvba.com/ to help maintain your project. It's an extremely helpful VBA development tool.
Some observations.
I'm not a fan of Class Factory modules and probably can be implemented using a predeclared classes and a constructor method in the class. See VBA Attribute VB_PredeclaredId = True . I haven't used accessing classes outside of the current project with the VB_Exposed attribute I'm assuming it should work.
eg In a predeclared WebDriver class
Public Function Create() As WebDriver
Set Create = New WebDriver
End Function
A couple of good articles regard VBA OOP
https://rubberduckvba.wordpress.com/2018/04/24/factories-parameterized-object-initialization/
https://rubberduckvba.wordpress.com/2020/02/27/vba-classes-gateway-to-solid/
I'm a bit rusty on the VBA OOP possibly a Get Self property may be appropriate as demonstrated in the 2nd article. From memory you need to careful not using the default instance unintentionally.
IMO for class private variables it's clearer to place into a private type and declare a private variable named This. It's explained in one of those articles.
eg WebDriver class
Private Type TWebDrive
sessionId_ As String
driverUrl_ As String
'etc
End Type
Private This As TWebDriver
I'm using MS Access 2016 and WebShared.bas wouldn't compile due to Excel reference ThisWorkbook.Path . Is there a generic VBA method that would be appropriate? Maybe CurDir()? It however defaults to the user/documents instead of the application file location.
Other possible solutions see:
https://stackoverflow.com/questions/45854327/constant-that-indicates-access-or-excel
Beta Was this translation helpful? Give feedback.
All reactions