Page 1 of 2

PureBasic Gadget Numbering System

Posted: Sun Oct 09, 2016 9:34 am
by VB6_to_PBx
PureBasic Gadget Numbering System

i find this Code to be convenient for handling a lot of various Program Inputs (50+)

Level 1 :
; 0 - 999 = Total of StringGadget and ComboBoxGadget ( 1000 Total possible values for Inputs )
Basically for example ,
my 1st Input or Choice is a ComboBoxGadget which i number as number 1
; 1000 - 1999 = TextGadgets only to use for 0-999 Gadgets ( 999 Total possible values )
but before it, i have a TextGadget , which i number 1001

then my 2nd Input is a StringGadget , which i number as number 2
Level 2 :
; 1000 - 1999 = TextGadgets only to use for 0-999 Gadgets ( 999 Total possible values )
but before it, i have a TextGadget , which i number 1002

and so on .........

__________________________________________________________________________

then maybe sometimes i might have a :

TextGadget + ComboBoxGadget + TextGadget + StringGadget ( all on same Line in Program )
this is where the 3rd Level comes in :
; 2000 - 2999 = extra TextGadget, StringGadget, ComboBoxGadget ( 999 Total possible values )

i would then Number the Gadgets like this

TextGadget(1003) + ComboBoxGadget(3) + TextGadget(2003) + + StringGadget(3)
and so on ........


All the primary Inputs or Choices use progressively increasing Gadget Numbers
like 1,2,3,4.... so on

all the TextGadgets use progressively increasing Gadget Numbers
like 1001, 1002, 1003, 1004, to correspond to the Primary Inputs

and the 3rd Level is used for multiple Gadgets on 1 Program Line
Level 3 :
or can use one of the --> 3000 - 3199 = Miscellaneous Gadgets ( 199 possible values )

__________________________________________________________________________


the ComboBoxGadget "Flag" ... is used to make an Editable ComboBoxGadget
"not" editable ... and to retain the original choice
if the User enters incorrect Keys or values

