• Continuation Character usage (2003)

    Author
    Topic
    #431846

    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=” & _ , …”PID=” ” & _ – 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

    Viewing 1 reply thread
    Author
    Replies
    • #1011705

      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)), “”)

      • #1011708

        “& _” works. THanks.

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

        Dennis

        • #1011712

          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:

          ThisVariable = MyFunction(ThatVariable, _
          OtherVariable)

          MyString = "The quick brown fox jumps " & _
          "over the lazy dog"

          The latter example can also be written as

          MyString = "The quick brown fox jumps " _
          & "over the lazy dog"

          Which one you use is just a matter of personal preference.

    • #1011744

      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

    Viewing 1 reply thread
    Reply To: Continuation Character usage (2003)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: