Results 1 to 6 of 6
  1. #1
    2 Star Lounger
    Join Date
    Jun 2004
    Location
    L, Schleswig-Holstein, Germany
    Posts
    184
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Continuation Character usage (2003)

    pre tags removed by HansV because they caused horrible horizontal scrolling

    Hello people,

    I have hard times using the continuation character "_" and I can't find any real reference to it in the help files nor the knowledge base.
    My code looks like this:

    lblReturnAddress.Caption = "Return to: " & nz(dLookup("[FirstName] & ' ' & [LastName] & ', ' & [Address] " & _
    " & ', ' & [ZIP] & ' ' & [City] & ', ' & [Country]", "tblPersonnel", "PID=" & dLookup("PID", "joinPersonnelPosition", "Year=" & Forms!frmYear!cboreg)), "")

    The first contination character works, but now I want one AFTER "PID=". I tried ..."PID=" & _ <newline>, ..."PID=" " & _ <newline> - nothing seems to work. I guess it has to do with the quotes around PID, but I just dont get it why I cant use the contination character anywhere. Please lighten me up on this one.

    Thanks
    Dennis

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Continuation Character usage (2003)

    It should work if you type a space and an underscore after "PID=" or after the following &. For example:

    lblReturnAddress.Caption = "Return to: " & Nz(dLookup("[FirstName] & ' ' & [LastName] & ', ' & [Address] " & _
    " & ', ' & [ZIP] & ' ' & [City] & ', ' & [Country]", "tblPersonnel", "PID=" & _
    dLookup("PID", "joinPersonnelPosition", "Year=" & Forms!frmYear!cboreg)), "")

  3. #3
    2 Star Lounger
    Join Date
    Jun 2004
    Location
    L, Schleswig-Holstein, Germany
    Posts
    184
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Continuation Character usage (2003)

    "& _" works. THanks.

    Is there any rules like when to ONLY use the _ and when with the & character?

    Dennis

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Continuation Character usage (2003)

    The line continuation character _ is used to break a long instruction into two (or more) lines. The _ *must* be preceded by a space.
    The & character is used to concatenate string values. You can use it in combination with _ to break up long strings. If your instruction doesn't involve strings, there is no need to use & toegether with _.

    Examples:
    <code>
    ThisVariable = MyFunction(ThatVariable, _
    OtherVariable)

    MyString = "The quick brown fox jumps " & _
    "over the lazy dog"
    </code>
    The latter example can also be written as
    <code>
    MyString = "The quick brown fox jumps " _
    & "over the lazy dog"
    </code>
    Which one you use is just a matter of personal preference.

  5. #5
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Continuation Character usage (2003)

    FYI - Buried deep in the MSDN, amongst all the VB.NET and VB 2005 documentation, you can still find archaic, "legacy" VB 6.0 (aka VB98) documentation. Some links below:

    VB 6.0 Code Basics

    This article notes, "You can't follow a line-continuation character with a comment on the same line. There are also some limitations as to where the line-continuation character can be used." These "limitations" do not appear to articulated, though the MSDN VB 2005 version of this article How to: Break and Combine Statements in Code states: "Some limitations exist as to where the line-continuation character can be used, such as in the middle of an argument name. You can break an argument list with the line-continuation character, but the individual names of the arguments must remain intact." This applies to "legacy" VB as well.

    VB 6.0 Code Limitations

    The latter article notes, "A single line of code can consist of up to 1023 bytes. Up to 256 blank spaces can precede the actual text on a single line, and no more than twenty-four line-continuation characters ( _) can be included in a single logical line." Generally, code limitations in VB6 would also apply to VBA as used by Access & other MS Office apps. NOTE: The "Legacy" MSDN apparently doesn't work too good if not using IE as browser - the left-hand hierarchy does not display properly. Recommend view VB6 articles in recent version of IE. The "new" MSDN (MSDN2) does display properly in non-IE (Firefox) browser.

    HTH

  6. #6
    2 Star Lounger
    Join Date
    Jun 2004
    Location
    L, Schleswig-Holstein, Germany
    Posts
    184
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Continuation Character usage (2003)

    Thanks to both of you, this really explains all!

    Dennis

Posting Permissions

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