For what use LABELS (left of the code) in Visual Basic Code?

A

Andreas Klemt

Hello,

for what is the LABEL good when programming in visual studio like this:

Sub xxxx

Label1: xxxx
xxxx
xxx

Label2: xxxxx

End Sub

For what do I need or can use "Label1" and "Label2" in my Visual Studio Code
?

Thanks for any help an answers in advance!
Andreas
 
C

Cowboy \(Gregory A. Beamer\)

Labels are a bit of a leftover from VB 6, IMO. The idea is being able to use
Goto statements to go to a specific label. For example:

Public Sub TestGoto()

Dim DataSetNumber As Integer = 1

RetrieveData:
Dim ds As DataSet = GetData(DataSetNumber )

For x = 1 to 100

'Assume if there is a "duck" then you go to retrieve data again
If ds.Tables[0].Rows[1]["Animal"] = "duck"
DataSetNumber += 1
Goto RetrieveData
End If
Next x

End Sub

This is a very bad example, as I can see no real use for labels any more,
but it illustrates that you can use it for flow control. In general, you
will find that proper architecture will not lead you to solutions where you
use labels.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

**********************************************************************
Think Outside the Box!
**********************************************************************
 
P

Patrice Scribe

A label can be used as a target for the "goto" or "gosub" statement (which
are generally avoided). It's perhaps also considered sometimes by some
people as a way to "document" things (?).

My personal opinion is that this is basically useless.

Patrice
 
B

Brian W

At the risk of revealing my age... It's actually a hold over from a lot
further than VB6.

Can anyone say QuickBASIC (GW-BASIC if you include line numbers in that)
?!?!


Regards
Brian W



Cowboy (Gregory A. Beamer) said:
Labels are a bit of a leftover from VB 6, IMO. The idea is being able to use
Goto statements to go to a specific label. For example:

Public Sub TestGoto()

Dim DataSetNumber As Integer = 1

RetrieveData:
Dim ds As DataSet = GetData(DataSetNumber )

For x = 1 to 100

'Assume if there is a "duck" then you go to retrieve data again
If ds.Tables[0].Rows[1]["Animal"] = "duck"
DataSetNumber += 1
Goto RetrieveData
End If
Next x

End Sub

This is a very bad example, as I can see no real use for labels any more,
but it illustrates that you can use it for flow control. In general, you
will find that proper architecture will not lead you to solutions where you
use labels.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

**********************************************************************
Think Outside the Box!
**********************************************************************
Andreas Klemt said:
Hello,

for what is the LABEL good when programming in visual studio like this:

Sub xxxx

Label1: xxxx
xxxx
xxx

Label2: xxxxx

End Sub

For what do I need or can use "Label1" and "Label2" in my Visual Studio Code
?

Thanks for any help an answers in advance!
Andreas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top