4 Replies - 320 Views - Last Post: 30 June 2013 - 04:10 PM Rate Topic: -----

#1 UbadahJafry  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 28-June 13

On Error Goto always executes

Posted 30 June 2013 - 11:09 AM

I have with Problem with
On Error Goto Start

 SaveFile.ShowDialog()
        b = SaveFile.FileName

        If Not System.IO.File.Exists(b) = True Then
            Dim file As System.IO.FileStream
            file = System.IO.File.Create(b)
            file.Close()
        End If
        My.Computer.FileSystem.WriteAllText(b, RichText.Text, False)
        TabControl1.SelectedTab.Text = b
Start:
        MsgBox(Err.Description)

This Works on Error with problem is that if there is no error But still it excute the messagebox

Is This A Good Question/Topic? 0
  • +

Replies To: On Error Goto always executes

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,496
  • Joined: 23-August 08

Re: On Error Goto always executes

Posted 30 June 2013 - 11:11 AM

Proper code tags:

:code:
Was This Post Helpful? 0
  • +
  • -

#3 UbadahJafry  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 28-June 13

Re: On Error Goto always executes

Posted 30 June 2013 - 11:12 AM

Sorry but code is
 SaveFile.ShowDialog()
        b = SaveFile.FileName

        If Not System.IO.File.Exists(B)/> = True Then
            Dim file As System.IO.FileStream
            file = System.IO.File.Create(B)/>
            file.Close()
        End If
        My.Computer.FileSystem.WriteAllText(b, RichText.Text, False)
        TabControl1.SelectedTab.Text = b
Start:
        MsgBox(Err.Description)


Was This Post Helpful? 0
  • +
  • -

#4 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: On Error Goto always executes

Posted 30 June 2013 - 12:35 PM

View PostUbadahJafry, on 30 June 2013 - 12:09 PM, said:

This Works on Error with problem is that if there is no error But still it excute the messagebox

There's nothing magical about a label. "Start:" is a label. When your program finishes executing line 10, it will then execute the next line, which is line 12. The only thin your "On Error" line does is to skip any lines between a line giving an error and line 11.

On Error is an older, VB way of doing things. You should use a Try/Catch block.

This post has been edited by lar3ry: 30 June 2013 - 12:35 PM

Was This Post Helpful? 0
  • +
  • -

#5 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3371
  • View blog
  • Posts: 11,420
  • Joined: 12-December 12

Re: On Error Goto always executes

Posted 30 June 2013 - 04:10 PM

So, you need Exit Sub before your Start label, otherwise the code following the label is always executed.

Even so, you should be using Try..Catch as lar3ry suggested (and MessageBox.Show).

BTW I've changed your topic-title. Please try and use more descriptive titles than just "Error".

This post has been edited by andrewsw: 30 June 2013 - 04:13 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1