Page 1 of 1

(Solved)Another problem with combobox....

Posted: Sun May 19, 2019 3:36 pm
by LESTROSO
hi to everybody....i trying to integrate some buttons with comboboxgadget and purebasic form designer...but without success....sorry i'm begineer

i have putted 3 buttons in the puebasic form designer...then i have made a second file.. to recall it...ok this work fine...i have added a timer for time to window..ok..but now i need to add a combobox gadget with 3 states.....when i select one i would like to do something by combobox...selection....

I enclose here my file that pilot the pbf...can somebody help me please??

Thanks a lot,

Lestroso :oops:

Code: Select all


XIncludeFile "test.pbf" ; Include the first window definition

   


Global Image_0


 InitSound() ; Initialize Sound system


 CatchSound(0, ?Music)
 
 
 
 
 Procedure combo()
       MyComboBox = ComboBoxGadget(#PB_Any, 10, 10, 100, 25)
      AddGadgetItem(MyComboBox, 0, "One")
      AddGadgetItem(MyComboBox, 1, "Two")
      AddGadgetItem(MyComboBox, 2, "Three")
    EndProcedure
    
   


 Procedure Window_0_Events(event)
  
  Select event
    Case #PB_Event_CloseWindow
      ProcedureReturn #False

    Case #PB_Event_Menu
      Select EventMenu()
      EndSelect

    Case #PB_Event_Gadget
      Select EventGadget()
        Case Button_1
          PlaySound(0, #PB_Sound_MultiChannel,20)
           MessageRequester("Gatto OKKK!", a$, 0)
             ;
        Case Button_2
         MessageRequester("Ok Tasto2", a$, 0)
        Case Button_3
          MessageRequester("ciao a  teeee!!!ahahahha", a$, 0)
          Case MyComboBox                                            <-----------------------this condition don't works
                If EventType() = #PB_EventType_Change
                  Select GetGadgetState(MyComboBox)
                    Case 0 : MessageRequester("Combo", "One")
                    Case 1 : MessageRequester("Combo", "Two")
                    Case 2 : MessageRequester("Combo", "Three")
          EndSelect
         EndIf
     EndSelect
     EndSelect
  ProcedureReturn #True
 
EndProcedure

Procedure Tempo()
  ;Repeat
Delay(1000)
timelcl=Date()
  If update<>timelcl
    update=timelcl
    hr=Hour(timelcl)
    min=Minute(timelcl)
    sec=Second(timelcl)
    hr12=hr%12
      If Not hr12
        hr12=12
      EndIf
      If hr>11
        ampm$=" pm"
          Else
        ampm$=" am"
      EndIf
    display$=Str(hr12)+":"+RSet(Str(min),2,"0")+":"+RSet(Str(sec),2,"0")+ampm$
    SetGadgetText(Text_2,display$)
    
  EndIf
  ;ForEver
  
EndProcedure


  

  OpenWindow_0 () ;Open the window!!!
  AddWindowTimer(Window_0, 1000, 1000)

  combo()
  
Repeat

  
  event= WaitWindowEvent()
    
  If Event = #PB_Event_Timer And EventTimer() = 1000
          tempo()
     
      EndIf    
    
  Until Window_0_Events(Event)= #False
  
  
  DataSection
     Music:
    IncludeBinary "Cat.wav" 
  EndDataSection
      


Re: Another problem with combobox....

Posted: Sun May 19, 2019 4:03 pm
by wombats
Does it work if you take out the Delay() in the tempo() procedure? That is slowing down the event loop.

Re: Another problem with combobox....

Posted: Sun May 19, 2019 4:03 pm
by mk-soft
The MyComboBox variable must be global.

It is better to create the ComboBox immediately with FormDesigner and to fill the ComboBox after creating the window "OpenWindow_0 ()".
I prefer to create the gadgets with FormDesigner not with "PB_Any", but with constants

Code: Select all

;-TOP

EnableExplicit

Enumeration FormWindow
  #Main
EndEnumeration

Enumeration FormGadget
  #Combo_Number
  #Button_Play
EndEnumeration


Procedure OpenMain(x = 0, y = 0, width = 270, height = 60)
  OpenWindow(#Main, x, y, width, height, "Main Window", #PB_Window_SystemMenu)
  ComboBoxGadget(#Combo_Number, 10, 10, 120, 30)
  ButtonGadget(#Button_Play, 150, 10, 80, 30, "Play")
EndProcedure

Procedure FillComboBox(Gadget)
  AddGadgetItem(Gadget, -1, "Zero")
  AddGadgetItem(Gadget, -1, "One")
  AddGadgetItem(Gadget, -1, "Two")
  AddGadgetItem(Gadget, -1, "Three")
  SetGadgetState(Gadget, 0)
EndProcedure

Procedure Main()
  
  OpenMain()
  
  FillComboBox(#Combo_Number)
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        Break
      Case #PB_Event_Menu
        Select EventMenu()
            
        EndSelect
      Case #PB_Event_Gadget
        Select EventGadget()
          Case #Combo_Number
            If EventType() = #PB_EventType_Change
              Select GetGadgetState(#Combo_Number)
                Case 0
                  Debug "Zero"
                Case 1
                  Debug "One"
                Case 2
                  Debug "Two"
                Case 3
                  Debug "Three"
                  
              EndSelect
            EndIf
          Case #Button_Play
            If EventType() = #PB_EventType_LeftClick
              Debug "Button Play"
            EndIf
            
        EndSelect
        
    EndSelect
  ForEver
  
EndProcedure : Main()


Re: Another problem with combobox....

Posted: Sun May 19, 2019 4:26 pm
by TI-994A
LESTROSO wrote: i need to add a combobox gadget with 3 states.....when i select one i would like to do something by combobox...selection....
Based on the original code:

Code: Select all

Global MyComboBox, Button_1, Button_2, Button_3, Text_2

Procedure combo()
  MyComboBox = ComboBoxGadget(#PB_Any, 10, 10, 100, 25)
  AddGadgetItem(MyComboBox, 0, "One")
  AddGadgetItem(MyComboBox, 1, "Two")
  AddGadgetItem(MyComboBox, 2, "Three")
EndProcedure

Procedure Window_0_Events(event)
  a$ = "message..."
  Select event
    Case #PB_Event_CloseWindow
      ProcedureReturn #False
    Case #PB_Event_Menu
      Select EventMenu()
      EndSelect
    Case #PB_Event_Gadget
      Select EventGadget()
        Case Button_1
          ;PlaySound(0, #PB_Sound_MultiChannel,20)
          MessageRequester("Gatto OKKK!", a$, 0)
        Case Button_2
          MessageRequester("Ok Tasto2", a$, 0)
        Case Button_3
          MessageRequester("ciao a  teeee!!!ahahahha", a$, 0)
        Case MyComboBox
          If EventType() = #PB_EventType_Change
            Select GetGadgetState(MyComboBox)
                Case 0 : MessageRequester("Combo", "One")
                Case 1 : MessageRequester("Combo", "Two")
                Case 2 : MessageRequester("Combo", "Three")
            EndSelect
          EndIf
      EndSelect
  EndSelect
  ProcedureReturn #True  
EndProcedure

Procedure Tempo()
  ;Repeat
  ;Delay(1000)
  timelcl=Date()
  If update<>timelcl
    update=timelcl
    hr=Hour(timelcl)
    min=Minute(timelcl)
    sec=Second(timelcl)
    hr12=hr%12
    If Not hr12
      hr12=12
    EndIf
    If hr>11
      ampm$=" pm"
    Else
      ampm$=" am"
    EndIf
    display$=Str(hr12)+":"+RSet(Str(min),2,"0")+":"+RSet(Str(sec),2,"0")+ampm$
    SetGadgetText(Text_2, display$)    
  EndIf
  ;ForEver  
EndProcedure

wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
OpenWindow(0, 0, 0, 450, 300, "ComboBox Events", wFlags)
Button_1 = ButtonGadget(#PB_Any, 120, 10, 100, 30, "Button 1")
Button_2 = ButtonGadget(#PB_Any, 230, 10, 100, 30, "Button 2")
Button_3 = ButtonGadget(#PB_Any, 340, 10, 100, 30, "Button 2")
Text_2 = TextGadget(#PB_Any, 10, 250, 430, 30, "", #PB_Text_Center)
AddWindowTimer(0, 1000, 1000)
combo()

Repeat
  event= WaitWindowEvent()
  If Event = #PB_Event_Timer And EventTimer() = 1000
    tempo()
  EndIf      
Until Window_0_Events(Event) = #False

Re: Another problem with combobox....

Posted: Sun May 19, 2019 4:27 pm
by mk-soft
wombats wrote:Does it work if you take out the Delay() in the tempo() procedure? That is slowing down the event loop.
Yes,
Never use delay within an event loop. Not even if they are connected to BindEvent or BindGadgetEvent.

re: Another problem with combobox....

Posted: Sun May 19, 2019 7:09 pm
by LESTROSO
thanks again to everybody...you have cleared the problem....and solved it...thank again...Lestroso :lol: