Naming controls

When you place a control in a window, PowerBuilder assigns it a unique name. The name is the concatenation of the default prefix for the control name and the lowest 1- to 4-digit number that makes the name unique.

For example, assume the prefix for ListBoxes is lb_ and you add a ListBox to the window:

  • If the names lb_1, lb_2, and lb_3 are currently used, the default name is lb_4

  • If lb_1 and lb_3 are currently used but lb_2 is not, the default name is lb_2

About the default prefixes

Each type of control has a default prefix for its name. The following table lists the initial default prefix for each control (note that there is no prefix for a window).

Control

Prefix

Animation

am_

CheckBox

cbx_

CommandButton

cb_

DataWindow

dw_

DatePicker

dp_

DropDownListBox

ddlb_

DropDownPictureListBox

ddplb_

EditMask

em_

Graph

gr_

GroupBox

gb_

HProgressBar

hpb_

HScrollBar

hsb_

HTrackBar

htb_

InkEdit

ie_

InkPicture

ip_

Line

ln_

ListBox

lb_

ListView

lv_

MonthCalendar

mc_

MultiLineEdit

mle_

OLE 2.0

ole_

Oval

ov_

Picture

p_

PictureHyperLink

phl_

PictureButton

pb_

PictureListBox

plb_

RadioButton

rb_

Rectangle

r_

RichTextEdit

rte_

RoundRectangle

rr_

SingleLineEdit

sle_

StaticText

st_

StaticHyperLink

shl_

Tab

tab_

TreeView

tv_

User Object

uo_

VProgressBar

vpb_

VScrollBar

vsb_

VTrackBar

vtb_


Changing the default prefixes

You can change the default prefixes for controls in the Window painter's Options dialog box. Select Design>Options from the menu bar to open the Options dialog box. The changes you make are saved in the PowerBuilder initialization file. For more about the PowerBuilder initialization file, see How the PowerBuilder environment is managed.

Changing the name

You should change the default suffix to a suffix that is meaningful in your application. For example, if you have command buttons that update and retrieve database information, you might call them cb_update and cb_retrieve. If you have many controls on a window, using intuitive names makes it easier for you and others to write and understand scripts for these controls.

Using application-based names instead of sequential numbers also minimizes the likelihood that you will have name conflicts when you use inheritance to create windows.

To change a control's name

  1. Select the control to display the control's properties in the Properties view.

  2. On the General tab page, select the application-specific suffix (for example, the 1 in the cb_1 command button name) and type a more meaningful one.

You can use any valid PowerBuilder identifier with up to 255 characters. For information about PowerBuilder identifiers, see the section called “Identifier names” in PowerScript Reference.