I'm just getting into using Rubberduck for my VBA applications. I came across a great post on adding attributes here:
How to set the Attribute VB_PredeclaredId using RubberDuck '#PredeclaredID
However, what if I want to remove the attribute? It seems like the only way to do it is via code inspections. However, after you initially set the '#PredeclaredId, there's no longer any error that shows up. So the option to remove the attribute is no longer available.
I tried deleting the attribute, but the "Predeclared" annotation is still in my explorer:
I'm sure I can export, edit in the text editor, and then re-import again, but one purpose of rubberduck is to avoid doing that.
Thanks.
After deleting the attribute annotation there will be a new "attribute value out of sync" inspection with 2 options:
adjust attribute value
adjust annotation
You want to do the first option which will nuke the hidden attribute value.
Update
Another 2 alternatives:
indent the module ctrl+m
cut and paste the code ctrl-a ctrl-x ctrl-v
Both these options will wipe out the attribute values by forcing VBA to recompile the module without them. This is normally an annoyance (indenting my project wipes the attributes and I need to restore them with RD annotation inspections)
Final thing remember to refresh RD code explorer so it picks up the changes and the icon will change. This often happens automatically though.
Related
I recently discovered that is possible to use Attribute [ProcedureName].VB_*, inside procedures.
What I found
But this code is not shown inside VBA Editor.
Same code in VBA Editor (left) and exported .cls in Notepad (right)
When Attribute is written inside VBA Editor, it's marked red
Attributes added manually in the VBA Editor
The question
Is there more elegant way how to maintain these Attributes than export class module, edit them outside and import them back (facepalm needed)?
Also I haven't found official documentation for these Attributes (on https://learn.microsoft.com/en-us/office/vba/).
Thank you!
PS: As always I hitted something interesting and related just after Question had been sent. A step-by-step example on Microsoft Docs site suggests to do it by Export-Edit-Import method :(
The process for getting Rubberduck to apply annotations requires a few steps.
Execute a Rubberduck refresh. If the code does not compile cleanly then Rubberduck will show a 'Parse Error'. In this case you need to sort out your code first. This can be an issues if you are applying Rubberduck to an existing code base. If not then learn to compile and rubberduck.Refresh early and regularly (i.e. after every complete edit)
If Rubberduck parses successfully you then need to look at Rubberduck.Code Inspections. To take action about an inspection result select the individual result and right click. This will provide a list of actions that can be applied by Rubberduck.
I'm using CLion IDE, and I really enjoy it, but one thing is quite annoying and I can't get rid of it.
CLion highlights every function declaration that overrides another function in base class with "Annotate this function with override or (rarely) final". As far as I know override keyword is an optional keyword. I would use it, but I recently joined this big sized project and I want to stay consistent to its conventions - and they don't use override keyword.
But the problem is that I couldn't find anywhere in CLion's settings where to disable this highlight option (I've tried using search option in settings, but still nothing).
It is a bit annoying because it highlights most of functions in my derived classes, and I have to mouse over it to check if it is an important notice, or just this "Annotate this...".
You can find on this link from jetbrains.com some explanations on how to disable inspections.
One of these method is temporary : Use the widget in the top-right corner of the editor and select the level 'None' in the Highlight list.
I recently did some refactoring in our code and marked some widely-used functions as obsolete. The problem now is, that I get not visual indicator when I use an obsolete function right away. I have to hover over the function call to get the popup with further information about that function, and even there the "deprecated" warning is not very prominent. As these functions are to widely-used and cause no real treat, setting the isError property is not an option.
I know that somewhere I saw obsolete functions that were highlighted with some kind of underlining, but I can not find an option that does that. Where is that option, or how else can I achieve a more eye-catching indication?
I have created a simple toy VB.Net console application in MSVS, as you can see in the image the items marked obsolete are underlined in green where they are used.
If you are not seeing this then you will need to provide some more details on your solution's settings - what type of project is it, what version of visual studio are you opening it in, is it the same version it was created in, do you have any third party code linter (eg ReSharper) in use... etc
EDIT: As you mention in your comment, the project's properties, including the Code Analysis settings, will affect whether this underlining show's correctly or not; you will need to ensure the correct rule-set is selected there.
When running a program I need to see every time a certain button is disabled and step through the code at that point.
If I set a breakpoint with a condition
(ex: only hit when button1.enabled=false) it will only hit in that specific place.
Is it possible to set a breakpoint on the entire program so that i can see when a condition changes across many forms and locations?
You can't set one breakpoint and have it apply to every line of the file, but you can set a breakpoint on the setter of Enabled and then filter it to a specific filter condition. That would give you the desired result. (Note, you might need to turn off "Just my code", see this question for more info)
Set a breakpoint using the "New Breakpoint At Function" as described here, though in Visual Studio 2013, I seem to need to use a slightly different notation:
Then set the breakpoint to funtion:
System.Windows.Forms.Control.Enabled
in C# or for VB.NET:
System.Windows.Forms.Control.set_Enabled(bool)
(You seem to need to use the class that actually defines the property, which in case of the Button class' Enabled property, is the Control class the Button inherits from.
Ignore the warning about it not being able to find the function (it does that for properties somehow), or uncheck the Intellisense lookup.
Now look up the breakpoint in the Breakpoints list and customize the condition so it breaks on the right button
Use the Name property (or any other filter that makes the breakpoint unique) to trigger when you need it to:
When it breaks, it will break in the sources of Control (if you have Framework Source Stepping enabled), which may be confusing. Use the Stack Trace window to find the location where the method was invoked exactly.
Another way of setting the breakpoint is through the Stacktrace window. Set a breakpoint on any line that has your property of interest on it. Launch the debugger and make it break on that line, now use "Step into Specific" to step into the property that you want to break on.
Use the "Stack" window to generate the breakpoint for you:
Since in your case you're looking to break on a function from the Microsoft .NET framework, there is another way. Enabled Framework Source Stepping.
Open the Visual Studio Debugger options and enable "Framework Source Stepping" and disable "Just My Code".
Then enable the Microsoft Symbol Servers in as instructed. Now load up your application under the debugger and wait for the symbol files to be downloaded.
set a break point anywhere in your code that is somehow related to System.Windows.Forms (The constructor of your MainForm for example) and rightclick any function from the "System.Windows.Forms" assembly to load the symbols for that assembly. This will allow you to step into the "Enabled" property and set a break point there.
A full tutorial can be found here:
http://blogs.msdn.com/b/sburke/archive/2008/01/16/configuring-visual-studio-to-debug-net-framework-source-code.aspx
I have been writing some VBA code to produce charts automatically, and at one point named a variable "CHARTTITLE" not realizing that this is a member of the Chart object. I have deleted this variable upon realizing my mistake. However, since doing so, wherever I employ something like
Charts(1).ChartTitle.Text =
It will automatically auto-capitalize to
Charts(1).CHARTTITLE.Text
I have tried search and replace over the entire project from .CHARTTITLE to .ChartTitle to no avail. I have also tried employing Option Explicit also without effect. I am worried that there is now some sort of memory issue or that I've overwritten something important. Is there any way to reset this back to its default state?
It's a benign effect and it's a long-standing bug relating to the way that VBA stores itself internally. A couple of things to try:
Change the first occurrence of CHARTTITLE in the module, or if in multiple modules in the first module that appears in the project explorer.
Export the module, remove it from the project, edit it using your favourite text editor and reimport it.