14 Replies - 84709 Views - Last Post: 29 January 2011 - 01:02 AM Rate Topic: -----

#1 Somyagupta  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 85
  • Joined: 05-August 10

How to close a form in vb6

Posted 24 August 2010 - 07:32 AM

What I want to do is terminate a form, or program, when certain conditions are not met.

I have successfully tested to see if the conditions exists to terminate; however, when I give an "Unload Me" statement, the system returns to the MDI form that called the program in the first place and errors with the message:

"object was unloaded"

and highlights the "show form" command.

It looks like my problem is that I never 'displayed' a screen object in the first place, so there is nothing to "unload". I don't want to terminate the whole application, just the current process.

Any help will be appreciated

Is This A Good Question/Topic? 0
  • +

Replies To: How to close a form in vb6

#2 guyfromri  Icon User is offline

  • D.I.C Addict

Reputation: 46
  • View blog
  • Posts: 836
  • Joined: 16-September 09

Re: How to close a form in vb6

Posted 24 August 2010 - 09:43 AM

Show us your code so we can help with out being vague and guessing
Was This Post Helpful? 0
  • +
  • -

#3 kingsonprisonic  Icon User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 74
  • Joined: 09-July 09

Re: How to close a form in vb6

Posted 24 August 2010 - 09:43 AM

Will you please give your code.....???? So we can help you..
Was This Post Helpful? 0
  • +
  • -

#4 Somyagupta  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 85
  • Joined: 05-August 10

Re: How to close a form in vb6

Posted 24 August 2010 - 11:03 AM

Private Sub menu_preview_license_Click()

    Form4.Show (vbModal)

End Sub






the second part of code uses szlist. but sometime this list is empty and generate error so I use "on error" sequence but this generate error


Private Sub Form_Load()

    Dim icount As Integer
    Dim ielement As Integer
    
    
    On Error GoTo error_unload
    
    ielement = UBound(szList) - LBound(szList)
    
    For icount = 0 To ielement
             
    
        Call loc_Check(szList(icount))
    
    Next icount


    
    Call loc_SetSelectedlist        
    Call loc_setAvailablelist
    
error_unload:
  
  lprt Me, "Error. szList is empty"
  Unload Form3
  'icount = MsgBox("Error! There is NO data available", vbOKOnly, "Error Loading Components")
  
  'Exit Sub
   
End Sub


Was This Post Helpful? 0
  • +
  • -

#5 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 330
  • View blog
  • Posts: 1,997
  • Joined: 26-March 09

Re: How to close a form in vb6

Posted 25 August 2010 - 11:48 AM

Maybe I'm reading this wrong, but you show Form4 modally, which I'm assuming has your code for szList, if so, should you not be Unloading form4 and not Form3?
Was This Post Helpful? 0
  • +
  • -

#6 Somyagupta  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 85
  • Joined: 05-August 10

Re: How to close a form in vb6

Posted 25 August 2010 - 11:58 AM

Typo error on my part in this post.

In my code I am writing form4
Was This Post Helpful? 0
  • +
  • -

#7 parbipin  Icon User is offline

  • D.I.C Head

Reputation: 29
  • View blog
  • Posts: 95
  • Joined: 23-August 10

Re: How to close a form in vb6

Posted 25 August 2010 - 04:43 PM

You cannot call Form_Unload Event from a Form_Load event procedure; You can hide this form at this time and unload it on the next event or user activity.
Was This Post Helpful? 0
  • +
  • -

#8 kingsonprisonic  Icon User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 74
  • Joined: 09-July 09

Re: How to close a form in vb6

Posted 26 August 2010 - 11:19 AM

View Postparbipin, on 25 August 2010 - 03:43 PM, said:

You cannot call Form_Unload Event from a Form_Load event procedure; You can hide this form at this time and unload it on the next event or user activity.



It's not true..

I mean you can call a unload event from a load event. Like:

Private Sub Form_Load()
Unload Me
End Sub





And "parbipin", please don't give any wrong suggestion if you don't know a thing very well...

Thank you....

This post has been edited by kingsonprisonic: 26 August 2010 - 11:41 AM

Was This Post Helpful? 0
  • +
  • -

#9 parbipin  Icon User is offline

  • D.I.C Head

Reputation: 29
  • View blog
  • Posts: 95
  • Joined: 23-August 10

Re: How to close a form in vb6

Posted 26 August 2010 - 11:41 AM

@kingsonprisonic: I am sorry, I realize I didn't make it clear enough... I was talking about calling Unload Form while the same form is being loaded;

which will be equivalent to Unload Me in a Form Load event.
Was This Post Helpful? 0
  • +
  • -

#10 kingsonprisonic  Icon User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 74
  • Joined: 09-July 09

Re: How to close a form in vb6

Posted 26 August 2010 - 11:47 AM

Use

On Error Resume Next


