SpinGadget Word Branching

Share your advanced PureBasic knowledge/code with the community.
User avatar
electrochrisso
Addict
Addict
Posts: 989
Joined: Mon May 14, 2007 2:13 am
Location: Darling River

SpinGadget Word Branching

Post by electrochrisso »

Use the SpinGadget and words to branch off, by using the state of the spin gadget in a Case statement.

Code: Select all

NewList Fruit.s()
AddElement(Fruit()) : Fruit() = "Apple"
AddElement(Fruit()) : Fruit() = "Banana"
AddElement(Fruit()) : Fruit() = "Orange"
AddElement(Fruit()) : Fruit() = "Peach"
AddElement(Fruit()) : Fruit() = "Pear"

If OpenWindow(0, 0, 0, 140, 70, "SpinGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  SpinGadget(0, 20, 20, 100, 20, 1, 5)
  SelectElement(Fruit(), 0)
  SetGadgetState(0, 0) : SetGadgetText(0, Fruit())
  ButtonGadget(1, 20, 45, 100, 20, "Debug")
  Repeat
    Event = WaitWindowEvent()
    If Event = #PB_Event_Gadget
      If EventGadget() = 0
        SelectElement(Fruit(), GetGadgetState(0) -1)
        SetGadgetText(0, Fruit())
      ElseIf EventGadget() = 1
        Select GetGadgetState(0) -1
            Case 0
              Debug "Nice and crunchy"
            Case 1
              Debug "Full of goodness"
            Case 2
              Debug "Nice and juicy"
            Case 3
              Debug "Great with cream"
            Case 4
              Debug "Hmm, not bad"
        EndSelect
      EndIf
    EndIf
  Until Event = #PB_Event_CloseWindow
EndIf
PureBasic! Purely the best 8)
User avatar
VB6_to_PBx
Enthusiast
Enthusiast
Posts: 627
Joined: Mon May 09, 2011 9:36 am

Re: SpinGadget Word Branching

Post by VB6_to_PBx »

electrochrisso,
thank you for great example
 
PureBasic .... making tiny electrons do what you want !

"With every mistake we must surely be learning" - George Harrison
User avatar
electrochrisso
Addict
Addict
Posts: 989
Joined: Mon May 14, 2007 2:13 am
Location: Darling River

Re: SpinGadget Word Branching

Post by electrochrisso »

VB6_to_PBx wrote:electrochrisso,
thank you for great example
Glad you like it. :)
PureBasic! Purely the best 8)
Post Reply