Results 1 to 9 of 9

Thread: [RESOLVED] form wont unload?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2004
    Location
    Newcastle
    Posts
    114

    Resolved [RESOLVED] form wont unload?

    hi guys, well what it is my form wont proply unload when useing winsock.
    when i open the form and close it straight away, it unload fine but when i connect to my server useing winsock, i unload the form but i have to press Ctrl,Alt,Delete and end the task? does anyone know how to prevent me haveing to do this everytime? thanks

  2. #2
    Addicted Member
    Join Date
    Apr 2006
    Posts
    155

    Re: form wont unload?

    Quote Originally Posted by Lazer
    hi guys, well what it is my form wont proply unload when useing winsock.
    when i open the form and close it straight away, it unload fine but when i connect to my server useing winsock, i unload the form but i have to press Ctrl,Alt,Delete and end the task? does anyone know how to prevent me haveing to do this everytime? thanks
    VB Code:
    1. Private Sub Form_Unload(Cancel As Integer)
    2.    If Winsock1.State <> sckClosed Then Winsock1.Close 'close if any connection is trying to be made
    3.     Unload Me 'unload the form
    4.      End 'terminate the program
    5. End Sub

  3. #3
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: form wont unload?

    Quote Originally Posted by XRsTX
    VB Code:
    1. Private Sub Form_Unload(Cancel As Integer)
    2.    If Winsock1.State <> sckClosed Then Winsock1.Close 'close if any connection is trying to be made
    3.     Unload Me 'unload the form
    4.      End 'terminate the program
    5. End Sub
    The form is already unloading so there is no need to call Unload Me again.

    And never use End. Forget it exists. All objects / connections / etc. should be unloaded / destroyed / closed / etc. in your Form_Unload event.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Mar 2004
    Location
    Newcastle
    Posts
    114

    Re: form wont unload?

    VB Code:
    1. Private Sub form_unload(Cancel As Integer)
    2.    If connection.State <> sckClosed Then connection.Close
    3. End Sub

    it still shows in the windows task manager. i realy cant understnad why its doing this

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: form wont unload?

    make sure no other code is execute in the sub you call unload me, this can keep the program running, if in doubt use
    VB Code:
    1. Unload Me
    2. Exit Sub
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  6. #6
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: form wont unload?

    when you run it in step by step by pressing F8, what happens...
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  7. #7
    PowerPoster Simply Me's Avatar
    Join Date
    Aug 2003
    Posts
    2,748

    Re: form wont unload?

    Quote Originally Posted by ganeshmoorthy
    when you run it in step by step by pressing F8, what happens...
    I agree
    To give is always to be NOBLE...
    To received is always to be BLESSED....
    Each day strive to be NOBLE
    Each day strive to be BLESSED

    If this post has helped you. Please take time to rate it.

    >=|+|=< Simply Me >=|+|=<

    ----------------------------------------
    Connection Strings | Number Only in Textbox | Splash Screen with Progress Bar | Printing to 1/2 of perforated bond paper |
    Freeze 2005 DataGridView Column

  8. #8
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: form wont unload?

    Either ..
    VB Code:
    1. '// UNLOAD FORM
    2. Private Sub Form_Unload(Cancel As Integer)
    3.     '// END TIMER IF YOU HAVE
    4.     ' Timer1.Interval = 0
    5.     ' Timer1.Enabled = False
    6.     '// CLOSE ANY OPEN CONN
    7.     Winsock1.Close
    8.     '// UNLOAD ALL FORMS
    9.     Do Until Forms.Count = 1
    10.         Unload Forms(Forms.Count - 1)
    11.     Loop
    12. End Sub

    Or ... something like this .. depends what forms and controls you have ..

    VB Code:
    1. Private Sub form_unload(Cancel As Integer)
    2.     Dim ctl As Control
    3.     For Each ctl In Me.Controls
    4.         If TypeOf ctl Is Timer Then      ' stop timers
    5.             ctl.Interval = 0
    6.             ctl.Enabled = False
    7.         End If
    8.         If TypeOf ctl Is Winsock Then  ' close winsocks
    9.             ctl.Close
    10.         End If
    11.     Next
    12.  
    13.     ' unload all forms
    14.     Do Until Forms.Count = 1
    15.         Unload Forms(Forms.Count - 1)
    16.     Loop
    17.  
    18. End Sub

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Mar 2004
    Location
    Newcastle
    Posts
    114

    Re: form wont unload?

    works a treat, thanks guys

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width