Problem With Closing Form

jothis

Active Member
Licensed User
Hi,
I created a new program,
Where I created forms by coding. with AddForm functions

see the code

Sub Globals
'Declare the global variables here.

End Sub

Sub App_Start
Design
End Sub
Sub Design
AddForm("FIRSTFORM","First")
FIRSTFORM.Show
End Sub
Sub FIRSTFORM_Close
AppClose
End Sub



So when I close that form, I got an error.
Please see the attachment. Can you help me please.
jothis
:sign0085:
 

Attachments

  • 2.sbp
    603 bytes · Views: 178

taximania

Well-Known Member
Licensed User
Longtime User
I was up early.

B4X:
Sub Globals
   'Declare the global variables here.

End Sub
Sub App_Start
   For a = 1 To 6 'Form1 to Form6
   AddEvent("Form" & a,Close,"F_Close")
   Next a
   For a = 1 To 5 'Button1 to Button5
   AddEvent("Button" & a,Click,"B_Click")
   Next a
   Form1.Show
End Sub



Sub F_Close
AppClose
End Sub

Sub B_Click 
              'Sender will be "Button1","Button2" etc
              'We only want the 1,2 etc
   b = StrAt(Sender,6)
   b=b+1 'Button2 closes Form3, Button3 closes Form4 etc
    Control("Form" & b,Form).Show
End Sub

If you use AddForm in code, you will have to add all the buttons
to the seperate Forms in code as well.
 

Attachments

  • test.sbp
    1.2 KB · Views: 210
Last edited:

jothis

Active Member
Licensed User
Thank you taximania,

I used Your Code But It is Not Successful. When I Close My Application The Program seems Not Respond And show a error "Basic4ppc has countered a problem and needs to close we are sorry for the in convenience " box with two buttons send error report ,dont send
i hope you understand my problem
please see the error image.zip file i attached here

jothis
:sign0085:
 
Last edited:

klaus

Expert
Licensed User
Longtime User
You don't need the lines in red.

Sub App_Start
Design
End Sub

Sub
Design
AddForm("FIRSTFORM","First")
AddButton("FIRSTFORM","gotoForm2",20,30,60,30,"Go")
AddForm("SECONDFORM","SECOND")
AddLabel("SECONDFORM","lbl2",60,60,60,40,"Form2")
FIRSTFORM.Show
End Sub

Sub
FIRSTFORM_Close
AppClose
End Sub

Sub
gotoForm2_Click
SECONDFORM.Show
End Sub

Best regards.
 

jothis

Active Member
Licensed User
Hi all,

But when I click on the close(X), in the form2. I am going to form1.
So , But I don't want to return to previous form.
If I close a form, I want to close complete application instead of going to previous forms.

If I have more than 100 forms, I will return to each form when I close each form.

So I wish to close my application.

I think you understand what i meant.

can you help me please.

with Thanks,
Jothis
 

taximania

Well-Known Member
Licensed User
Longtime User
I'm using B4ppc V6.80 :(
You might have to alter the 'control' syntax.

It changed in V6.90
If that is what you are using.
Instead of writing Control(ControlName, ControlType), it is now possible to write ControlType(ControlName). The desktop IDE fully supports the new syntax with autocomplete and with the usual popup menu.
The code I wrote works as you wish with V6.80 ;-)
Don't give up, you'll get there :)


Adios, Au revoir, Buenos Nochas, bye bye etc, packing my suitcase :sign0060:
 
Last edited:

robinathome

Member
Licensed User
Longtime User
The attached shows how it could be closed with a minor modification to the above. You don't need to add the AppClose to the Main Form, ie Form1. Closing From1 will close the application.

Sub Globals
'Declare the global variables here.

End Sub
Sub App_Start
For a = 2 To 6
AddEvent("Form" & a,Close,"F_Close")
Next a
For a = 1 To 5
AddEvent("Button" & a,Click,"B_Click")
Next a
Form1.Show
End Sub

Sub F_Close
AppClsoe
End Sub

Sub B_Click
b = StrAt(Sender,6)
b=b+1
Form("Form" & b).Show
End Sub

Hope this helps.:):):)
Robin
 

jothis

Active Member
Licensed User
Thankyou

Thankyou For Your Help.

I Solved The Problem With Closing Form With This Code

Sub Globals
'Declare the global variables here.

End Sub
Sub App_Start
Designer
form.Show
End Sub
Sub Designer
AddForm("form","newform")
AddButton("form","Login",20,30,80,30,"login")
AddForm("form0","seconform")
AddButton("form0","ThirdForm",20,30,80,30,"ThirdForm")
AddForm("form1","Thirdform")
End Sub
Sub Login_Click
form0.Show
End Sub
Sub form0_Close
form.Close
End Sub
Sub ThirdForm_Click
form1.Show
End Sub
Sub form1_Close
form.Close
End Sub

jothis
:sign0060:
 
Top