SOLVED Inputting/Validating Form Data
Posted: Mon Dec 15, 2025 9:20 pm
Ubuntu Unity 24.04 PureBasic 6.21
Hi.
I used the PureBasic built in Form Designer to set up a simple 3 gadget Form; Customer Number (CustNum), Customer Name (CustName), and an Update Button (Button_Update).
I'm trying to find sample code that will demonstrate to me the correct way to input and validate the Fields (gadgets) according to some criteria, like:
CustNum must be 4 digits
CustName can be 3 to 20 characters, A-Z, a-z, or a '.'
When both fields are entered correctly, the 'Update' button would be pressed, the fields cleared, and the next Customer Data would be entered.
The Form .pbf file was generated like this:
but what would the rest of the Source Code be ?
3. In my old Main Frame programming days, I would have Numbered Fields. You selected the Number Of the Field, entered the data, and hit carriage return. Then there would be a validation process. If there were any invalid characters (a letter instead of a number, etc.), an error message would be displayed, and you would have to re-enter the field.
I do not know how to do this in PB. I gather an event is triggered when a character is entered for any gadget. How can I capture and validate that character ?
And how would I know if someone leaves a Field (gadget) prematurely before it is complete (like only entering 2 characters for the Name gadget) and then clicking on another gadget ?
Is there any sample code that would demonstrate to me on how Fields (gadgets) are inputted and validated ?
So much to learn.
Thanks,
M.....
Hi.
I used the PureBasic built in Form Designer to set up a simple 3 gadget Form; Customer Number (CustNum), Customer Name (CustName), and an Update Button (Button_Update).
I'm trying to find sample code that will demonstrate to me the correct way to input and validate the Fields (gadgets) according to some criteria, like:
CustNum must be 4 digits
CustName can be 3 to 20 characters, A-Z, a-z, or a '.'
When both fields are entered correctly, the 'Update' button would be pressed, the fields cleared, and the next Customer Data would be entered.
The Form .pbf file was generated like this:
Code: Select all
Global CustNum, CustName, Button_Update
Enumeration FormWindow
#TestFormWindow
EndEnumeration
Enumeration FormGadget
#Text_1
#Text_2
EndEnumeration
Declare CustNameProc(EventType)
Procedure OpenTestFormWindow(x = 0, y = 0, width = 720, height = 410)
OpenWindow(#TestFormWindow, x, y, width, height, "Test Form", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_TitleBar | #PB_Window_BorderLess | #PB_Window_ScreenCentered | #PB_Window_WindowCentered | #PB_Window_Maximize | #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_TitleBar | #PB_Window_BorderLess | #PB_Window_ScreenCentered | #PB_Window_WindowCentered | #PB_Window_Maximize)
SetWindowColor(#TestFormWindow, RGB(135,167,0))
CustNum = StringGadget(#PB_Any, 240, 70, 100, 25, "")
GadgetToolTip(CustNum, "4 Digits")
CustName = StringGadget(#PB_Any, 240, 130, 340, 25, "")
GadgetToolTip(CustName, "3-20 Characters")
TextGadget(#Text_1, 0, 70, 200, 25, "Customer Number: ")
TextGadget(#Text_2, 0, 130, 160, 25, "Customer Name:")
Button_Update = ButtonGadget(#PB_Any, 170, 280, 100, 25, "Update")
EndProcedure
Procedure TestFormWindow_Events(event)
Select event
Case #PB_Event_CloseWindow
ProcedureReturn #False
Case #PB_Event_Menu
Select EventMenu()
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case[b] CustName[/b]
CustNameProc(EventType())
EndSelect
EndSelect
ProcedureReturn #True
EndProcedure
[/quote]
Questions:
1. I see the Case of CustName, but why no reference to CustNum ?
2. I understand the first 3 lines of the Source Code would be:
[quote]XIncludeFile "TestForm01.pbf"
OpenTestFormWindow()
While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend3. In my old Main Frame programming days, I would have Numbered Fields. You selected the Number Of the Field, entered the data, and hit carriage return. Then there would be a validation process. If there were any invalid characters (a letter instead of a number, etc.), an error message would be displayed, and you would have to re-enter the field.
I do not know how to do this in PB. I gather an event is triggered when a character is entered for any gadget. How can I capture and validate that character ?
And how would I know if someone leaves a Field (gadget) prematurely before it is complete (like only entering 2 characters for the Name gadget) and then clicking on another gadget ?
Is there any sample code that would demonstrate to me on how Fields (gadgets) are inputted and validated ?
So much to learn.
Thanks,
M.....
