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
New Smaller program still won't work but is working better
-
johnorourke1351
- User

- Posts: 37
- Joined: Sun Nov 02, 2014 6:23 pm
- Location: Los Angeles
Re: New Smaller program still won't work but is working bett
Could you please use the [ code ] tag? Just press the button "Code", it inserts:
[/code]
Now paste your code between the start and ending tag. You can also select some text
and then press the "Code" button to surround it with the tags. Thanks in advance!
Code: Select all
[code]Now paste your code between the start and ending tag. You can also select some text
and then press the "Code" button to surround it with the tags. Thanks in advance!
Re: New Smaller program still won't work but is working bett
Hello johnorourke1351. Your code is fine, except for one small syntax error; Result = ValidateFields(). Just add the parentheses and it works as expected. You must also declare the ValidateFields() procedure in small.pbf, just as you've done for the other procedures:johnorourke1351 wrote:...the program never gets beyond the result=validatefields...
in small.pbf:
Code: Select all
Declare CalcButtonEvent(EventType)
Declare SaveButtonEvent(EventType)
Declare ValidateFields() ;add this declarationTexas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel 
-
johnorourke1351
- User

- Posts: 37
- Joined: Sun Nov 02, 2014 6:23 pm
- Location: Los Angeles
Re: New Smaller program still won't work but is working bett
Hi ,
I corrected the parenthesis problem and , as you said, it works now. Thanks so much . I have included the corrected code with start and end code brackets around the code and the include statement commented out.
I corrected the parenthesis problem and , as you said, it works now. Thanks so much . I have included the corrected code with start and end code brackets around the code and the include statement commented out.
Code: Select all
;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
-
johnorourke1351
- User

- Posts: 37
- Joined: Sun Nov 02, 2014 6:23 pm
- Location: Los Angeles
Re: New Smaller program still won't work but is working bett
Hi,
I am not sure why you say that ValidateFields needs to be declared in small.pbf. When I compile small.pb and small.pbf the forms program removes the ValidateFields declaration and the program seems to work anyways. The ValidateFields code is only in small.pb and is not referred to in the form code or objects related to it.
John O
I am not sure why you say that ValidateFields needs to be declared in small.pbf. When I compile small.pb and small.pbf the forms program removes the ValidateFields declaration and the program seems to work anyways. The ValidateFields code is only in small.pb and is not referred to in the form code or objects related to it.
John O
Re: New Smaller program still won't work but is working bett
Yes, John; you're right about the declaration being removed by the form designer. However, based on the listing that you've posted here, calling the ValidateFields() procedure from the CalcButtonEvent() procedure would fail, because it has not been declared. You'd either have to declare it in small.pb, or re-position the ValidateFields() procedure before the CalcButtonEvent() procedure:johnorourke1351 wrote:I am not sure why you say that ValidateFields needs to be declared in small.pbf. When I compile small.pb and small.pbf the forms program removes the ValidateFields declaration and the program seems to work anyways. The ValidateFields code is only in small.pb and is not referred to in the form code or objects related to it.
declare the ValidateFields() procedure in small.pb
Code: Select all
OpenWindow_0()
Declare CheckNull(Gadget)
Declare ValidateFields()
Procedure SaveButtonEvent(EventType)
Debug "SaveButton event"
EndProcedure
Procedure CalcButtonEvent(EventType)
Result = ValidateFields()
If Result<>1
Result = CalculateFields
EndIf
Debug "Calc event"
EndProcedure
Procedure ValidateFields()
Result = CheckNull(#String_Name)
If Result=1
ProcedureReturn 1
EndIf
EndProcedureCode: Select all
OpenWindow_0()
Declare CheckNull(Gadget)
Procedure SaveButtonEvent(EventType)
Debug "SaveButton event"
EndProcedure
Procedure ValidateFields()
Result = CheckNull(#String_Name)
If Result=1
ProcedureReturn 1
EndIf
EndProcedure
Procedure CalcButtonEvent(EventType)
Result = ValidateFields()
If Result<>1
Result = CalculateFields
EndIf
Debug "Calc event"
EndProcedureTexas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel 
-
johnorourke1351
- User

- Posts: 37
- Joined: Sun Nov 02, 2014 6:23 pm
- Location: Los Angeles
Re: New Smaller program still won't work but is working bett
Hi,
Ok. I have been learning about rearranging the procedures so they are positioned before the procedures that call them. Thanks again for your help.
Slowly but surely I am learning not to foolishly call people by their purebasic classification category.
John O
Ok. I have been learning about rearranging the procedures so they are positioned before the procedures that call them. Thanks again for your help.
Slowly but surely I am learning not to foolishly call people by their purebasic classification category.
John O