the reason i use an editable ComboBoxGadget ( that's made non-editable )
is to maintain same "look" as a StringGadget and TextGadget
in a large Program with 50+ Inputs

an editable ComboBoxGadget can have same height as a StringGadget and TextGadget
which allows a better looking text Font to fit inside the height of an
editable ComboBoxGadget -VS- normal graphic looking ComboBoxGadget ,
and at same time , increases Screen real-estate when having to fit a bunch of Gadgets

Code: Select all

;-----< Top >-----

;        Calculate_Cubic_Inches_with_ComboBox_FLAG_v1.pb

;-............... PureBasic  Gadget  Numbering  System ......................................................
;
;        5000 - 9999 = CatchImage         ( 4999 possible values )    ( .PNG , .JPG , .BMP , etc. )
; 
;        4800 - 4999 = Windows            (  199 possible values )
;        4600 - 4799 = Menu               (  199 possible values )
; -----------------------------------------------------------------------------------------------------------
;        4300 - 4599 = ContainerGadget    (  299 possible values )
;        4000 - 4299 = ButtonGadget       (  299 possible values )
;        3700 - 3999 = ButtonImageGadget  (  299 possible values )
;        3400 - 3699 = ImageGadget        (  299 possible values )
;        3300 - 3399 = CanvasGadget       (   99 possible values )
;        3200 - 3299 = EditorGadget       (   99 possible values )
;        3000 - 3199 = Miscellaneous      (  199 possible values )      #Dummy_Focus = 3199
; -----------------------------------------------------------------------------------------------------------
;        2000 - 2999 = TextGadget, StringGadget, ComboBoxGadget  (  999 Total possible values )
;        1000 - 1999 = TextGadgets only to use for 0-999 Gadgets (  999 Total possible values )
;            0 - 999 = Total of StringGadget and ComboBoxGadget  ( 1000 Total possible values for Inputs )
;____________________________________________________________________________________________________________

EnableExplicit

;~~~~~ Constants List
#Window_0 = 0
#Menu_0 = 1
#CalcTextBox = 2000
#HelpTextBox = 3000
#CalculateButton = 4000

#Tahoma10 = 4
#Verdana9 = 5
LoadFont(#Tahoma10,"Tahoma", 10)
LoadFont(#Verdana9,"Verdana", 9)

Global.i WW, EW, EG, EM
;      WW = WaitWindowEvent()     ; EventID  = WaitWindowEvent()
;      EW = EventWindow()         ; WindowID = EventWindow()
;      EG = EventGadget()         ; GadgetID = EventGadget()
;      EM = EventMenu()           ; MenuID   = EventMenu()


Global Cylinders.i , Bore.d , Stroke.d , CID.d , wFlags.i, Flag


Declare Help(Index.i)
Procedure Help(Index.i)
    Protected Help_Txt.s
    Select Index
    Case 1 : Help_Txt = " Choose :  Number of Cylinders  (  1  to  16   Default = 8 Cylinders )"
    Case 2 : Help_Txt = " Cylinder Bore in inches      ( Valid Range= 1.000  to  7.000 inches )"
    Case 3 : Help_Txt = " Crankshaft Stroke in inches  ( Valid Range= 1.000  to  7.000 inches )"
    EndSelect
    
    SetGadgetText(#HelpTextBox,Help_Txt)
EndProcedure


Declare InputMAX()
Procedure InputMAX()
    ;Beep_(2500,200)
    ;~~~~~~~~~~ Result = MessageRequester(Title$, Text$ [, Flags])   ;~~~~~~~~~~ 2= CANCEL  6= YES  7= NO
    ;~~~~~~~~~~ #PB_MessageRequester_Ok          ;~~~~~~~~~~  'OK' only one button (Standard)
    ;~~~~~~~~~~ #PB_MessageRequester_YesNo       ;~~~~~~~~~~  'YES' or 'NO' buttons
    ;~~~~~~~~~~ #PB_MessageRequester_YesNoCancel ;~~~~~~~~~~  'YES', 'NO' and 'CANCEL' buttons
    Protected Title$ = "ERROR  :  Input  exceeded  the  Valid  Range"
    Protected Text$ = "Input exceeded the maximum allowed value ...." + #CRLF$ + #CRLF$ + "Please enter a Value within the Valid Range"
    MessageRequester(Title$, Text$, #PB_MessageRequester_Ok)
EndProcedure


Declare ComboMAX()
Procedure ComboMAX()
    ;Beep_(2500,200)
    ;~~~~~~~~~~ Result = MessageRequester(Title$, Text$ [, Flags])   ;~~~~~~~~~~ 2= CANCEL  6= YES  7= NO
    ;~~~~~~~~~~ #PB_MessageRequester_Ok          ;~~~~~~~~~~  'OK' only one button (Standard)
    ;~~~~~~~~~~ #PB_MessageRequester_YesNo       ;~~~~~~~~~~  'YES' or 'NO' buttons
    ;~~~~~~~~~~ #PB_MessageRequester_YesNoCancel ;~~~~~~~~~~  'YES', 'NO' and 'CANCEL' buttons
    Protected Title$ = "ERROR  :   Invalid  Keyboard  Key  Pressed"; + Space(5)
    Protected Text$ = "Valid Keyboard Keys are :" + #CRLF$ + #CRLF$
    Text$ + "F4 = ( Dropdown or Close ComboBox )" + #CRLF$+ #CRLF$
    Text$ + "Arrow Up" + #CRLF$
    Text$ + "Arrow Down" + #CRLF$
    Text$ + "Arrow Left" + #CRLF$
    Text$ + "Arrow Right" + #CRLF$
    Text$ + "Page Up" + #CRLF$
    Text$ + "Page Down" + #CRLF$
    Text$ + "Home" + #CRLF$
    Text$ + "End" + #CRLF$ + #CRLF$
    Text$ + "Enter  or  Return" + #CRLF$
    Text$ + "Escape ( Esc )" + #CRLF$
    Text$ + "Tab" + #CRLF$ + #CRLF$ + #CRLF$
    Text$ + "Note :  Default Choice will now be used !" + #CRLF$ + #CRLF$
    Text$ + Space(2) + "... make sure this new Choice is correct ?" + #CRLF$ + #CRLF$
    MessageRequester(Title$, Text$, #PB_MessageRequester_Ok)
EndProcedure


Declare Calc_CID()
Procedure Calc_CID()
    Protected Title$ = "  ERROR  :  Input  Value  is  less  than  Valid  Range   "
    Protected Text$ = "  Input is less than the minimum allowed value "  + #CRLF$ + #CRLF$ + "  Please enter a Value within the Valid Range " + #CRLF$

    Protected Cnt.i
    For Cnt = 1 To 3
         If ValD(GetGadgetText(Cnt)) < 1
              SetGadgetText(Cnt,"")
              MessageRequester(Title$, Text$, #PB_MessageRequester_Ok)             
              SetActiveGadget(Cnt)
              ProcedureReturn
         EndIf
    Next Cnt

    Select GetGadgetState(1)
    Case 0 : Cylinders = 1
    Case 1 : Cylinders = 2
    Case 2 : Cylinders = 3
    Case 3 : Cylinders = 4
    Case 4 : Cylinders = 5
    Case 5 : Cylinders = 6
    Case 6 : Cylinders = 8
    Case 7 : Cylinders = 10
    Case 8 : Cylinders = 12
    Case 9 : Cylinders = 16
    EndSelect

    CID = Bore * Bore * Stroke * Cylinders * #PI/4  ;<--- 0.78539816339744828
    SetGadgetText(#CalcTextBox,"CID = " + StrD(CID,5))
    SetActiveGadget(1)
EndProcedure



OpenWindow(#Window_0, 0, 0, 440, 300, "Calculate Cubic Inch Displacement", #PB_Window_SystemMenu | #PB_Window_ScreenCentered )

    CreateMenu(#Menu_0, WindowID(#Window_0))
         MenuTitle("Exit")
              MenuItem(0,"Quit  Program")

    TextGadget(1001,3,61,58,18," Cylinders") : SetGadgetFont(1001,FontID(#Tahoma10)) : SetGadgetColor(1001,#PB_Gadget_BackColor,RGB(250,250,250))
    ComboBoxGadget(1,63,60,39,20,#PB_ComboBox_Editable) : SetGadgetFont(1,FontID(#Verdana9))
         AddGadgetItem(1, -1, " 1")    ; 0
         AddGadgetItem(1, -1, " 2")    ; 1
         AddGadgetItem(1, -1, " 3")    ; 2
         AddGadgetItem(1, -1, " 4")    ; 3
         AddGadgetItem(1, -1, " 5")    ; 4
         AddGadgetItem(1, -1, " 6")    ; 5
         AddGadgetItem(1, -1, " 8")    ; 6  =  8 Cylinders = Default choice
         AddGadgetItem(1, -1, "10")    ; 7
         AddGadgetItem(1, -1, "12")    ; 8 
         AddGadgetItem(1, -1, "16")    ; 9
         SetGadgetState(1,6) ;6  =  8 Cylinders = Default choice

    TextGadget(1002,3,81,58,18," Bore") : SetGadgetFont(1002,FontID(#Tahoma10)) : SetGadgetColor(1002,#PB_Gadget_BackColor,RGB(250,250,250))
    StringGadget(2,63,80,84,20,"",#PB_Text_Center) : SetGadgetFont(2,FontID(#Verdana9)) : SetGadgetAttribute(2,#PB_String_MaximumLength,10)

    TextGadget(1003,3,101,58,18," Stroke") : SetGadgetFont(1003,FontID(#Tahoma10)) : SetGadgetColor(1003,#PB_Gadget_BackColor,RGB(250,250,250))
    StringGadget(3,63,100,84,20,"",#PB_Text_Center) : SetGadgetFont(3,FontID(#Verdana9)) : SetGadgetAttribute(3,#PB_String_MaximumLength,10)

    ButtonGadget(#CalculateButton,26,124,70,20,"Calculate") : SetGadgetFont(#CalculateButton,FontID(#Verdana9))
    GadgetToolTip(#CalculateButton, "Calculate Cubic Inches")

    TextGadget(#CalcTextBox,3,150,142,18,"",#PB_Text_Center) : SetGadgetFont(#CalcTextBox,FontID(#Verdana9)) : SetGadgetColor(#CalcTextBox,#PB_Gadget_BackColor,RGB(255,255,255))

    TextGadget(#HelpTextBox,5,200,400,18,"") : SetGadgetFont(#HelpTextBox,FontID(#Tahoma10)) : SetGadgetColor(#HelpTextBox,#PB_Gadget_BackColor,RGB(255,255,220))


    AddKeyboardShortcut(#Window_0,#PB_Shortcut_Return,10013)
    AddKeyboardShortcut(#Window_0,#PB_Shortcut_Escape,10027)

    SetActiveGadget(1) : SendMessage_(GadgetID(GetActiveGadget()), #EM_SETSEL, 0, -1)

Repeat
    WW = WaitWindowEvent()   ;<--- WW = WaitWindowEvent()

    Select EventWindow()
    Case #Window_0 ;~~~~~ BlackBox
         Select WW
         Case #PB_Event_CloseWindow : End 
         Case #PB_Event_Gadget
              EG = EventGadget()  ;<--- EG = EventGadget()
              Select EventGadget()
              Case 1    ; Number of Cylinders
                   Select EventType()
                   Case #PB_EventType_Focus : Flag = GetGadgetState(GetActiveGadget()) : Help(EG)
                   Case #PB_EventType_Change : SetGadgetText(#CalcTextBox,"")
                        If GetGadgetState(GetActiveGadget()) <> -1 : Flag = GetGadgetState(GetActiveGadget()) : SetGadgetState(EventGadget(),Flag) : EndIf
                        If GetGadgetState(GetActiveGadget()) = -1 : SetGadgetState(EventGadget(),Flag) : ComboMAX() : EndIf
                   EndSelect
              Case 2    ; Bore
                   Select EventType()
                   Case #PB_EventType_Focus : Help(EG) : Bore = ValD(GetGadgetText(EG)) : SendMessage_(GadgetID(EventGadget()),#EM_SETSEL,0,-1) 
                   Case #PB_EventType_Change : SetGadgetText(#CalcTextBox,"")
                        If ValD(GetGadgetText(EG)) > 7 : InputMAX() : SetGadgetText(EG,"") : SetActiveGadget(EG) : EndIf
                   Case #PB_EventType_LostFocus : Bore = ValD(GetGadgetText(EG)) 
                        If Bore >= 1 And Bore <= 7 : SetGadgetText(EG,StrD(Bore,5)) : Else : SetGadgetText(EG,"") : EndIf
                   EndSelect
              Case 3    ; Stroke
                   Select EventType()
                   Case #PB_EventType_Focus : Help(EG) : Stroke = ValD(GetGadgetText(EG)) : SendMessage_(GadgetID(EventGadget()),#EM_SETSEL,0,-1)
                   Case #PB_EventType_Change : SetGadgetText(#CalcTextBox,"")
                        If ValD(GetGadgetText(EG)) > 7 : InputMAX() : SetGadgetText(EG,"") : SetActiveGadget(EG) : EndIf
                   Case #PB_EventType_LostFocus : Stroke = ValD(GetGadgetText(EG))
                        If Stroke >= 1 And Stroke <= 7 : SetGadgetText(EG,StrD(Stroke,5)) : Else : SetGadgetText(EG,""): EndIf
                   EndSelect
              Case #CalculateButton ;  Calculate Button 
                   Calc_CID()
                   Select EventType()
                   EndSelect
              EndSelect
         Case #PB_Event_Menu
              Select EventMenu()
              Case 0    ; Exit and Quit Program
                   End  ; End Program
                   ;=====< Enter/Return and Escape Keys to move thru Input routines >=====
              Case 10013     ;~~~~~ #PB_Shortcut_Return ( 13 is now 10013 )
                   Select GetActiveGadget()
                   Case #CalculateButton : RemoveKeyboardShortcut(#Window_0,#PB_Shortcut_Return)
                                           Calc_CID()
                                           AddKeyboardShortcut(#Window_0, #PB_Shortcut_Return, 10013)
                   Case 1 To 2 : SetActiveGadget(GetActiveGadget() + 1)
                   Case 3 : SetActiveGadget(#CalculateButton)
                   EndSelect
              Case 10027     ;~~~~~ #PB_Shortcut_Escape ( 27 is now 10027 )
                   Select GetActiveGadget()
                   Case 1 : SetActiveGadget(3)
                   Case 2 To 3 : SetActiveGadget(GetActiveGadget() - 1)
                   EndSelect
              EndSelect
         EndSelect
    EndSelect
Until WW = #PB_Event_CloseWindow


;----------< Bottom >--------------------------


Re: PureBasic Gadget Numbering System

Posted: Tue Oct 11, 2016 8:20 am
by Kukulkan
I strongly recommend to use #PB_Any in all environments and cases :!:

I use #PB_Any all the time as using fixed numbers is a horrible mess if you have several functionalities to be re-used across bigger projects (eg proxy settings dialogue, display generic information). It becomes even more complicated if you try to encapsulate parts in modules. You'll have conflicts all the time if you use fixed numbers. IMHO, definitely no good idea. It is okay for some quick testing or small programs, but better to not use this in bigger projects.

I would even say to ask Fred for a PB version that does not allow to define these numbers in general (all of them, not only gadgets). Just assume #PB_Any for all functions and drop that baleful parameter. :mrgreen:

Re: PureBasic Gadget Numbering System

Posted: Tue Oct 11, 2016 9:01 am
by Marc56us
On rare occasions you may need numbers known in advance. For example, for the creation and reuse dynamic multiples image.
(I use static numbers of objects in my program (launcher), only for icons zones (300) and #PB_Any for the rest of objects)
As the number of each item does not vary from one launch to another, it is also much easier to create dynamic names to save and load data in the INI file

Without this, I must maintain a hash table or array to make the connection between the dynamic ID (#PB_Any) and static numbers (# in array) of # of zone.
Feasible, but much longer.

So it is good to have both systems and know the advantages and disadvantages of each.

:wink:

Re: PureBasic Gadget Numbering System

Posted: Tue Oct 11, 2016 7:26 pm
by VB6_to_PBx
Kukulkan wrote:I strongly recommend to use #PB_Any in all environments and cases :!:

I use #PB_Any all the time as using fixed numbers is a horrible mess if you have several functionalities to be re-used across bigger projects (eg proxy settings dialogue, display generic information). It becomes even more complicated if you try to encapsulate parts in modules. You'll have conflicts all the time if you use fixed numbers. IMHO, definitely no good idea. It is okay for some quick testing or small programs, but better to not use this in bigger projects.

I would even say to ask Fred for a PB version that does not allow to define these numbers in general (all of them, not only gadgets). Just assume #PB_Any for all functions and drop that baleful parameter. :mrgreen:
the Code is just "bare-bones" snippet example of my commerical software i'm working on that has 50+ Inputs , 19 Windows , bunch of Modules
the reason i went this route, was i had #PB_Any conflicts crop up early on in my programming style

i'm open to suggestions ... How would you use #PB_Any in the short Code snippet above ??? could you show me example how you would do it using #PB_Any

remember that i must keep one hand on the Number Pad , and cannot use TAB Keys to travel thru 50+ Inputs
and not use Mouse to select the next Input Box , the commercial software is "manual entry on the fly with a machine running "
Mouse and other Keyboard Keys are used at mainly at beginning or end of tests , to enter Test data
but while machine is actually running Test , "its Number Pad manual entry on the fly ".



this is important Code to be able to travel thru Inputs with ENTER or RETURN Keys
how would you use #PB_Any to replace my Code for same effects ??

Case 1 To 2 : SetActiveGadget(GetActiveGadget() + 1)

Case 2 To 3 : SetActiveGadget(GetActiveGadget() - 1)


Code: Select all

              Case 10013     ;~~~~~ #PB_Shortcut_Return ( 13 is now 10013 )
                   Select GetActiveGadget()
                   Case #CalculateButton : RemoveKeyboardShortcut(#Window_0,#PB_Shortcut_Return)
                                           Calc_CID()
                                           AddKeyboardShortcut(#Window_0, #PB_Shortcut_Return, 10013)
                   Case 1 To 2 : SetActiveGadget(GetActiveGadget() + 1)
                   Case 3 : SetActiveGadget(#CalculateButton)
                   EndSelect
              Case 10027     ;~~~~~ #PB_Shortcut_Escape ( 27 is now 10027 )
                   Select GetActiveGadget()
                   Case 1 : SetActiveGadget(3)
                   Case 2 To 3 : SetActiveGadget(GetActiveGadget() - 1)
                   EndSelect

and then use #PB_Any to show HELP text for each Input value i travel thru ???
like in this Code =>

Case #PB_EventType_Focus : Help(EG) : Stroke = ValD(GetGadgetText(EG)) : SendMessage_(GadgetID(EventGadget()),#EM_SETSEL,0,-1)


Code: Select all

              Case 2    ; Bore
                   Select EventType()
                   Case #PB_EventType_Focus : Help(EG) : Bore = ValD(GetGadgetText(EG)) : SendMessage_(GadgetID(EventGadget()),#EM_SETSEL,0,-1) 
                   Case #PB_EventType_Change : SetGadgetText(#CalcTextBox,"")
                        If ValD(GetGadgetText(EG)) > 7 : InputMAX() : SetGadgetText(EG,"") : SetActiveGadget(EG) : EndIf
                   Case #PB_EventType_LostFocus : Bore = ValD(GetGadgetText(EG)) 
                        If Bore >= 1 And Bore <= 7 : SetGadgetText(EG,StrD(Bore,5)) : Else : SetGadgetText(EG,"") : EndIf
                   EndSelect

Re: PureBasic Gadget Numbering System

Posted: Tue Oct 11, 2016 7:53 pm
by walbus
kukulkan write :

It's strongly recommended to use #PB_Any in all environments and cases :!:

Yep, this is more as a good idea :wink:

Re: PureBasic Gadget Numbering System

Posted: Tue Oct 11, 2016 8:11 pm
by VB6_to_PBx
i forgot to mention about this Code :

i need to "cycle" between all 50+ Input values to determine if Input "minimum" values are within the Valid Range

how could i accomplish same resuts with #PB_Any ??

Protected Cnt.i
For Cnt = 1 To 3
If ValD(GetGadgetText(Cnt)) < 1

SetGadgetText(Cnt,"")
MessageRequester(Title$, Text$, #PB_MessageRequester_Ok)
SetActiveGadget(Cnt)
ProcedureReturn
EndIf
Next Cnt

Code: Select all

Declare Calc_CID()
Procedure Calc_CID()
    Protected Title$ = "  ERROR  :  Input  Value  is  less  than  Valid  Range   "
    Protected Text$ = "  Input is less than the minimum allowed value "  + #CRLF$ + #CRLF$ + "  Please enter a Value within the Valid Range " + #CRLF$

    Protected Cnt.i
    For Cnt = 1 To 3
         If ValD(GetGadgetText(Cnt)) < 1
              SetGadgetText(Cnt,"")
              MessageRequester(Title$, Text$, #PB_MessageRequester_Ok)             
              SetActiveGadget(Cnt)
              ProcedureReturn
         EndIf
    Next Cnt

    Select GetGadgetState(1)
    Case 0 : Cylinders = 1
    Case 1 : Cylinders = 2
    Case 2 : Cylinders = 3
    Case 3 : Cylinders = 4
    Case 4 : Cylinders = 5
    Case 5 : Cylinders = 6
    Case 6 : Cylinders = 8
    Case 7 : Cylinders = 10
    Case 8 : Cylinders = 12
    Case 9 : Cylinders = 16
    EndSelect

    CID = Bore * Bore * Stroke * Cylinders * #PI/4  ;<--- 0.78539816339744828
    SetGadgetText(#CalcTextBox,"CID = " + StrD(CID,5))
    SetActiveGadget(1)
EndProcedure


Re: PureBasic Gadget Numbering System

Posted: Wed Oct 12, 2016 7:17 am
by Kukulkan
Here is an example of a tool of myself without fixed numbers including XML dialogue:
http://www.purebasic.fr/english/viewtop ... 27&t=62908

I you generate gadgets on runtime, simply store the ID's in LinkedLists. This allows you to cycle through the gadgets or values as you like. You can also use that to save preferences etc. It is definitely possible to solve using #PB_Any without much more code.

Anyway, you can do like you prefer. I believe PB will keep that option forever. But in my experience, the fixed numbers are always making trouble. If not today, it will be tomorrow...

Re: PureBasic Gadget Numbering System

Posted: Wed Oct 12, 2016 9:17 pm
by VB6_to_PBx
Kukulkan wrote:Here is an example of a tool of myself without fixed numbers including XML dialogue:
http://www.purebasic.fr/english/viewtop ... 27&t=62908

I you generate gadgets on runtime, simply store the ID's in LinkedLists. This allows you to cycle through the gadgets or values as you like. You can also use that to save preferences etc. It is definitely possible to solve using #PB_Any without much more code.

Anyway, you can do like you prefer. I believe PB will keep that option forever. But in my experience, the fixed numbers are always making trouble. If not today, it will be tomorrow...
Kukulkan ,

thanks for the Link to your Code example
will tryout your method !

Re: PureBasic Gadget Numbering System

Posted: Wed Oct 12, 2016 10:01 pm
by Andre
In my project I'm using also a mix of both without problems:
1) fixed numbers for all gadgets in windows (+ their windows), which are unique (main window, preference window)
2) #PB_Any generated gadget numbers for all gadgets / windows, which can have multiple instances (e.g. information windows of the same layout, but with different content, in my case for example up-to 200 windows with country informations...). A linked list save all the needed stuff (WindowID, GadgetID, ID of displayed country to avoid multiple instances of exactly the same window, etc.)

Just my 2 cents. :mrgreen:

Re: PureBasic Gadget Numbering System

Posted: Thu Oct 13, 2016 7:21 am
by Kukulkan
Hi Andre,

I did it the same way. But later I wanted to re-use dialogues in several programs. Like my proxy-selection dialogue include, a progress-bar module, my pie-chart module, a password-dialogue include, popup-notifier, some specific displays for our commercial software and so on. And if you use static id's in such dialogues, you will get a conflict very soon. I got conflicts for Windows, Menus, File Handles, Images, Fonts and even Thread-ID's. At the end, I was forced to re-write all of them to use #PB_any. Since then, I can use and re-use code at any project without any problems and conflicts. I realized that only #PB_Any is reliable in all cases. I use fixed ID's only for testing, small code snippets or very small projects.

I think that even the examples in the PB documentation should be switched to use #PB_Any. So beginners do not start with fixed ID's and do not need to refactor all their code later. But I know that this is a huge job and, most likely, will never be done.

Best,

Kukulkan

Re: PureBasic Gadget Numbering System

Posted: Thu Oct 13, 2016 8:59 am
by ts-soft
I use fixed ID with named-enumeration without conflicts. All object beginning with zero, without waste memory, like the first example.

Re: PureBasic Gadget Numbering System

Posted: Thu Oct 13, 2016 10:03 am
by Kukulkan
ts-soft wrote:I use fixed ID with named-enumeration without conflicts. All object beginning with zero, without waste memory, like the first example.
So you run a global enumeration in every new program and copy all the (named)constants from an include/module into this enumeration? Is this even working with modules? Sounds like a huge effort...

Re: PureBasic Gadget Numbering System

Posted: Thu Oct 13, 2016 12:04 pm
by ts-soft
Kukulkan wrote:So you run a global enumeration in every new program and copy all the (named)constants from an include/module into this enumeration? Is this even working with modules? Sounds like a huge effort...
No problem, my first module is:

Code: Select all

DeclareModule CommonConstants
  ; Form
  Enumeration FormWindow
  EndEnumeration
  Enumeration FormGadget
  EndEnumeration
  Enumeration FormMenu
  EndEnumeration
  Enumeration FormImage
  EndEnumeration
  Enumeration FormFont
  EndEnumeration
  ; Event
  Enumeration EventCustom #PB_Event_FirstCustomValue
  EndEnumeration
  Enumeration EventTypeCustom #PB_EventType_FirstCustomValue
  EndEnumeration
EndDeclareModule

Module CommonConstants
EndModule

UseModule CommonConstants
I have only use "UseModule CommonConstants" in other modules, that using id's-

Re: PureBasic Gadget Numbering System

Posted: Thu Oct 13, 2016 1:30 pm
by Kukulkan
Ok, now I understand. So you are using CommonConstants::#ConstantName all the time? Like this:

Code: Select all

OpenWindow(CommonConstants::#Window1, 1, 1, 100, 100, "Foo")
But if you try to re-use a module in another program, how do you know what enumerations you have to add to your CommonConstants module? If you use #PB_Any, you simply do not care and you do not need to know what constants the module/function might need (which might be a lot of different types).

I'm not convinced that this is more easy than using #PB_Any by default... :?

But hey, everybody is allowed to handle it this way or that way 8)

Re: PureBasic Gadget Numbering System

Posted: Thu Oct 13, 2016 1:49 pm
by ts-soft
Kukulkan wrote:Ok, now I understand. So you are using CommonConstants::#ConstantName all the time? Like this:

Code: Select all

OpenWindow(CommonConstants::#Window1, 1, 1, 100, 100, "Foo")
More like this :)

Code: Select all

DeclareModule CommonConstants
  ; Form
  Enumeration FormWindow
  EndEnumeration
  Enumeration FormGadget
  EndEnumeration
  Enumeration FormMenu
  EndEnumeration
  Enumeration FormImage
  EndEnumeration
  Enumeration FormFont
  EndEnumeration
  ; Event
  Enumeration EventCustom #PB_Event_FirstCustomValue
  EndEnumeration
  Enumeration EventTypeCustom #PB_EventType_FirstCustomValue
  EndEnumeration
EndDeclareModule

Module CommonConstants
EndModule

UseModule CommonConstants

DeclareModule bla
  UseModule CommonConstants
  
  Enumeration FormWindow
    #frmbla1
  EndEnumeration
  
  Declare bla()
EndDeclareModule

Module bla
  Procedure bla()
    Debug #frmbla1
  EndProcedure 
EndModule

Enumeration FormWindow
  #frmMain
EndEnumeration

bla::bla()
Debug #frmMain