Page 1 of 1

PureBasic Visual Designer If .. ElseIf Select .. Case

Posted: Thu May 19, 2005 4:20 pm
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"

Select case

Posted: Thu May 19, 2005 4:31 pm
by PB&J Lover
No, I agree, it is easier to follow a select case event menu than ELSEIFs.

This is not personal preference.

Posted: Thu May 19, 2005 4:42 pm
by Dare2
More readable, true. However isn't If .. ElseIf .. Else .. EndIf faster than Select .. Case .. EndSelect?

faster

Posted: Thu May 19, 2005 4:57 pm
by PB&J Lover
In what way is it faster?

Posted: Thu May 19, 2005 5:36 pm
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 :)

Posted: Thu May 19, 2005 5:52 pm
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... ;-)

PureVision

Posted: Thu May 19, 2005 5:54 pm
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

Posted: Fri May 20, 2005 9:22 am
by Berikco
This event loop is already included in new VD im working on now, you can choose if/endif or select/case/endselect.

Posted: Fri May 20, 2005 10:28 am
by naw
:D

Brilliant - thanks Bericko

Visual Designer Event loops

Posted: Fri May 20, 2005 1:22 pm
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.