Hello, people,
I have a user form ufCommands with more then 200 CommandButtons
And I have code for each Command buttonBy example:Private Sub CommandButton252_Click()flag_arrange = 1'85 x 53 ÐÀÇÌÅÐ ÍÀ ÄÆÎÁÍÎ ÊÀËÅÍÄÀÐ×Å'80 x 40 ÐÀÇÌÅÐ ÍÀ ÒÅÊÑÒÀ'MsgBox ActiveShape.LeftX & " " & ActiveShape.CenterXFor X = 1 To 12CommandButton251_ClickNext XMe.HideCommandButton255_ClickCommandButton254_Clickmgroup.CenterX = mrect.CenterXmgroup.CenterY = mrect.CenterY - 5.5 / 25.4Set mgroup1 = ActiveLayer.Shapes.All.GroupFor X = 1 To 4Set mgroup1 = mgroup1.Duplicate(0, mgroup1.SizeHeight)NextSet mgroup1 = ActiveLayer.Shapes.All.GroupSet mgroup1 = mgroup1.Duplicate(mgroup1.SizeWidth, 0)Set mgroup1 = ActiveLayer.Shapes.All.Groupmgroup1.CenterX = ActivePage.CenterXmgroup1.CenterY = ActivePage.CenterYUnload MeEnd Sub
Code above is started when CommandButton252_ClickYou can see, that CommandButton252_Click callCommandButton251_ClickCommandButton255_ClickCommandButton254_Click
When I write this code many months ago it's simple to remember where this Command buttons are, but now i can not find there.To find CommandButton251 i use this code:Private Sub CommandButton274_Click()If COLORFLAG = 1 ThenMYCOLOR = CommandButton251.BackColor'MsgBox MYCOLORCommandButton251.BackColor = vbBlackCOLORFLAG = 2Else'MsgBox MYCOLORCommandButton251.BackColor = MYCOLORCOLORFLAG = 1End IfEnd Sub
The meaning of the above code is that when the first time it is launched the background color of the search button becomes black and this is clearly visible. When the code is run again, the background color of the searched button becomes what it was at the beginning.
Please help to improve this code. How to find CommandButton254, CommandButton255 in one other, more improved way?Thanx!
I don't understand the usefulness of so many buttons... Perhaps it is a case of grouping them by the similarity of function they perform. You could use MultiPage to create these groupings of correlated functions, and so you could better distribute these buttons.
Have you ever thought about renaming the buttons, with intuitive names, for example the button with text "Change All Text", use the name "ChangeAllText_Button" define the name using UpperCamelCase to define the characteristic of the variable and separate the component with an underline, " ChangeAllText_Button","ChangeAllText_Label","ChangeAllText_ComboBox"
This will help you a lot in the future.
6 coding best practices for beginner programmers (educative.io)
Hello,Thank You for this answer!This form is my labor, my experiment place. It's great idea to place all necessary macros in just one form. If You see, I have green buttons on form. Clicking on one of them opens this form in design mode. More then. I have class CommandButton. So when i click with LMB on right site of button - Click event fires. But when click with RMB - Command Button code is opened. There are many other benefits of using one form to store many macros. By example - sharing and archiving the code.Greetings!
Hello,Thank You for this answer!Of course I use intuitive names, but when ideas come fast, there is no time for it The question is fundamental.Many thanks for the link to a beginner's guide. An inquisitive Person can always learn something new.Thank You!