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

Discussion in 'ASP .Net' started by Andreas Klemt, Jan 14, 2004.

  1. 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
    Andreas Klemt, Jan 14, 2004
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:%23WeEI$...
    > 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
    >
    >
    Cowboy \(Gregory A. Beamer\), Jan 14, 2004
    #2
    1. Advertising

  3. 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

    --

    "Andreas Klemt" <> a écrit dans le message de
    news:%23WeEI$...
    > 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
    >
    >
    Patrice Scribe, Jan 14, 2004
    #3
  4. Andreas Klemt

    Brian W Guest

    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)" <> wrote in
    message news:%...
    > 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" <> wrote in message
    > news:%23WeEI$...
    > > 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
    > >
    > >

    >
    >
    Brian W, Jan 14, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. M P
    Replies:
    6
    Views:
    548
    Joe Fallon
    Aug 7, 2004
  2. Stewart
    Replies:
    1
    Views:
    523
    Ken Cox [Microsoft MVP]
    Feb 24, 2006
  3. =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=

    Help on table align on left of page vs left hanging indent

    =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=, Jul 10, 2007, in forum: XML
    Replies:
    2
    Views:
    1,001
    =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=
    Jul 16, 2007
  4. pc
    Replies:
    2
    Views:
    1,312
    crisgoogle
    Jun 8, 2011
  5. lawrence
    Replies:
    13
    Views:
    297
    Thomas 'PointedEars' Lahn
    Sep 4, 2004
Loading...

Share This Page