enumeration

Just starting out? Need help? Post your questions and find answers here.
ludoke
Enthusiast
Enthusiast
Posts: 153
Joined: Fri Jul 08, 2016 5:35 pm
Location: Essen (Belgium)

enumeration

Post by ludoke »

;enumeration question
;can I do enumeration in procedures or must enumeration always on top of the program ??

Code: Select all

Enumeration  
  #main_win: #font
  #F1     ;functietoets met add
EndEnumeration  
;-------------------------------------------------------
Global win_color.l=RGB(115,122,121)
;-------------------------------------------------------
Declare sneltoets()
;Declare set_knop_kleur(id,text$)
;-------------------------------------------------------
  LoadFont(#font,"caladea",18, #PB_Font_Italic|#PB_Font_Bold) 

If OpenWindow (#main_win,0,0,500,500, "ENURATION TEST" ,flags )
 sneltoets()   ;aanroep van procedure voor installatie sneltoetsen AddKeyboardShortcut(#main_win,  #PB_Shortcut_F1,#F1)

 Repeat
    Ev = WaitWindowEvent()
    Select ev   ;
        Case   #PB_Event_Menu , #PB_Event_Gadget        ;dit werkt verschillende case scheiden met komma                
         
        Select EventGadget() | EventMenu() 
               
          Case #F1     ;main
               Debug "F1 pressed"       
        EndSelect
EndSelect
    Until ev=#PB_Event_CloseWindow
  
EndIf

End   
      ;--------------------------------------------------------
Procedure test1()   ;<- is this possible enumerate in a procedure ?
  Enumeration
    #var1 
    #var2
  EndEnumeration  
  ; other code
  ;
  ;
EndProcedure  
;--------------------------------------------------------------
Procedure test2()
  Enumeration
    #var1  ;  <- is this also possible ,using the same Enumeration ,its locale in the procedure or not ?
    #var3
    #var4
  EndEnumeration  
  ; other code
  ;
  ; 
EndProcedure  
;--------------------------------------------------------------
Procedure sneltoets()
  AddKeyboardShortcut(#main_win,  #PB_Shortcut_F1,#F1)
  
EndProcedure 
User avatar
Demivec
Addict
Addict
Posts: 4091
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: enumeration

Post by Demivec »

You can do enumeration in both the main scope an in procedures.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: enumeration

Post by ts-soft »

Yes, you can do it in both, but it makes no realy sense to do it in a procedure, a constant is always for mainscope.
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Little John
Addict
Addict
Posts: 4527
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: enumeration

Post by Little John »

Code: Select all

Procedure test2()
  Enumeration
    #var1  ;  <- is this also possible, using the same Enumeration, its locale in the procedure or not ?
    #var2
    #var3
  EndEnumeration 
  ; other code
  ;
  ;
EndProcedure  

Debug #var2     ; shows 1
As you see from this small demo code, it is possible to use Enumeration this way.
However, like any other named constants in PB, these constants are not local in the procedure.
So writing Enumerations inside a procedure will give a wrong impression of the scope of the regarding constants.
ludoke
Enthusiast
Enthusiast
Posts: 153
Joined: Fri Jul 08, 2016 5:35 pm
Location: Essen (Belgium)

Re: enumeration

Post by ludoke »

thanks,
enumeration is global ,
I did not know that.
So important to a good description of the enumerations at the top of the code to keep track off them.
Post Reply