PureBasic Visual Designer If .. ElseIf Select .. Case

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
naw
Enthusiast
Enthusiast
Posts: 573
Joined: Fri Apr 25, 2003 4:57 pm

PureBasic Visual Designer If .. ElseIf Select .. Case

Post by naw »

Simple request, I like Visual Designer. Auto-generating the Event loop is great, but could it please be amended to use the much *neater*:

(Obviously, this is just a *personal preference* thing but I think this is nicer)

Code: Select all

Repeat
EVENT=WaitWindowEvent()
Select EVENT
   Case #PB_EventGadget
;- PB Gadget Events
            Select EventGadgetId()
                      Case #BTN_1:  Debug(str(#BTN_1)
                      Case #BTN_2:  Debug (str(#BTN_2)
            EndSelect

   Case #PB_EventMenu
;- PB Menu Events
            Select EventMenuId()
                       Case #MENU_1:
                       Case #MENU_1:
            EndSelect
EndSelect

---------------------------------------------------------------------


Instead of the explosion of If ElseIf's (which I find difficult to read):

Code: Select all

Repeat
  
  Event = WaitWindowEvent()
  
  Case
  Select
  
  
  If Event = #PB_EventMenu
    
    ;Debug "WindowID: " + Str(EventWindowID())
    
    MenuID = EventMenuID()
    
    If MenuID = #MENU_1
      Debug "GadgetID: #MENU_1"
      
    ElseIf MenuID = #MENU_5
      Debug "GadgetID: #MENU_5"
Ta - N
PB&J Lover
Enthusiast
Enthusiast
Posts: 212
Joined: Fri Apr 22, 2005 2:07 pm
Location: U.S.A.
Contact:

Select case

Post by PB&J Lover »

No, I agree, it is easier to follow a select case event menu than ELSEIFs.

This is not personal preference.
-- DB

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius — and a lot of courage — to move in the opposite direction.

Albert Einstein
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

More readable, true. However isn't If .. ElseIf .. Else .. EndIf faster than Select .. Case .. EndSelect?
@}--`--,-- A rose by any other name ..
PB&J Lover
Enthusiast
Enthusiast
Posts: 212
Joined: Fri Apr 22, 2005 2:07 pm
Location: U.S.A.
Contact:

faster

Post by PB&J Lover »

In what way is it faster?
-- DB

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius — and a lot of courage — to move in the opposite direction.

Albert Einstein
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1282
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Post by Paul »

PureVision produces much cleaner code and uses Select/Case for Event Loop
(which in our tests run much faster than If/ElseIf when compiled)

You can always give it a try :)
Image Image
naw
Enthusiast
Enthusiast
Posts: 573
Joined: Fri Apr 25, 2003 4:57 pm

Post by naw »

I dunno if If Else is faster or not. I think that this is only the main Event Loop so its not so important as say a sort routine or a search routine etc.

It would also be nice if VisualDesigner produced the Procedures using the Constants Names given to the Gadgets and Menus. But thats not such a big deal...

- just seems like replacing If...ElseIf...EndIf with Select...Case...EndSelect would be a fairly easy change to make and would produce prettier code. At the mo' I have to do a load of Search & Replace and hand-editing which is a bit of a pain.

- Y'know what - I might just give PV a try... ;-)
Ta - N
PB&J Lover
Enthusiast
Enthusiast
Posts: 212
Joined: Fri Apr 22, 2005 2:07 pm
Location: U.S.A.
Contact:

PureVision

Post by PB&J Lover »

I'm still evaluating PV. I've tried it on my Me machine and it kept jumping every time it updated the form as I moved things around.

I've not given up on it, though.

Thanks
-- DB

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius — and a lot of courage — to move in the opposite direction.

Albert Einstein
Berikco
Administrator
Administrator
Posts: 1326
Joined: Wed Apr 23, 2003 7:57 pm
Location: Belgium
Contact:

Post by Berikco »

This event loop is already included in new VD im working on now, you can choose if/endif or select/case/endselect.
naw
Enthusiast
Enthusiast
Posts: 573
Joined: Fri Apr 25, 2003 4:57 pm

Post by naw »

:D

Brilliant - thanks Bericko
Ta - N
PB&J Lover
Enthusiast
Enthusiast
Posts: 212
Joined: Fri Apr 22, 2005 2:07 pm
Location: U.S.A.
Contact:

Visual Designer Event loops

Post by PB&J Lover »

While we're on the topic of event loops in the Visual Designer. There doesn't seem to be a way to declared a window in a project a child (and Identify the parent). This also effects event loops because the VD simply includes the controls from all the windows in the event loop and that forces you to hack the child window sections out of the loop into their own.

Also, there needs to be a way of saving one window to it's own file (to use it again) and for removing it from the project.

Looking forward to the update.
-- DB

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius — and a lot of courage — to move in the opposite direction.

Albert Einstein
Post Reply