Get variable from GUI

Just starting out? Need help? Post your questions and find answers here.
simkot
User
User
Posts: 31
Joined: Sat Oct 26, 2024 8:25 am

Get variable from GUI

Post 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?
AZJIO
Addict
Addict
Posts: 2225
Joined: Sun May 14, 2017 1:48 am

Re: Get variable from GUI

Post 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
Last edited by AZJIO on Tue Oct 29, 2024 3:25 pm, edited 1 time in total.
simkot
User
User
Posts: 31
Joined: Sat Oct 26, 2024 8:25 am

Re: Get variable from GUI

Post 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
?
AZJIO
Addict
Addict
Posts: 2225
Joined: Sun May 14, 2017 1:48 am

Re: Get variable from GUI

Post 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
Post Reply