Simple.....
Was This Post Helpful? 0
  • +
  • -

#11 parbipin  Icon User is offline

  • D.I.C Head

Reputation: 29
  • View blog
  • Posts: 95
  • Joined: 23-August 10

Re: How to close a form in vb6

Posted 26 August 2010 - 12:00 PM

Thanks for the suggestion but I don't think that will avoid the error because the error occurs not at Unload Me but when it executes End Sub or Exit Sub after unloading the form. because it no longer exits in the memory. and that cant be handled with an On Error Resume Next.


The correct way to avoid getting an error is use the obnoxious "End" command just after Unload Me
Was This Post Helpful? 0
  • +
  • -

#12 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 469
  • View blog
  • Posts: 4,280
  • Joined: 25-March 09

Re: How to close a form in vb6

Posted 27 August 2010 - 02:44 AM

@kingsonprisonic avoid using on error resume next any where you can.
simple example why:
Private Sub Command1_Click()
    Dim str1 As String
    Dim num1 As Integer
    Dim result1 As Double
    Dim result2 As Double
    On Error Resume Next
    
    str1 = "Abc"
    num1 = 2
    
    result1 = str1 / num1
    
    result2 = (1 + result1) / 2
    MsgBox result2
End Sub



the message box will show 0.5 every time error show up witch is incorrect data while using this:
Private Sub Command1_Click()
    Dim str1 As String
    Dim num1 As Integer
    Dim result1 As Double
    Dim result2 As Double
    On Error GoTo err_h
    
    str1 = "Abc"
    num1 = 2
    
    result1 = str1 / num1
    
    result2 = (1 + result1) / 2
    MsgBox result2
    Exit Sub
err_h:
    MsgBox "ERROR " & Err.Number & " " & Err.Description
End Sub



will warn the user that he have incorrect data.

@OP if you show form4 why you try to unload form3 on error handler? do you load form 3 anywhere?

This post has been edited by NoBrain: 27 August 2010 - 02:54 AM

Was This Post Helpful? 0
  • +
  • -

#13 Guest_MengKeang*


Reputation:

Re: How to close a form in vb6

Posted 28 January 2011 - 09:47 AM

I want to close the active form and then open another form in VB6.0, but I can't accomplish it because when I used the Unload statement, it will terminate the application. Any help will be appreciated... Here is my code.

Private Sub CommandButton1_Click()
Unload Me
Load Form2



AND

Private Sub CommandButton1_Click()
Unload Me
Form2.Show
[/Code]
Was This Post Helpful? 0

#14 Guest_MengKeang*


Reputation:

Re: How to close a form in vb6

Posted 28 January 2011 - 09:53 AM

View PostMengKeang, on 28 January 2011 - 09:47 AM, said:

I want to close the active form and then open another form in VB6.0, but I can't accomplish it because when I used the Unload statement, it will terminate the application. Any help will be appreciated... Here is my code.

Private Sub CommandButton1_Click()
Unload Me
Load Form2
End Sub



AND

Private Sub CommandButton1_Click()
Unload Me
Form2.Show
End Sub
[/Code]

Was This Post Helpful? 0

#15 BobRodes  Icon User is offline

  • Lovable Curmudgeon
  • member icon

Reputation: 600
  • View blog
  • Posts: 3,071
  • Joined: 19-May 09

Re: How to close a form in vb6

Posted 29 January 2011 - 01:02 AM

View Postkingsonprisonic, on 26 August 2010 - 11:47 AM, said:

Use

On Error Resume Next


Simple.....

The only time to ever use On Error Resume Next is when you want to do inline error handling, and then handle the error afterwards. It is NOT a way to ignore phantom runtime errors. This only makes them someone else's problem.

View PostMengKeang, on 28 January 2011 - 09:47 AM, said:

I want to close the active form and then open another form in VB6.0, but I can't accomplish it because when I used the Unload statement, it will terminate the application. Any help will be appreciated... Here is my code.

Private Sub CommandButton1_Click()
Unload Me
Load Form2



AND

Private Sub CommandButton1_Click()
Unload Me
Form2.Show
[/Code]

As you have seen, these don't work. It's like trying to keep running the program after you've stopped it! So, instead, show form2, then unload form1 in form2_load.

View PostSomyagupta, on 24 August 2010 - 07:32 AM, said:

What I want to do is terminate a form, or program, when certain conditions are not met.

I have successfully tested to see if the conditions exists to terminate; however, when I give an "Unload Me" statement, the system returns to the MDI form that called the program in the first place and errors with the message:

"object was unloaded"

and highlights the "show form" command.

It looks like my problem is that I never 'displayed' a screen object in the first place, so there is nothing to "unload". I don't want to terminate the whole application, just the current process.

Any help will be appreciated

Sounds like you tried to reference the form in your MDI form that called the "program," after unloading the form. That won't work, as you can see.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1