"Me" keyword for current gadget number

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

"Me" keyword for current gadget number

Post by PB »

I would like to see an internal variable (called "Me" like in Visual Basic)
that holds the current gadget number that was created by any of the
gadget commands, to reduce typing the same gadget name over and
over. Sort of like With/EndWith. Here's what I mean:

Code: Select all

Enumeration
  #NumberSelection
  #NameList
EndEnumeration

If OpenWindow(0,300,250,400,200,"test",#PB_Window_SystemMenu)

  ComboBoxGadget(#NumberSelection,10,10,70,22)

    AddGadgetItem(#NumberSelection,-1,"One")
    AddGadgetItem(#NumberSelection,-1,"Two")
    AddGadgetItem(#NumberSelection,-1,"Three")
    SetGadgetText(#NumberSelection,"One")
    GadgetToolTip(#NumberSelection,"Sets the number")

  ListIconGadget(#NameList,100,10,200,100,"Names",180)

    AddGadgetItem(#NameList,-1,"Fred")
    AddGadgetItem(#NameList,-1,"Freak")
    AddGadgetItem(#NameList,-1,"Berikco")
    DisableGadget(#NameList,#True)
    GadgetToolTip(#NameList,"List of team members")

  Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow

EndIf
The above code could be replaced with something like this:

Code: Select all

Enumeration
  #NumberSelection
  #NameList
EndEnumeration

If OpenWindow(0,300,250,400,200,"test",#PB_Window_SystemMenu)

  ComboBoxGadget(#NumberSelection,10,10,70,22)

    AddGadgetItem(Me,-1,"One")
    AddGadgetItem(Me,-1,"Two")
    AddGadgetItem(Me,-1,"Three")
    SetGadgetText(Me,"One")
    GadgetToolTip(Me,"Sets the number")

  ListIconGadget(#NameList,100,10,200,100,"Names",180)

    AddGadgetItem(Me,-1,"Fred")
    AddGadgetItem(Me,-1,"Freak")
    AddGadgetItem(Me,-1,"Berikco")
    DisableGadget(Me,#True)
    GadgetToolTip(Me,"List of team members")

  Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow

EndIf
See how it eliminates the need to type the gadget's constant name over
and over? The internal variable "Me" would just be updated by the
compiler every time a new gadget command is reached. Don't give it
a long name (like "CurrentGadget") because that defeats the purpose.
I just want something quick to type in place of the gadget number so
I don't need to type the name again and again every time I add to it.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
magicjo
User
User
Posts: 61
Joined: Sun May 07, 2006 10:43 am
Location: Italy

Post by magicjo »

Fred tell me that the feature will be added for 4.50 version :lol: , for now use the macros.
PB Registered User, Egrid Registered User
Win7 x64 Ultimate, 4,00 Gb Mem, Ati Radeon HD4600 Series, Realtek High Definition Audio Integrated
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

Can't you just use a variable called "Me" ?
quidquid Latine dictum sit altum videtur
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

Instead of 'Me' one could use '#TheNrOfTheLastGadgetIReferencedToInMyCode', but I have to admit that isn't shorter ;-)

I see the point though :-)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
milan1612
Addict
Addict
Posts: 894
Joined: Thu Apr 05, 2007 12:15 am
Location: Nuremberg, Germany
Contact:

Post by milan1612 »

Seems reasonable to me and could be quite useful. But I'd like it to work with all
PB identifiers, with files or network connections and so on...
Windows 7 & PureBasic 4.4
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

A keyword like '#Last'... but that could get complicated when mixing up types...

Then #LastGadget, #LastFile etc. but those mean you'd have longer to type...

Unless the compiler would be smart enough and turn #Last into a contextual value based upon the preceeding source code. Hmm. Even a preprocessor could do that :-)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> Can't you just use a variable called "Me" ?

Okay, yes, but I didn't mention it could be used for more than just gadget
creation. For example, later in the same example app above, the compiler
could use "Me" again with a code block like this:

Code: Select all

ClearGadgetItems(#NameList)
AddGadgetItem(Me,-1,"gnozal")
AddGadgetItem(Me,-1,"Sparkie")
SetActiveGadget(Me)
To use a variable manually, means putting "Me=#NameList" everywhere in
my source, as well as for every other gadget. The aim is to save typing. ;)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

To me this just sounds messy. It decreases the readability of the code imho. And wait until you copy/paste/move some code around and wonder why everything is messed up just because there is a gadget command somewhere in between.

Also you don't always need the compiler's help for things like this:

Code: Select all

Global Me

Procedure SetMe(Value)
  Me = Value
  ProcedureReturn Value
EndProcedure

ClearGadgetItems(SetMe(#NameList))
AddGadgetItem(Me,-1,"gnozal")
AddGadgetItem(Me,-1,"Sparkie")
SetActiveGadget(Me) 

Besides, your constant names are rather short. My longer ones look like this: :D

Code: Select all

#DEBUGGER_GADGET_Variable_InputRange
quidquid Latine dictum sit altum videtur
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Post by Demivec »

If the "Me" existed would it only be translated when used in those contexts or would you now lose the use of a variable with the same name?

I think that's way the names for things like this have always resembled something like #PBCompiler_LastGadgetNumber. It gave it meaning and also didn't interfere with your own names for things.


The idea seems useful but brings with it complications like the aforementioned.

Here's a crazy variation of it (that has its own problems):

Code: Select all

Enumeration
  #NumberSelection
  #NameList
EndEnumeration

If OpenWindow(0,300,250,400,200,"test",#PB_Window_SystemMenu)
  
  ComboBoxGadget(#NumberSelection,10,10,70,22)
  
  With #NumberSelection
    AddGadgetItem(##,-1,"One")
    AddGadgetItem(##,-1,"Two")
    AddGadgetItem(##,-1,"Three")
    SetGadgetText(##,"One")
    GadgetToolTip(##,"Sets the number")
  EndWith
  
  ListIconGadget(#NameList,100,10,200,100,"Names",180)
  
  With #NameList
    AddGadgetItem(##,-1,"Fred")
    AddGadgetItem(##,-1,"Freak")
    AddGadgetItem(##,-1,"Berikco")
    DisableGadget(##,#True)
    GadgetToolTip(##,"List of team members")
  EndWith
  
  Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
  
EndIf
cas
Enthusiast
Enthusiast
Posts: 597
Joined: Mon Nov 03, 2008 9:56 pm

Re: "Me" keyword for current gadget number

Post by cas »

PB wrote:I just want something quick to type in place of the gadget number so
I don't need to type the name again and again every time I add to it.

Code: Select all

;{ 

Macro ComboBoxGadgetEx(gadget,x,y,Width,Height,Flags=0)
  ComboBoxGadget(gadget,x,y,Width,Height,Flags) : Me=gadget
EndMacro

Macro ListIconGadgetEx(gadget,x,y,Width,Height,Title,TitleWidth,Flags=0)
  ListIconGadget(gadget,x,y,Width,Height,Title,TitleWidth,Flags) : Me=gadget
EndMacro

;insert here all other macros...

Global Me ;this var can be made local if writing threaded app

;}

Enumeration
  #NumberSelection
  #NameList
EndEnumeration

If OpenWindow(0,300,250,400,200,"test",#PB_Window_SystemMenu)

  ComboBoxGadgetEx(#NumberSelection,10,10,70,22)

    AddGadgetItem(Me,-1,"One")
    AddGadgetItem(Me,-1,"Two")
    AddGadgetItem(Me,-1,"Three")
    SetGadgetText(Me,"One")
    GadgetToolTip(Me,"Sets the number")

  ListIconGadgetEx(#NameList,100,10,200,100,"Names",180)

    AddGadgetItem(Me,-1,"Fred")
    AddGadgetItem(Me,-1,"Freak")
    AddGadgetItem(Me,-1,"Berikco")
    DisableGadget(Me,#True)
    GadgetToolTip(Me,"List of team members")

  Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow

EndIf 
8)
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> To me this just sounds messy

Visual Basic coders have done it that way for decades, as evidenced by lots
of source code listings on dozens of Visual Basic sites. It's tried and true. ;)

@Cas: Nice example, but doesn't fulfill the second part of my request, that
is, later calls to the gadget that was created. Also it means I have to add lots
of macros to my app (one for every gadget), which is time-wasting. (Example:
One of my apps has an on-screen keyboard, so I'd need 101 macros. :( ).

I think I'll try my hand at a pre-processor one day. I've never done it before.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

Whats wrong with my example ? Its only seven characters more to type than your original proposal. You can't be that lazy :P
quidquid Latine dictum sit altum videtur
cas
Enthusiast
Enthusiast
Posts: 597
Joined: Mon Nov 03, 2008 9:56 pm

Post by cas »

freak wrote:Whats wrong with my example ?
Your solution is definitely best here (and easiest to implement).
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

You are misunderstanding the 'Me' keyword in VisualBasic. Visual Basic is an object oriented basic, and the 'Me' refers to the current object, like 'This' in JAVA or C#. It's only available when you act from inside the object. PB doesn't have object, so such a keyword is not possible.
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

freak wrote:To me this just sounds messy. It decreases the readability of the code imho.
Yep, agreed! Just use a variable.
PB wrote:Visual Basic coders have done it that way for decades, as evidenced by lots of source code listings on dozens of Visual Basic sites.
Doesn't make it right or well designed.
--Kale

Image
Post Reply