Fundamental misunderstanding of Gadget initialization
Posted: Sun Jun 21, 2015 11:11 pm
Hey All. Brand Newbie to PB here. I've been working through example codes, manual and these forums to learn PB and have had good success in most things so far. I have working forms, menus, Gadget creation, Includes, and procedures working with other procedures so I seem to be making progress. However I have stumbled upon a compiling error which indicates that I have missed a chapter somewhere on the fundamental operation of #gadget and variables in PB. What brought me to this is the desire to capture the Return/Enter key use by the user.
Reading the forum I came across the code below which appears to be the commonly acceptable method lacking a native PB command or gadget attribute for this purpose. I copied, compiled and ran this code and it works as advertized.
The above code worked well until I attempted to modify it
For my application, depending upon user input, he will be presented with 15 to 75 string gadgets into which he must enter data. I would like to control the movement of focus from str to str as data is entered and completed with the Return key (think spreadsheet data entry). I attempted to generalize the above code so that instead of listing all of the possible #String gadget constants or numbers in the Case statements, I could identify them by using either SetGadgetData()/GetGadgetData() or by using GadgetType(). Both attempts ended with: [ERROR] The specified #Gadget is Not initialised. My ill-fated attempt with the GadgetType method is below:
OK, now you can see that I have a deficiency in my fundamentals. Would someone please help:
1. Get my understanding about the use of gadget numbers and variables corrected (most important!)
2. Help me generalize the above code (nice, but if I have the above, I might be able to do it myself!)
Thanks to all those members who help us newbies. You have already helped me understand PB more than you realize.
Best,
John
Reading the forum I came across the code below which appears to be the commonly acceptable method lacking a native PB command or gadget attribute for this purpose. I copied, compiled and ran this code and it works as advertized.
Code: Select all
;Member:idle Post subject: Re: Intercept the *Return Key* PostPosted: Thu Feb 09, 2012 6:37 am
Enumeration 1
#String1
#string2
#string3
#string4
#menuQuit
EndEnumeration
OpenWindow(0,#Null,#Null,400,200,"HAI",#PB_Window_ScreenCentered)
StringGadget(#String1,5,5,300,20,"Sting Field 1")
StringGadget(#String2,5,35,300,20,"2 Field String 2")
AddKeyboardShortcut(0,#PB_Shortcut_Escape,#menuQuit)
OpenWindow(1,#Null,#Null,400,200,"HAI",#PB_Window_ScreenCentered)
StringGadget(#String3,5,5,300,20,"Sting Field 3")
StringGadget(#String4,5,35,300,20,"2 Field String 4")
AddKeyboardShortcut(1,#PB_Shortcut_Escape,#menuQuit)
SetActiveGadget(1)
Repeat
event=WaitWindowEvent()
evw = EventWindow()
Select event
Case #PB_Event_Gadget
eventg=EventGadget()
evw = EventWindow()
Select eventg
Case #String1,#string2,#string3,#string4
Select EventType()
Case #PB_EventType_Focus
AddKeyboardShortcut(evw,#PB_Shortcut_Return, eventg)
Case #PB_EventType_LostFocus
RemoveKeyboardShortcut(evw,#PB_Shortcut_Return)
EndSelect
EndSelect
Case #PB_Event_Menu
menu = EventMenu()
Select Menu
Case #String1,#string2,#string3,#string4
MessageRequester("Easy",GetGadgetText(menu)+" See?")
Case #menuQuit
Quit=1
EndSelect
Case #PB_Event_CloseWindow
Quit=1
RemoveKeyboardShortcut(0,#PB_Shortcut_Return)
RemoveKeyboardShortcut(1,#PB_Shortcut_Return)
EndSelect
Until Quit=1Code: Select all
Enumeration 1
#String1
#string2
#string3
#string4
#menuQuit
EndEnumeration
OpenWindow(0,#Null,#Null,400,200,"HAI",#PB_Window_ScreenCentered)
StringGadget(#String1,5,5,300,20,"Sting Field 1")
StringGadget(#String2,5,35,300,20,"2 Field String 2")
AddKeyboardShortcut(0,#PB_Shortcut_Escape,#menuQuit)
OpenWindow(1,#Null,#Null,400,200,"HAI",#PB_Window_ScreenCentered)
StringGadget(#String3,5,5,300,20,"Sting Field 3")
StringGadget(#String4,5,35,300,20,"2 Field String 4")
AddKeyboardShortcut(1,#PB_Shortcut_Escape,#menuQuit)
SetActiveGadget(1)
Repeat
event=WaitWindowEvent()
evw = EventWindow()
Select event
Case #PB_Event_Gadget
eventg=EventGadget()
gtype=GadgetType(eventg) ;Determine Gadget Type: produces ERROR The specified Gadget is not initialised
evw = EventWindow()
Select gtype
Case #PB_GadgetType_String ; if Gadget Type is a string gadget
Select EventType()
Case #PB_EventType_Focus
AddKeyboardShortcut(evw,#PB_Shortcut_Return, eventg)
Case #PB_EventType_LostFocus
RemoveKeyboardShortcut(evw,#PB_Shortcut_Return)
EndSelect
EndSelect
Case #PB_Event_Menu
menu = EventMenu()
Select Menu
Case #PB_GadgetType_String
MessageRequester("Easy",GetGadgetText(menu)+" See?")
Case #menuQuit
Quit=1
EndSelect
Case #PB_Event_CloseWindow
Quit=1
RemoveKeyboardShortcut(0,#PB_Shortcut_Return)
RemoveKeyboardShortcut(1,#PB_Shortcut_Return)
EndSelect
Until Quit=11. Get my understanding about the use of gadget numbers and variables corrected (most important!)
2. Help me generalize the above code (nice, but if I have the above, I might be able to do it myself!)
Thanks to all those members who help us newbies. You have already helped me understand PB more than you realize.
Best,
John