Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2007
    Posts
    49

    Unanswered: jump to perticular line in VBA code

    Hi,
    My project is in Ms Access 2002.
    I only want to know ,in Access, is there any function like FLAG or
    Label or Go To.
    I don't know its name properly.
    But in C or C++ we use this function to jump at perticular line in
    code.

    this is just example code is not working.this is just sample to show
    what i want?.


    Quote:
    Originally Posted by
    1 x=some string
    2 for(i=1,j=1;i<10,j<strlen(X);i++,j++)
    3 {
    4 if(i=j)
    5 go to LabelA
    6 else
    7 some code
    8 }
    9 some code
    10
    .
    .
    .
    20 LabelA:
    21 for(k=0;k<10;k++)
    22 {
    23 print("string match");
    24 }


    How can I jump to line 5 to line 20?

  2. #2
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    Its overuse is considered poor coding, but there is:

    GoTo
    Paul

  3. #3
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    I'd prefer this pseudo construct
    Code:
    Dim someFlag As String
    Dim i, j As Integer
    
    someFlag = ""
    j = 6
    
    For i = 1 to 10 Step 1
      If i = j
        someFlag = "label A"
        Exit For
      End If
    Next
    
    If someFlag = "label A"
      MsgBox "good stuff"
      Exif Sub
    End If
    Superior control to GoTo, but requires a bit more nouse. Hopefully this gives a bit of an idea
    George
    Home | Blog

  4. #4
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    or alternatively write your label bit as a function which you can then call when a criteria is met (i.e when i=j)
    George
    Home | Blog

  5. #5
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    I though goto's were supposedly the spawn of the devil and not allowed in serious development languages like C and its imitators and successors. It wa always one of the sneering comments from developers in C that basic isn't a real language as it allows jumps to labels.

    So, having been beaten round the head so many times for using labels in the past (and I've still got the scars to prove it) I'd re-write the code using appropriate control structures so that you never jump to a label (unless you are using error trapping)

    the only construct I'd use which doesn't follow that approach is the exit function/sub statements (say the data caused a validation fail.. I often kick out using that to make it clear that we don't go near this function if the data is invalid. Or exit if statements/ exit loop when the the work id done. but usually on a loop I'd set trip a flag to indicate processign is finished and treat it exactly as if it were a property such
    Code:
    as do while .eof
    in file processing, Id use something like
    Code:
    Do while StayinLoop
    putting labels in risks having the dreaded spaghetti approach and can make the code a lot harder to comprehend. At least thats what sneering C,C++ self styled 'real' developers always told me.

Posting Permissions

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