AllExperts > FoxPro 
Search      
FoxPro
Volunteer
Answers to thousands of questions
 Home · More FoxPro Questions · Answer Library  · Encyclopedia ·
More FoxPro Answers
Question Library

Ask a question about FoxPro
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Markish
Expertise
I can answer general questions related to Foxpro from Version 2.0 to 9.0. I'll try to answer them as quickly as possible.

Experience
I've been into Dbase programming from age of 11. I've worked in versions from FoxPro 2.0 and Foxbase.
Education/Credentials
I've done my B.Tech (IT) with distinction from Anna University, Chennai - India.

 
   

You are here:  Experts > Computing/Technology > Databases > FoxPro > Unload/Release Forms while in Main Form

FoxPro - Unload/Release Forms while in Main Form


Expert: Markish - 8/19/2008

Question
Markish,


I'm trying to release all forms loaded in the MainForm when i click LogOFF button. I'm getting an error 'Object 'name' is not found.' when I issue a release command.

Here is my code to RELEASE the forms.
Local instance_ct As Integer
Local lcCmd As String

instance_ct   = 0
For ii=1 To _Screen.FormCount
  If Upper(_Screen.Forms(ii).Name) <> Upper('frmMainForm') THEN
     lcCmd = Alltrim(_Screen.Forms(ii).Name) +'.Release'
     &lcCmd
  Endif
Next ii

Or do you have any suggestion on how to do my LOGOFF routine.

Thanks in advance.


Best regards,

FLeX
VFP7 Developer

Answer
Hi Flex,
   I had a look at your code, It's a small problem. Moment you release one form, the total number of forms get reduces. Hence if you try to refer one of the form with form(ii) that is not exisiting... It gives an error. I'm not sure if you want to close all other forms but for the frmmain. For this you can store the forms to be closed into an array and close them. Code like below will do

DIMENSION mactive_forms(100)
frm_ct=0
FOR ctr=1 To _screen.FormCount
  If _Screen.Forms(ctr).Name<>Thisform.Name
     frm_ct=frm_ct+1
     mactive_forms(frm_ct)=_Screen.Forms(ctr)
  ENDIF
ENDFOR
IF frm_ct>0
  FOR ctr=1 TO frm_ct
     mactive_forms(ctr).release
  ENDFOR
ENDIF

If you want to close all the forms otherwise, you can use
FOR ctr=_screen.FormCount TO 1 STEP -1
  _Screen.Forms(ctr).Release
ENDFOR

Hope this helps...
Best regards,
Markish
http://markishonline.com


Add to this Answer   Ask a Question


 
User Agreement | Privacy Policy | Kids' Privacy Policy | Help
Copyright  © 2008 About, Inc. AllExperts, AllExperts.com, and About.com are registered trademarks of About, Inc. All rights reserved.