cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Super User
Super User

Naming conventions for controls, any tips?

Interested to know what others do about naming conventions for controls.

 

 

I'm coming from an Access background for forms creation where control names only have to be unique to their parent form. You tend to reference a control by its parent form, e.g. MyForm.MyControl. 

 

In PowerApps every control name must be unique, but I frequently have the 'same' control on multiple screens (e.g. Control 'CustomerName' may appear in a New Customer screen, Edit Customer screen, Customer Gallery screen and so on).

 

I've taken to prefixing every Control name with the name of the screen on which it appears and giving every screen a name related to its function/data, e.g. scnNewCustomer.DataCardCustomerName. This results in very long-winded control names, but at least avoids name clashes and confusion when reading formulae. 

 

6 REPLIES 6
Super User
Super User

Re: Naming conventions for controls, any tips?

I'm doing it in a similar way, but I tend to put hte screen name last, and have an abbreviation of the type of control first, so a label on the main screen would be namned lblAccountHdrscrMain, a drop down would be ddAccountList etc. Furthermore I group items a lot, and the group's name will start with grp and then something descriptive, like grpAccountInfo. I haven't done that many apps yet though, so I tend to experiment a bit and change things around.

 

It certainly does not make for short namnes, but I think it will be easier to maintain in the long run, especially if someone else takes over. If there is something I strongly dislike it's going through undocumented and poorly written code!

 

One thing I miss (or have missed how to do) is the ability to search and replace names of global variables once they are being used. Examnple: I used Set(nLeftMargin, 4) in an app with lots of fields and rectangles but as things evolved, as they tend to do, I use the same variabel for both left and right margin as well as spacing within fields, so I'd like to change name to reflect this. Now I have used it in too many places so it's not really possible without putting a lot of time into it.

 

 

 

mx
Level 8

Re: Naming conventions for controls, any tips?

@PaulD1

In having worked with Access for almost 25 years and counting ... I can appreciate the need for Naming Conventions ala the original Leszynski/Reddick Naming Conventions back in the day.

 

"but at least avoids name clashes and confusion when reading formulae. "

Exactly !  

At this point in PowerApps relatively short existence ... using ANY sort of consistent naming convention will be ahead of the game.My conventions are still a moving target which each new app I do ... as new elements (objects/controls) are put in use 🙂

 

 

DatabaseMX ('mx')
Microsoft Access MVP
Anonymous
Not applicable

Re: Naming conventions for controls, any tips?

"In PowerApps every control name must be unique" ==> why is this?

Super User
Super User

Re: Naming conventions for controls, any tips?

In, for example, MS Access, a control name only needs to be unique to the screen (form) on which it appears. When you reference a control it is assumed to be on the same form unless you qualify the reference by giving the form name followed by a period followed by the control name.
In PowerApps you don't qualify a reference with the form name, so every control name must be unique. If two or more controls had the same name, how would the system know which you were referencing? Perhaps think of it like cells in Excel. Every one has a unique 'name'.
CurranD
Level: Powered On

Re: Naming conventions for controls, any tips?

Tend to use ScreenControlDescription e.g. a label on the home screen for users would be HsLblUsers

 

Makes it easier when reading though code to know whats being reffered to & also if you were looking for a label on the home screen you'd just type HsLbl and it would list all 🙂

mx
Level 8

Re: Naming conventions for controls, any tips?

Overall, I suggest adopting a *consistent* naming convention for yourself and use it.

DatabaseMX ('mx')
Microsoft Access MVP

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors
Users Online
Currently online: 177 members 4,600 guests
Please welcome our newest community members: