O'Reilly logo

VB.NET Language in a Nutshell, Second Edition by Steven Roman PhD, Paul Lomax, Ron Petrusha

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

GoTo Statement

Syntax

GoTo label
label (required)

Type: String literal

A subroutine name

Description

Passes execution to a specified line within a procedure

Rules at a Glance

label must be a line label

Programming Tips and Gotchas

  • GoTo can branch only to lines within the procedure where it appears.

  • It is not permitted to branch from outside a Try...Catch...Finally block to a point inside the Catch or Finally block.

  • It is also not permitted to branch from within the Catch or Finally block to a label outside the block.

  • The GoTo statement is most commonly used with the On Error statement to direct control to an error-handling routine.

  • GoTo is frequently used to control program flow within a procedure, a technique that often produces highly unreadable “spaghetti code.” Accordingly, great care should be taken when using the GoTo statement.

VB.NET/VB 6 Differences

In VB 6, label could be either a line number or a label. In VB.NET, label can be only a label.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required