PureBasic Forum
https://www.purebasic.fr/english/

[Done] bug,SetGadgetText(#ComboBox_1,s.s)
https://www.purebasic.fr/english/viewtopic.php?f=4&t=69019
Page 1 of 3

Author:  gurj [ Tue Aug 22, 2017 5:17 am ]
Post subject:  [Done] bug,SetGadgetText(#ComboBox_1,s.s)

bug,SetGadgetText(#ComboBox_1,s.s)

first click ButtonG_"+>" 5 times, all ok

then let Gadget1 state To 1(any>-1)
click ButtonG_"+>" 1 times, ok
again click ButtonG_"+>",No
pb5.6 winxp x86 has this bug.
but old pb4.61 no bug.

Code:
OpenWindow(0, 0, 0, 440, 160, "", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
LoadFont(0,"System", 12, #PB_Font_Bold):SetGadgetFont(#PB_Default, FontID(0))
ComboBoxGadget(1, 165, 110, 195, 25, #PB_ComboBox_Editable)

ComboBoxGadget(5, 5, 110, 80, 25)
AddGadgetItem(5,-1,"1ms")
AddGadgetItem(5,-1,"1sec")
AddGadgetItem(5,-1,"1min")
AddGadgetItem(5,-1,"1hour")
AddGadgetItem(5,-1,"1day")
AddGadgetItem(5,-1,"1mon")
AddGadgetItem(5,-1,"1year")
AddGadgetItem(5,-1,"4year")
AddGadgetItem(5,-1,"100year")
AddGadgetItem(5,-1,"400year")
Dim t.q(9):t(0)=1
t(1)=1000
t(2)=60000
t(3)=3600000
t(4)=86400000
t(5)=2592000000
t(6)=31536000000
t(7)=126230400000
t(8)=3155673600000
t(9)=12622780800000

ButtonGadget(7, 85, 110, 40, 23, "+>")
ButtonGadget(8, 125, 110, 40, 23, "->")
AddGadgetItem(1,-1,"-9223")
AddGadgetItem(1,-1,"9223")

Repeat:ev=WaitWindowEvent():Select ev
  Case #PB_Event_Gadget:eg=EventGadget()
   Select eg
     Case 5:g5t.a=GetGadgetState(5)
     Case 7:g1s.s=Str(Val(GetGadgetText(1))+t(g5t)):SetGadgetText(1,g1s)
     Case 8:SetGadgetText(1,Str(Val(GetGadgetText(1))-t(g5t)))
   EndSelect
   
  Case #PB_Event_CloseWindow:Break
EndSelect:ForEver
End

Author:  gurj [ Tue Aug 22, 2017 5:41 am ]
Post subject:  Re: bug,SetGadgetText(#ComboBox_1,s.s)

bug on:
If Gadget1 state >-1
GetGadgetText(1) == GetGadgetItemText(1,Gadget1 state)

Author:  gurj [ Tue Aug 22, 2017 7:06 am ]
Post subject:  Re: bug,SetGadgetText(#ComboBox_1,s.s)

I guessing involve and this:
[5.42] Replace by using old replace phrase fails...
viewtopic.php?f=4&t=65153

Author:  gurj [ Tue Aug 22, 2017 8:13 am ]
Post subject:  Re: bug,SetGadgetText(#ComboBox_1,s.s)

tiny code to try:
Code:
OpenWindow(0,0,0,300,100,"",#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_ScreenCentered)
LoadFont(0,"system", 12):SetGadgetFont(#PB_Default, FontID(0))
ComboBoxGadget(0, 5, 5, 80, 25, #PB_ComboBox_Editable)
AddGadgetItem(0,-1,"100")
AddGadgetItem(0,-1,"200")

ButtonGadget(1, 85, 0,200, 25, "Button 0")

Repeat:ev=WaitWindowEvent():Select ev
  Case #PB_Event_Gadget:eg=EventGadget()
   Select eg
    Case 1:SetGadgetText(0,Str(1+Val(GetGadgetText(0))))
   EndSelect
   
  Case #PB_Event_CloseWindow:Break
EndSelect:ForEver
End

Author:  DK_PETER [ Tue Aug 22, 2017 9:04 am ]
Post subject:  Re: bug,SetGadgetText(#ComboBox_1,s.s)

Is this what you're after?

Code:
OpenWindow(0,0,0,300,100,"",#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_ScreenCentered)
LoadFont(0,"system", 12):SetGadgetFont(#PB_Default, FontID(0))
ComboBoxGadget(0, 5, 5, 80, 25, #PB_ComboBox_Editable)
AddGadgetItem(0,-1,"100")
AddGadgetItem(0,-1,"200")

ButtonGadget(1, 85, 0,200, 25, "Button 0")

Repeat
  ev=WaitWindowEvent()
  Select ev
    Case #PB_Event_Gadget:eg=EventGadget()
      Select eg
        Case 1
          nextvalue.i = Val(GetGadgetText(0)) + 1
          SetGadgetItemText(0,GetGadgetState(0), Str(nextvalue))
      EndSelect
    Case #PB_Event_CloseWindow
      Break
  EndSelect
ForEver
End

Author:  gurj [ Tue Aug 22, 2017 9:24 am ]
Post subject:  Re: bug,SetGadgetText(#ComboBox_1,s.s)

thanks.
not allow change Gadget_0 Item

Author:  DK_PETER [ Tue Aug 22, 2017 9:38 am ]
Post subject:  Re: bug,SetGadgetText(#ComboBox_1,s.s)

gurj wrote:
thanks.
not allow change Gadget_0 Item


True..The value has to be added to the combo before any addition can be made..

In the example below, I've used a keyboard shortcut to capture the return key.
It added the typed value and selects it for further handling.

Code:
OpenWindow(0,0,0,300,100,"",#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_ScreenCentered)
CreatePopupMenu(0)
MenuItem(2, "DummyItem")
LoadFont(0,"system", 12):SetGadgetFont(#PB_Default, FontID(0))
ComboBoxGadget(0, 5, 5, 80, 25, #PB_ComboBox_Editable)
AddKeyboardShortcut(0,#PB_Shortcut_Return, 2)
AddGadgetItem(0,-1,"100")
AddGadgetItem(0,-1,"200")

ButtonGadget(1, 85, 0,200, 25, "Button 0")

Repeat
  ev=WaitWindowEvent()
  Select ev
    Case #PB_Event_Gadget
      eg=EventGadget()
      Select eg
        Case 1
          nextvalue.i = Val(GetGadgetText(0)) + 1
          SetGadgetItemText(0,GetGadgetState(0), Str(nextvalue))   
      EndSelect
        Case #PB_Event_Menu
          AddGadgetItem(0, -1, GetGadgetText(0))
          SetGadgetState(0, CountGadgetItems(0)-1)
    Case #PB_Event_CloseWindow
      Break
  EndSelect
ForEver
End

Author:  gurj [ Tue Aug 22, 2017 9:56 am ]
Post subject:  Re: bug,SetGadgetText(#ComboBox_1,s.s)

because this bug,I now use:
Code:
OpenWindow(0,0,0,300,100,"",#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_ScreenCentered)
LoadFont(0,"system", 12):SetGadgetFont(#PB_Default, FontID(0))
StringGadget(3, 5, 5, 80, 25,"")
ComboBoxGadget(0, 5, 30, 80, 25)
AddGadgetItem(0,-1,"100")
AddGadgetItem(0,-1,"200")

ButtonGadget(1, 85, 0,200, 25, "<+1")

Repeat
  ev=WaitWindowEvent()
  Select ev
    Case #PB_Event_Gadget:eg=EventGadget()
     Select eg
       Case 0:If EventType()=#PB_EventType_Change
      SetGadgetText(3,GetGadgetText(0)):EndIf
        Case 1
          SetGadgetText(3,Str(Val(GetGadgetText(3)) + 1))
      EndSelect
    Case #PB_Event_CloseWindow
      Break
  EndSelect
ForEver
End


Author:  DK_PETER [ Tue Aug 22, 2017 10:17 am ]
Post subject:  Re: bug,SetGadgetText(#ComboBox_1,s.s)

@gurj

It's not a bug. The gadget state is -1 at first, which is as expected.

The example uses:

Code:
SetGadgetItemText(0, GetGadgetState(0), Str(nextvalue))


edit: rephasing
to place the incremented value back in it's place.

Author:  gurj [ Tue Aug 22, 2017 11:06 am ]
Post subject:  Re: bug,SetGadgetText(#ComboBox_1,s.s)

no,no, ComboBoxGadget's Editable has bug,so i use StringGadget here.

now pb bug is :
If Gadget_0 state >-1 [by select Box list only]
then if user Edit ComboBoxGadget's Editable,Gadget_0 state = -1
but if by command Edit ComboBoxGadget's Editable,Gadget_0 state remain >-1 ,this is wrong!!!

Author:  gurj [ Tue Aug 22, 2017 11:38 am ]
Post subject:  Re: bug,SetGadgetText(#ComboBox_1,s.s)

ComboBoxGadget's Editable is Gadget's state = -1 when Edited.
and irrelevant ComboBoxGadget's state,should can G[S]etGadgetText(#ComboBox_1) for ComboBoxGadget's Editable
------
other, i also hope use G[S]etGadgetItemText(#ComboBox_1,-1) for ComboBoxGadget's Editable
this can =
G[S]etGadgetText(#ComboBox_1)
sorry my bad english.

Author:  DK_PETER [ Tue Aug 22, 2017 12:38 pm ]
Post subject:  Re: bug,SetGadgetText(#ComboBox_1,s.s)

No bug. :wink:

Change this to your fit your needs:

Code:
Global ComboIndex.i = -1
OpenWindow(0,0,0,300,100,"",#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_ScreenCentered)
LoadFont(0,"system", 12):SetGadgetFont(#PB_Default, FontID(0))
ComboBoxGadget(0, 5, 5, 80, 25, #PB_ComboBox_Editable)
AddGadgetItem(0,-1,"100")
AddGadgetItem(0,-1,"200")

ButtonGadget(1, 85, 0,200, 25, "Button 0")

Repeat
  ev=WaitWindowEvent()
  Select ev
    Case #PB_Event_Gadget
      eg=EventGadget()
      Select eg
        Case 1
          If GetGadgetState(0) = -1 And GetGadgetText(0) <> ""
            nextvalue = Val(GetGadgetText(0))+1
            AddGadgetItem(0, -1, Str(nextvalue))
            SetGadgetItemText(0,GetGadgetState(0), Str(nextvalue))   
            ComboIndex = CountGadgetItems(0)-1
            SetGadgetState(0, ComboIndex)
          Else
            nextvalue.i = Val(GetGadgetText(0)) + 1
            ComboIndex = GetGadgetState(0)
            SetGadgetItemText(0, ComboIndex, Str(nextvalue))   
          EndIf
      EndSelect

    Case #PB_Event_CloseWindow
      Break
  EndSelect
ForEver
End

Author:  Dude [ Tue Aug 22, 2017 12:47 pm ]
Post subject:  Re: bug,SetGadgetText(#ComboBox_1,s.s)

Not a bug. Just a problem with the logic of the code. Here's proof that it works:

Code:
OpenWindow(0,300,300,300,100,"",#PB_Window_SystemMenu)

ComboBoxGadget(0, 5, 5, 80, 25, #PB_ComboBox_Editable)

ButtonGadget(1, 85, 0,200, 25, "Click to increase value +1")

Repeat
  ev=WaitWindowEvent()
  If ev=#PB_Event_Gadget And EventGadget()=1
    SetGadgetText(0,Str(Val(GetGadgetText(0))+1))
  EndIf
Until ev=#PB_Event_CloseWindow

Author:  gurj [ Tue Aug 22, 2017 1:10 pm ]
Post subject:  Re: bug,SetGadgetText(#ComboBox_1,s.s)

is bug!
first let ComboBoxGadget_0 state>-1 [by select Box list only]
then SetGadgetText(0,s.s)
then you can't ture GetGadgetText(0), so:
Editable nonprofit, Editable invalid, Editable not worth

Author:  gurj [ Wed Aug 23, 2017 5:58 am ]
Post subject:  Re: bug,SetGadgetText(#ComboBox_1,s.s)

because this bug,I now use:
updated:
Code:
    OpenWindow(0,0,0,300,100,"",#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_ScreenCentered)
    LoadFont(0,"system", 12):SetGadgetFont(#PB_Default, FontID(0))
    StringGadget(3, 5, 5, 80, 25,"")
    ComboBoxGadget(0, 5, 30, 80, 25)
    AddGadgetItem(0,-1,"100")
    AddGadgetItem(0,-1,"200")

    ButtonGadget(1, 85, 0,200, 25, "<+1")

    Repeat
      ev=WaitWindowEvent()
      Select ev
        Case #PB_Event_Gadget:eg=EventGadget()
         Select eg
           Case 0;:If EventType()=#PB_EventType_Change
          SetGadgetText(3,GetGadgetText(0));:EndIf
            Case 1
              SetGadgetText(3,Str(Val(GetGadgetText(3)) + 1))
          EndSelect
        Case #PB_Event_CloseWindow
          Break
      EndSelect
    ForEver
    End


Page 1 of 3 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/