# How to get Button Control USE name or Any Window Control

**URL:** <https://clarionhub.com/t/how-to-get-button-control-use-name-or-any-window-control/8214>\
**Category:** code\
**Tags:** language\
**Created:** [May 22, 2025, 5:41pm UTC](https://clarionhub.com/t/how-to-get-button-control-use-name-or-any-window-control/8214 "2025-05-22T17:41:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![CarlBarnes](https://clarionhub.com/user_avatar/clarionhub.com/carlbarnes/32/1859_2.png) [@CarlBarnes](https://clarionhub.com/u/CarlBarnes)\
**Post date:** [May 22, 2025, 5:41pm UTC](https://clarionhub.com/t/how-to-get-button-control-use-name-or-any-window-control/8214/1 "2025-05-22T17:41:39Z")

</div>

I saw this post out in DiscussSV Clarion 11 and thought it had some useful content that was not on the Hub.

Oggy posted:

How to get button(s) use variable name?  
for example:

```clarion
  Loop k# = FIRSTFIELD() to LASTFIELD()
      IF k#{prop:type} = Create:Button
          stop(k#&' , '&k#{PROP:use}) ! I need to get used name of button control
      END
  END

```

---

<div class="post-metadata">

**Author:** ![CarlBarnes](https://clarionhub.com/user_avatar/clarionhub.com/carlbarnes/32/1859_2.png) [@CarlBarnes](https://clarionhub.com/u/CarlBarnes)\
**Post date:** [May 22, 2025, 5:45pm UTC](https://clarionhub.com/t/how-to-get-button-control-use-name-or-any-window-control/8214/2 "2025-05-22T17:45:06Z")

</div>

Jeff replied with a perfect example of using the undocumented RTL function Cla$FIELDNAME:

```clarion
  PROGRAM
  MAP
    MODULE('')
      FEQtoFieldName (SIGNED pFeq), *CSTRING, RAW, NAME('Cla$FIELDNAME')
    END
  END

Window WINDOW('Caption'),AT(,,395,224),GRAY,FONT('Segoe UI',9)
              BUTTON('&OK'),AT(291,201,41,14),USE(?OkButton),DEFAULT
              BUTTON('&Cancel'),AT(340,201,42,14),USE(?CancelButton)
            END
  CODE
  OPEN(Window)
  MESSAGE('?OkButton FEQ='& ?OkButton & |
         '|FEQ to Field Name='& FEQtoFieldName(?OkButton)) 

```

Above I enhanced the original `MESSAGE(FEQtoFieldName(?OkButton))`

---

<div class="post-metadata">

**Author:** ![CarlBarnes](https://clarionhub.com/user_avatar/clarionhub.com/carlbarnes/32/1859_2.png) [@CarlBarnes](https://clarionhub.com/u/CarlBarnes)\
**Post date:** [May 22, 2025, 7:10pm UTC](https://clarionhub.com/t/how-to-get-button-control-use-name-or-any-window-control/8214/3 "2025-05-22T19:10:29Z")

</div>

I normally wrap calls to the Cla$FIELDNAME function to catch some problems. If there is no USE(), or the FEQ is invalid, then the FieldName returns blank so this returns ` __Feq_####__ ` to have an idea of what control it was. When FEQ=0 it returns `'Window'` … I know of no way to get the Window Label at runtime.

```clarion
  MAP
ClaFeqName PROCEDURE(LONG Feq),STRING,PRIVATE    
      MODULE('RTL')
ClaFieldNameRTL PROCEDURE(LONG pFEQ),CSTRING,RAW,NAME('Cla$FIELDNAME'),DLL(dll_mode)
      END
  END

ClaFeqName PROCEDURE(LONG F)!,STRING
n CSTRING(128)
  CODE
  if ~F then return 'Window'. 
  n=ClaFieldNameRTL(F)
  if n <= ' ' then 
     n = ' __Feq_'& F &'__' !No USE(?xx) so return __Feq_#__
  end
  return n

```

---

<div class="post-metadata">

**Author:** ![CarlBarnes](https://clarionhub.com/user_avatar/clarionhub.com/carlbarnes/32/1859_2.png) [@CarlBarnes](https://clarionhub.com/u/CarlBarnes)\
**Post date:** [May 22, 2025, 7:31pm UTC](https://clarionhub.com/t/how-to-get-button-control-use-name-or-any-window-control/8214/4 "2025-05-22T19:31:11Z")

</div>

A related post is this that gets the FEQ for a Report control

> [@Get label of USE variable of REPORT control at runtime](https://clarionhub.com/t/get-label-of-use-variable-of-report-control-at-runtime/4729/22):
>
> Jeff I added/changed some things for these reasons: Prototype change WINDOW to REPORT. Works the same, more obvious to pass REPORT. For Header,Detail,Footer… types that cannot clone to WINDOW by return “\_Type\_FEQ\_#” If blank FEQ Name returned by ClaFieldNameRTL() then return "\_RptFEQ\_#’ Open Dummy Window will change Target() so restore SetTarget(Report) RptControlFEQName PROCEDURE(LONG ControlFEQ, REPORT ReportRef)!,STRING !works passing REPORT DummyWindow WINDOW,AT(-10,-10,1,1) …

---

<div class="post-metadata">

**Author:** ![CarlBarnes](https://clarionhub.com/user_avatar/clarionhub.com/carlbarnes/32/1859_2.png) [@CarlBarnes](https://clarionhub.com/u/CarlBarnes)\
**Post date:** [May 22, 2025, 9:05pm UTC](https://clarionhub.com/t/how-to-get-button-control-use-name-or-any-window-control/8214/5 "2025-05-22T21:05:20Z")

</div>

> [@CarlBarnes](#):
>
> ```clarion
> Loop k# = FIRSTFIELD() to LASTFIELD()
> IF k#{prop:type} = Create:Button
> stop(k#&' , '&k#{PROP:use}) ! I need to get used name of button control
> END
> END
> 
> ```

One other detail is FIRSTFIELD() and LASTFIELD() are somewhat deprecated as they can return control numbers that do not exist due to gaps. The better way is to use PROP:NextField:

```clarion
FldNo LONG
    CODE 
    FldNo = 0
    LOOP 
        FldNo = 0{PROP:NextField, FldNo} !instead of First / LastField()
        IF FldNo = 0 THEN BREAK.
        IF FldNo{prop:Type} = Create:Button
           stop('FEQ='& FldNo &' , Use='& ClaFeqName(FldNo) ) 
        END        
    END 

```
