Page 1 of 1

Get variable from GUI

Posted: Tue Oct 29, 2024 2:43 pm
by simkot
There is a test program

Code: Select all

Enumeration
  #WIN_MAIN
  #BUTTON_INTERACT
  #BUTTON_CLOSE
  #STRING_INPUT
EndEnumeration

Global Quit.b = #False
#FLAGS = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
If OpenWindow(#WIN_MAIN, 0, 0, 300, 200, "Test", #FLAGS)
  ButtonGadget(#BUTTON_INTERACT, 20, 150, 100, 30, "Btn 1")
  ButtonGadget(#BUTTON_CLOSE, 170, 150, 100, 30, "Btn 2")
  StringGadget(#STRING_INPUT, 10, 30, 280, 30, "")
  SetActiveGadget(#STRING_INPUT)
  Repeat
    Event.l = WaitWindowEvent() 
    Select Event
      Case #PB_Event_Gadget
        Select EventGadget()
          Case #BUTTON_INTERACT
            A.s =GetGadgetText(#STRING_INPUT)
          Case #BUTTON_CLOSE
            Quit = #True
        EndSelect
    EndSelect
  Until Event = #PB_Event_CloseWindow Or Quit = #True
EndIf
End
It gets the value of variable A.s by pressing the button. But I need GetGadgetText(#STRING_INPUT) to work constantly, in a cycle (for example, with an interval of 500 ms) and variable A.s =GetGadgetText(#STRING_INPUT) to be updated automatically, without waiting for the button to be pressed. How can I do this?

Re: Get variable from GUI

Posted: Tue Oct 29, 2024 2:48 pm
by AZJIO

Code: Select all

Enumeration
	#WIN_MAIN
	#BUTTON_INTERACT
	#BUTTON_CLOSE
	#STRING_INPUT
EndEnumeration

Global Quit.b = #False
#FLAGS = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
If OpenWindow(#WIN_MAIN, 0, 0, 300, 200, "Test", #FLAGS)
	ButtonGadget(#BUTTON_INTERACT, 20, 150, 100, 30, "Btn 1")
	ButtonGadget(#BUTTON_CLOSE, 170, 150, 100, 30, "Btn 2")
	StringGadget(#STRING_INPUT, 10, 30, 280, 30, "")
	SetActiveGadget(#STRING_INPUT)
	Repeat
		Event.l = WaitWindowEvent() 
		Select Event
			Case #PB_Event_Gadget
				Select EventGadget()
					Case #STRING_INPUT
						If EventType()  = #PB_EventType_Change
							A.s =GetGadgetText(#STRING_INPUT)
							Debug A
						EndIf
					Case #BUTTON_INTERACT
						A.s =GetGadgetText(#STRING_INPUT)
					Case #BUTTON_CLOSE
						Quit = #True
				EndSelect
		EndSelect
	Until Event = #PB_Event_CloseWindow Or Quit = #True
EndIf
End
neat code

Code: Select all

Enumeration
	#win_main
	#button_interact
	#button_close
	#string_input
EndEnumeration

Define a.s
If OpenWindow(#win_main, 0, 0, 300, 200, "Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
	ButtonGadget(#button_interact, 20, 150, 120, 30, "Btn 1")
	ButtonGadget(#button_close, 160, 150, 120, 30, "close")
	StringGadget(#string_input, 10, 30, 280, 30, "")
	SetActiveGadget(#string_input)
	Repeat
		Select WaitWindowEvent()
			Case #PB_Event_Gadget
				Select EventGadget()
					Case #string_input
						If EventType() = #PB_EventType_Change
							a = GetGadgetText(#string_input)
							SetGadgetText(#button_interact, a)
						EndIf
					Case #button_interact
						a = GetGadgetText(#string_input)
					Case #button_close
						End
				EndSelect
			Case #PB_Event_CloseWindow
				End
		EndSelect
	ForEver
EndIf
End

Re: Get variable from GUI

Posted: Tue Oct 29, 2024 3:24 pm
by simkot
Thank you very much! And how to make it so that when the window is launched, some task not related to gadgets is performed? For example, so that the work

Code: Select all

 i = i + 1
?

Re: Get variable from GUI

Posted: Tue Oct 29, 2024 3:27 pm
by AZJIO

Code: Select all

AddWindowTimer(#Window , Timer , Timeout)
But that's another question

Code: Select all

CreateThread(@ProcedureName() , *Value)
Like this

Code: Select all

i + 1