New Smaller program still won't work but is working better
Posted: Sat Nov 08, 2014 6:21 am
Hi,
I am beginning to think the forms program has gotten out of sync with the actual screen and the code it generates (I posted earlier about multiple problems).
But here is a smaller set of programs.
I am trying to test a name field to make sure that it is not null and I will eventually calculate an amount field after all of the validation is done on all of my fields. In this simple example, I don't have a lot of fields yet but I am just trying to debug the overall program flow first.
I have a .pb main program and a .pbf form source code file included in .pb
Here is the code I will trying to comment the sections I am having trouble with:
XIncludeFile "small.pbf" ; Include the first window definition
;OpenSmallWindow() ; Open the first window. This procedure name is always 'Open' followed by the window name
OpenWindow_0()
; The event procedures, as specified in the 'event procedure' property of each gadget
Declare CheckNull(Gadget)
Procedure SaveButtonEvent(EventType)
Debug "SaveButton event"
EndProcedure
Procedure CalcButtonEvent(EventType)
; I put a breakpoint here after I clear the data out of the name field on the displayed screen and press the "Calc" button
; the program never gets beyond the result=validatefields it doesn't reach the if result<>1 statement and doesn't execute ValidateFields
; There is undoubtedly something very simple that I am doing wrong here but I don't see it
Result = ValidateFields
If Result<>1
Result = CalculateFields
EndIf
Debug "Calc event"
EndProcedure
Procedure ValidateFields()
;I have a breakpoint at result = ... but it never gets here
;Why?
Result = CheckNull(#String_Name)
If Result=1
ProcedureReturn 1
EndIf
EndProcedure
;I want to check for a null value in my gadget which in this case is the #String_Name
;But it doesn't get here either
Procedure CheckNull(Gadget)
TestString$ = GetGadgetText(Gadget)
If TestString$ = ""
MessageRequester ("Error", "You must enter a value", #PB_MessageRequester_Ok)
ProcedureReturn 1
Else
ProcedureReturn 0
EndIf
EndProcedure
; The main event loop as usual, the only change is to call the automatically
; generated event procedure for each window.
Repeat
Event = WaitWindowEvent()
Select EventWindow()
Case Window_0
Window_0_Events(Event) ; This procedure name is always window name followed by '_Events'
EndSelect
Until Event = #PB_Event_CloseWindow ; Quit on any window close
Here is the screen code from small.pbf
;
; This code is automatically generated by the FormDesigner.
; Manual modification is possible to adjust existing commands, but anything else will be dropped when the code is compiled.
; Event procedures needs to be put in another source file.
;
; Earlier the forms program seemed to be generating weird code but in the smaller version of this program it seems to be ok now.
;
Global Window_0
Global Text_Name, Text_Amount
Enumeration FormGadget
#String_Name
#String_Amount
#Button_Save
#Button_Calc
EndEnumeration
Declare CalcButtonEvent(EventType)
Declare SaveButtonEvent(EventType)
Procedure OpenWindow_0(x = 0, y = 0, width = 700, height = 390)
Window_0 = OpenWindow(#PB_Any, x, y, width, height, "", #PB_Window_SystemMenu)
Text_Name = TextGadget(#PB_Any, 60, 90, 100, 25, "Name")
StringGadget(#String_Name, 160, 90, 100, 25, "Name")
Text_Amount = TextGadget(#PB_Any, 300, 90, 100, 25, "Amount")
StringGadget(#String_Amount, 400, 90, 100, 25, "")
ButtonGadget(#Button_Save, 70, 190, 100, 25, "Save")
ButtonGadget(#Button_Calc, 180, 190, 100, 25, "Calc")
EndProcedure
Procedure Window_0_Events(event)
Select event
Case #PB_Event_CloseWindow
ProcedureReturn #False
Case #PB_Event_Menu
Select EventMenu()
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case #Button_Save
SaveButtonEvent(EventType())
Case #Button_Calc
CalcButtonEvent(EventType())
EndSelect
EndSelect
ProcedureReturn #True
EndProcedure
I am beginning to think the forms program has gotten out of sync with the actual screen and the code it generates (I posted earlier about multiple problems).
But here is a smaller set of programs.
I am trying to test a name field to make sure that it is not null and I will eventually calculate an amount field after all of the validation is done on all of my fields. In this simple example, I don't have a lot of fields yet but I am just trying to debug the overall program flow first.
I have a .pb main program and a .pbf form source code file included in .pb
Here is the code I will trying to comment the sections I am having trouble with:
XIncludeFile "small.pbf" ; Include the first window definition
;OpenSmallWindow() ; Open the first window. This procedure name is always 'Open' followed by the window name
OpenWindow_0()
; The event procedures, as specified in the 'event procedure' property of each gadget
Declare CheckNull(Gadget)
Procedure SaveButtonEvent(EventType)
Debug "SaveButton event"
EndProcedure
Procedure CalcButtonEvent(EventType)
; I put a breakpoint here after I clear the data out of the name field on the displayed screen and press the "Calc" button
; the program never gets beyond the result=validatefields it doesn't reach the if result<>1 statement and doesn't execute ValidateFields
; There is undoubtedly something very simple that I am doing wrong here but I don't see it
Result = ValidateFields
If Result<>1
Result = CalculateFields
EndIf
Debug "Calc event"
EndProcedure
Procedure ValidateFields()
;I have a breakpoint at result = ... but it never gets here
;Why?
Result = CheckNull(#String_Name)
If Result=1
ProcedureReturn 1
EndIf
EndProcedure
;I want to check for a null value in my gadget which in this case is the #String_Name
;But it doesn't get here either
Procedure CheckNull(Gadget)
TestString$ = GetGadgetText(Gadget)
If TestString$ = ""
MessageRequester ("Error", "You must enter a value", #PB_MessageRequester_Ok)
ProcedureReturn 1
Else
ProcedureReturn 0
EndIf
EndProcedure
; The main event loop as usual, the only change is to call the automatically
; generated event procedure for each window.
Repeat
Event = WaitWindowEvent()
Select EventWindow()
Case Window_0
Window_0_Events(Event) ; This procedure name is always window name followed by '_Events'
EndSelect
Until Event = #PB_Event_CloseWindow ; Quit on any window close
Here is the screen code from small.pbf
;
; This code is automatically generated by the FormDesigner.
; Manual modification is possible to adjust existing commands, but anything else will be dropped when the code is compiled.
; Event procedures needs to be put in another source file.
;
; Earlier the forms program seemed to be generating weird code but in the smaller version of this program it seems to be ok now.
;
Global Window_0
Global Text_Name, Text_Amount
Enumeration FormGadget
#String_Name
#String_Amount
#Button_Save
#Button_Calc
EndEnumeration
Declare CalcButtonEvent(EventType)
Declare SaveButtonEvent(EventType)
Procedure OpenWindow_0(x = 0, y = 0, width = 700, height = 390)
Window_0 = OpenWindow(#PB_Any, x, y, width, height, "", #PB_Window_SystemMenu)
Text_Name = TextGadget(#PB_Any, 60, 90, 100, 25, "Name")
StringGadget(#String_Name, 160, 90, 100, 25, "Name")
Text_Amount = TextGadget(#PB_Any, 300, 90, 100, 25, "Amount")
StringGadget(#String_Amount, 400, 90, 100, 25, "")
ButtonGadget(#Button_Save, 70, 190, 100, 25, "Save")
ButtonGadget(#Button_Calc, 180, 190, 100, 25, "Calc")
EndProcedure
Procedure Window_0_Events(event)
Select event
Case #PB_Event_CloseWindow
ProcedureReturn #False
Case #PB_Event_Menu
Select EventMenu()
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case #Button_Save
SaveButtonEvent(EventType())
Case #Button_Calc
CalcButtonEvent(EventType())
EndSelect
EndSelect
ProcedureReturn #True
EndProcedure