IntelliJ: Change access modifier for list of vars - intellij-idea

Noob programmer here. I'm reorganizing a bunch of the code for a small crappy videogame I'm making right now in LibGDX. I'm moving a bunch of vars from a class that were declared as private into a separate class. I tried to lookup a quick way that I could change all of the vars from private to public all at once, but alas no luck. I can click on each individual var and wait for the lightbulb to show up so that I can click "change access modifier", but it'd be really nice if there were a way to highlight all of them at once and change them all to public. Bonus points if I can change them all to public and static at the same time. (I know that having a class of nothing but public static non-final vars is supposed to be frowned upon, but whatever, it makes things a heck of a lot cleaner! Don't judge me!)

You may create the search and replace template ie like follows:
then create an inspeciton from it, run and press the "replace all" button:
For more info please see: https://www.jetbrains.com/help/idea/structural-search-and-replace.html#structural_replace

Related

How to clear all public variables?

Is it possible to clear all public variables without the needs to define one by one. It is like you press reset button in VBA. Is there any kind of code to do that?

Best practice for using main form controls

So lets say I have a form1 that opens on startup. Form1 contains a textbox named textbox1 and a button named button1. When I click button1 this is code that is called:
Class form1
Sub CapLetters () 'buttons click event
Dim myObj as new MyObject
MyObj.CapAllLetters
Textbox1.text = MyObj.GetThoseCapLetters
End sub
End class
Now, I know this is kinda dumb, but my main question is, since im creating a new object, the textbox1 will not be available in my object unless I specifically call it like:
Form1.textbox1.text
Is this good practice or is there a better way? Now in my program I have about 10 textbox and comboboxs I need my object to use. I know i could do something like this:
MyObj.CapAllLetters (textbox1.text)
But that doesn't seem like a good idea to pass that many values in a method.
I think I need a way for my object to gather all the info upon initating it?
Thoughts?
You basically seem to be asking whether it's OK to use the default instance of a form. The answer is yes. In recent versions of VB, each form that has a parameterless constructor also has a default instance, which is a single instance that can be accessed anywhere and at any time via the class name. This feature exists because it makes it easier for beginners to access forms from different places in a project without having to worry about passing references to forms around that project.
In the case of the startup form in a project, it is always the default instance of its type, assuming that you haven't disabled the application framework. That means that you can always access your startup form anywhere in your project using the default instance of its type.
Now, you'll find that experienced developers rarely use default instances. That's because they are never required and rarely add value if you know what you're doing. That means that you can always access your application's startup form is reasonable locations throughout your project without using the default instance.

VBA OOP extending existing classes

I'm a rookie at VBA(Excel) but I know some OOP stuff from java. What I want to do is extend the class MSForms.TextBox to add my own constructors and properties. I've tried using the implements keyword but my class won't compile. It would also be helpful to add these fields into some kind of container variable since they're arranged in a 9x9 pattern. Here's what I want my custom textbox to do. (It's for a game)
I need to be initiate it and place it on the form and put initial text into the box based on what is passed to the constructor. I also would like to have it check the values at runtime with an event to make sure they comply with the game rules. If it does not comply I would like to change the background color to red.
I'm able to do all of this when I just make a bunch of form controls the old fashioned way and use a sub controlled by a button to check the text box values.
Any help on extending classes would be much appreciated.
Thanks
I don't think you can do that in VBA. I would keep two arrays, one array of TextBox and one array of a new class representing your extended properties. Then you keep them in sync. e.g. Textbox #71 and extended properties #71.
You can look at the following link for making and working with control arrays.
http://www.siddharthrout.com/index.php/2018/01/15/vba-control-arrays/

Create a shared copy and paste menu for my grids

I have 20 or so grids in my application suite. I'd like to create a global copy/paste context menu which I can bind to every single grid rather than code in each form.
I am unsure what is the best way to achieve this, I have started to create a class with my menu in it, but get stuck at the point of adding the actual menu options. For example I know I'll need to call a "copy" event, but I also know I'll need to tell it what I am copying, and I cannot see how that is done in vb.net when you can only add the address of a method minus parameters.
e.g.
.MenuItems.Add("Copy Cell", New System.EventHandler(AddressOf CopyCell))
Obviously I want "CopyCell" to only be coded in one place as well, rather than repeated in each form. I will always be copying the same object (SelectedCellCollection).
I am not sure how to make the menu have an event with parameters, or how to make it "know" that I want to always copy the selected items. I'm aware that I'd have to do some coding in the form but just trying to work out the way to minimize it.
I have created my own context menu class (via inheritance) with specific copy and paste functionality / options tailored to the grid I am using. It works fine and only needs one line of code per form/grid to activate.

VBA - Import namespaces?

Is it possible to import namespaces in VBA? I'm writing Word macros and I want to put all functions inside Modules or Classes. But once I do that I see that I cannot reach the controls in the VBA form easily. I have to include the name of the form first, then access the control within that one. I can't just go
TextBox1.Caption
I have to go
Form1.TextBox1.Caption
Is there a way to get around this?
You shouldn't be coupling your classes/modules so tightly. A worker module shouldn't require knowledge of the Form1 class, because then it can't be used separately in another project.
Instead, you probably want to pass the function in your helper class an argument on which it performs work, and then returns the result (if necessary). As a completely useless, trivial example:
Public Sub SetLabelText(ByVal lbl As Label, ByVal caption As String)
lbl.Caption = caption
End Sub
And you would call it from within the form class, like so:
MyHelpers.SetLabelText(Label1, "New Label Caption")
That way, you can use the functions in your helper class from any form.
But, as far as your actual question, no. VBA doesn't have any concept of "namespaces". The best you can do is the With statement, but having to do this frequently is more likely an indication of a design flaw, as I discussed above.