Below are both code samples. Both run but only the button code works right. I would sure appreciate it if anybody can point out what I am doing wrong with the stringGadgets. Thanks for looking!
Here is the working code using buttons:
Code: Select all
;postwithbuttons.pb
;Test of an outer and inner event loop
;Click on begin button, then randomly on the other buttons. The textGadgets will report which button was pressed.
;- Window Constants
Enumeration
#Window_mainForm
#beginbutton
#buttonA
#buttonB
#buttonC
#text1
#text2
EndEnumeration
Procedure.i Window_mainForm()
If OpenWindow(#Window_mainForm,0,0,800,250,"Test with Buttons",#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_ScreenCentered|#PB_Window_Invisible)
ButtonGadget(#beginbutton,0,0,60,20,"Begin")
ButtonGadget(#buttonA, 100, 30, 150, 60, "A")
ButtonGadget(#buttonB, 300, 30, 150, 60, "B")
ButtonGadget(#buttonC, 500, 30, 150, 60, "C")
TextGadget(#text1, 225,150,300,20,"",#PB_Text_Border|#PB_Text_Center)
TextGadget(#text2, 225,180,300,20,"",#PB_Text_Border|#PB_Text_Center)
HideWindow(#Window_mainForm,0)
ProcedureReturn WindowID(#Window_mainForm)
EndIf
EndProcedure
If Window_mainForm()
Define quitmainForm=0
SetGadgetText(#text2,"hit Begin button to start")
Repeat ;main outer loop
Select WaitWindowEvent()
Case #PB_Event_Gadget
Select EventGadget()
Case #beginbutton
DisableGadget(#beginbutton,1)
SetGadgetText(#text1, "")
SetGadgetText(#text2, "Left Click on a button (you get 4 tries)")
For i = 1 To 4
proceed = 0
Repeat ;inner loop for begin button behavior
Select WaitWindowEvent()
Case #PB_Event_Gadget
Select EventGadget()
Case #buttonA
proceed = 1
SetGadgetText(#text1, "on try " + Str(i))
SetGadgetText(#text2, "You pressed the A button")
Case #buttonB
proceed = 1
SetGadgetText(#text1, "on try " + Str(i))
SetGadgetText(#text2, "You pressed the B button")
Case #buttonC
proceed = 1
SetGadgetText(#text1, "on try " + Str(i))
SetGadgetText(#text2, "You pressed the C button")
EndSelect ;EventGadget() inner
EndSelect ;WaitWindowEvent() inner
Until proceed
Next i
Delay(1000)
DisableGadget(#beginbutton,0)
SetGadgetText(#text1, "Yer done!")
SetGadgetText(#text2, "Press the Begin button for even more thrills.")
EndSelect ;EventGadget() outer
Case #PB_Event_CloseWindow
If WindowID=#Window_mainForm
quitmainForm=1
EndIf
EndSelect ;WaitWindowEvent() outer
Until quitmainForm
CloseWindow(#Window_mainForm)
EndIf ;window
Code: Select all
;postwithstringgadgets.pb
;Test of an outer and inner event loop
;Click on begin button, then randomly on the stringGadgets.
;The textGadgets will report which stringGadget was clicked on.
;Unlike buttons, the stringGadgets seem to generate additional events.
;The event processing in the code below does not handle them properly.
;- Window Constants
Enumeration
#Window_mainForm
#beginbutton
#stringA
#stringB
#stringC
#text1
#text2
EndEnumeration
Procedure.i Window_mainForm()
If OpenWindow(#Window_mainForm,0,0,800,250,"Test with StringGadgets",#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_ScreenCentered|#PB_Window_Invisible)
ButtonGadget(#beginbutton,0,0,60,20,"Begin")
StringGadget(#stringA,100, 30, 150, 60, "A",#ES_MULTILINE|#ES_AUTOVSCROLL|#ESB_DISABLE_LEFT|#ESB_DISABLE_RIGHT|#ES_READONLY)
StringGadget(#stringB,300, 30, 150, 60, "B",#ES_MULTILINE|#ES_AUTOVSCROLL|#ESB_DISABLE_LEFT|#ESB_DISABLE_RIGHT|#ES_READONLY)
StringGadget(#stringC,500, 30, 150, 60, "C",#ES_MULTILINE|#ES_AUTOVSCROLL|#ESB_DISABLE_LEFT|#ESB_DISABLE_RIGHT|#ES_READONLY)
TextGadget(#text1, 225,150,300,20,"",#PB_Text_Border|#PB_Text_Center)
TextGadget(#text2, 225,180,300,20,"",#PB_Text_Border|#PB_Text_Center)
HideWindow(#Window_mainForm,0)
ProcedureReturn WindowID(#Window_mainForm)
EndIf
EndProcedure
If Window_mainForm()
Define quitmainForm=0
Repeat ;main outer loop
SetGadgetText(#text2,"hit Begin button to start")
Select WaitWindowEvent()
Case #PB_Event_Gadget
Select EventGadget()
Case #beginbutton
DisableGadget(#beginbutton,1)
SetGadgetText(#text1, "")
SetGadgetText(#text2, "Left Click on a string gadget (you get 4 tries)")
For i = 1 To 4
proceed = 0
Repeat ;inner loop for begin button behavior
Select WaitWindowEvent()
Case #PB_Event_Gadget
Select EventGadget()
Case #stringA
proceed = 1
SetGadgetText(#text1, "on try " + Str(i))
SetGadgetText(#text2, "You pressed the A string gadget")
Case #stringB
proceed = 1
SetGadgetText(#text1, "on try " + Str(i))
SetGadgetText(#text2, "You pressed the B string gadget")
Case #stringC
proceed = 1
SetGadgetText(#text1, "on try " + Str(i))
SetGadgetText(#text2, "You pressed the C string gadget")
EndSelect ;EventGadget() inner
EndSelect ;WaitWindowEvent() inner
Until proceed
Next i
Delay(1000)
DisableGadget(#beginbutton,0)
SetGadgetText(#text1, "Yer done!")
SetGadgetText(#text2, "Press the Begin button again for even more thrills.")
EndSelect ;EventGadget() outer
Case #PB_Event_CloseWindow
If WindowID=#Window_mainForm
quitmainForm=1
EndIf
EndSelect ;WaitWindowEvent() outer
Until quitmainForm
CloseWindow(#Window_mainForm)
EndIf ;window



