New Keywords Low() and High()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Axolotl
Addict
Addict
Posts: 835
Joined: Wed Dec 31, 2008 3:36 pm

New Keywords Low() and High()

Post by Axolotl »

Explanation (why this request)
I use the Enumeration very often.

Code: Select all

Enumeration EWindow 
  #WND_Main 
  #WND_Preview 
  ; ... 
EndEnumeration 

Enumeration EGadget 
  #GDT_btnRefresh 
  #GDT_lstPreview 
  ; ... 
EndEnumeration 
You can also continue the enumeration by naming it. For example In an include file.

Code: Select all

Enumeration EWindow 
  #WND_Editor 
  ; ... 
EndEnumeration 

Enumeration EGadget 
  #GDT_Editor_btnApply 
  #GDT_Editor_edtContent  
  ; ... 
EndEnumeration 
With these new procedures it could be possible to deal with all items.

Code: Select all

Low(<Enumeration>) 
High(<Enumeration>) 

Code: Select all

  ;// sample code 
  For idxWindow = Low(EWindow) To High(EWindow) 
    HideWindow(idxWindow, #True) 
  Next idxWindow 


Maybe there is a small problem with the use of the optional [step]
My work-around so far is like this:

Code: Select all

 
;// add this lines behind the first Enumeration 
Macro Lo_Window : #WND_Main : EndMacro  ; <= my style guide requires #WND_Main as the first Window (Value == 1) 
Macro Hi_Window : #PB_Compiler_EnumerationValue : EndMacro 
;// add this line behind the next Enumerations 
UndefineMacro Hi_Window : Macro Hi_Window : #PB_Compiler_EnumerationValue : EndMacro 
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
User avatar
Demivec
Addict
Addict
Posts: 4267
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: New Keywords Low() and High()

Post by Demivec »

Axolotl wrote: Sat May 17, 2025 10:57 am Explanation (why this request)
I use the Enumeration very often.
You can also continue the enumeration by naming it. For example In an include file.
Axolotl wrote: Maybe there is a small problem with the use of the optional [step]
Enumerations do not have to be sequential. Besides [step] you can set individual values at any time with [=].

Your idea doesn't sound like new keywords, it sounds like new compiler functions.
They would really be useful with named enumerations. I don't see a real need for them otherwise.

There are possible workarounds but I won't go into those as this isn't the forum for questions on coding. :wink:


@Edit: This posting was edited numerous times before it took its final form (in case you wondered why the message contents changed after you read it).
Axolotl
Addict
Addict
Posts: 835
Joined: Wed Dec 31, 2008 3:36 pm

Re: New Keywords Low() and High()

Post by Axolotl »

@Demivec. You are right, Keyword is not a proper name for this. On the other hand I would not make any suggestion on implementation.

BTW: I added a work-around already, even if this is not the right place to do so. Because I was not asking for any work-arounds.
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
Post Reply