On error goto....
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Thread: On error goto....

  1. #1
    Join Date
    Sep 2009
    Posts
    126

    On error goto....

    Hi. I have made an program with a winsock control. A chat program. Then if the winsock isint connected and you try to send something comes an error. When I put in on error goto Handler and write the 'Handler', it goes through even without a error.
    Help...
    And another question.
    When I save my project and press the button, make NameOfFile.exe there comes up an error: Permission denied to "C\Location\". This happends sometimes, not allways. Whats the problem?

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,101

    Re: On error goto....

    Quote Originally Posted by Equx View Post
    When I save my project and press the button, make NameOfFile.exe there comes up an error: Permission denied to "C\Location\". This happends sometimes, not allways. Whats the problem?
    I guess I can help here

    Before trying to compile ( MAke EXE ), make sure al the processes of your app has been destroyed. Meaning, make sure your program exits correctly. If you still have running processes of your program, while trying to make the exe again, you will get errors.

  3. #3
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: On error goto....

    Yes. Winsock sometimes leaves processes running in the background, when aborted or stopped on errors.

    To help you build a working error handler, we'd have to see what you did, that it won't trap the error as would be expected.

  4. #4
    Join Date
    Sep 2009
    Posts
    126

    Re: On error goto....

    Quote Originally Posted by WoF View Post
    Yes. Winsock sometimes leaves processes running in the background, when aborted or stopped on errors.

    To help you build a working error handler, we'd have to see what you did, that it won't trap the error as would be expected.
    OK Ty.
    Here is one example:
    Private Sub Form_Load()
    On Error GoTo Errorhandler
    MsgBox "Hello World!"

    Errorhandler:
    MsgBox "Error!"
    End Sub

    Here when you start up the program both two msgboxes comes up...

  5. #5
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,101

    Re: On error goto....

    OK, that helps a bit.

    How did you configure your Winsock control, any other code ¿

  6. #6
    Join Date
    Sep 2009
    Posts
    126

    Re: On error goto....

    Quote Originally Posted by HanneSThEGreaT View Post
    OK, that helps a bit.

    How did you configure your Winsock control, any other code
    what do you exact mean?

  7. #7
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,101

    Re: On error goto....

    CAn you upload your project here in zip format ¿

  8. #8
    Join Date
    Sep 2009
    Posts
    126

    Re: On error goto....

    Quote Originally Posted by HanneSThEGreaT View Post
    CAn you upload your project here in zip format
    I dont want other to get the code so I send you a PM with the download link!

  9. #9
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,101

    Re: On error goto....

    But you expect others to help you ¿

    This is a public forum, where all of us must share with each other.

    If you don't want everyone to see your code, fine that is your perogative, but you have to understand, that, without your code we cannot help you - do you understand that ¿

    We are all helping voluntary, we don't get anything except the satisfaction of helping others like you.

    Again, if you want us to help you, give the code so that we can help you.

    Take it, or leave it!

  10. #10
    Join Date
    Sep 2009
    Posts
    126

    Re: On error goto....

    Quote Originally Posted by HanneSThEGreaT View Post
    But you expect others to help you ¿

    This is a public forum, where all of us must share with each other.

    If you don't want everyone to see your code, fine that is your perogative, but you have to understand, that, without your code we cannot help you - do you understand that ¿

    We are all helping voluntary, we don't get anything except the satisfaction of helping others like you.

    Again, if you want us to help you, give the code so that we can help you.

    Take it, or leave it!
    Can I only post the part of code where I need help?

    *****

    ' Error code:
    On Error GoTo Handler

    Dim text As String
    text = Text1.text
    Dim username As String
    username = Settingsform.Text1.text
    If username = "" Then
    Chatform.Combo1.AddItem "Please fill in a username!"
    Else
    Connectform.Winsock1.SendData username & " says : " & text
    Chatform.Combo1.AddItem username & " " & "says : " & text
    End If
    Text1.text = ""

    ' Error Handler
    Handler:
    Combo1.AddItem "#Error! Please connect first!"

    End Sub
    Last edited by Equx; November 11th, 2009 at 11:03 AM.

  11. #11
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: On error goto....

    Quote Originally Posted by Equx View Post
    OK Ty.
    Here is one example:
    Private Sub Form_Load()
    On Error GoTo Errorhandler
    MsgBox "Hello World!"

    Errorhandler:
    MsgBox "Error!"
    End Sub

    Here when you start up the program both two msgboxes comes up...
    Here is a simple solution to your problem.

    Code:
    Private Sub Form_Load()
    On Error GoTo Errorhandler
    MsgBox "Hello World!"
    Exit Sub
    
    Errorhandler:
    MsgBox "Error!"
    End Sub
    Without Exit Sub, both the message boxes will be shown. You have to tell the program when to execute what piece of code. Exit Sub ensures that the code in the error handler does not get called unless there is an actual error.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center