Stupid question on syntax

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John

    Stupid question on syntax

    Hi

    I have the following statement and I am getting the 'Expression expected'
    error on the &.

    If Flds(0) = CStr(IIf(Reader .GetString(Read er.GetOrdinal(" AccNam")) Is
    Nothing, "", Reader.GetStrin g(Reader.GetOrd inal("AccNam")) )) AND & _
    Flds(1) = CStr(IIf(Reader .GetString(Read er.GetOrdinal(" AccNam")) Is
    Nothing, "", Reader.GetStrin g(Reader.GetOrd inal("AccNam")) )) then

    Fld is an array of strings.

    How can I fix it?

    Many Thanks

    Regards



  • rowe_newsgroups

    #2
    Re: Stupid question on syntax

    On Aug 15, 9:45 am, "John" <i...@nospam.in fovis.co.ukwrot e:
    Hi
    >
    I have the following statement and I am getting the 'Expression expected'
    error on the &.
    >
    If Flds(0) = CStr(IIf(Reader .GetString(Read er.GetOrdinal(" AccNam")) Is
    Nothing, "", Reader.GetStrin g(Reader.GetOrd inal("AccNam")) )) AND & _
       Flds(1) = CStr(IIf(Reader .GetString(Read er.GetOrdinal(" AccNam"))Is
    Nothing, "", Reader.GetStrin g(Reader.GetOrd inal("AccNam")) )) then
    >
    Fld is an array of strings.
    >
    How can I fix it?
    >
    Many Thanks
    >
    Regards
    Wow.

    I'd say refactor your code so you can understand it first, then the
    error should be obvious.

    Thanks,

    Seth Rowe [MVP]

    Comment

    • John

      #3
      Re: Stupid question on syntax

      If I take out the '& _' and bring it on the same line then it works...so
      something to do with &

      Thanks

      Regards

      "rowe_newsgroup s" <rowe_email@yah oo.comwrote in message
      news:d3a346f0-b783-49a0-be4c-af32141e8882@e3 9g2000hsf.googl egroups.com...
      On Aug 15, 9:45 am, "John" <i...@nospam.in fovis.co.ukwrot e:
      Hi
      >
      I have the following statement and I am getting the 'Expression expected'
      error on the &.
      >
      If Flds(0) = CStr(IIf(Reader .GetString(Read er.GetOrdinal(" AccNam")) Is
      Nothing, "", Reader.GetStrin g(Reader.GetOrd inal("AccNam")) )) AND & _
      Flds(1) = CStr(IIf(Reader .GetString(Read er.GetOrdinal(" AccNam")) Is
      Nothing, "", Reader.GetStrin g(Reader.GetOrd inal("AccNam")) )) then
      >
      Fld is an array of strings.
      >
      How can I fix it?
      >
      Many Thanks
      >
      Regards
      Wow.

      I'd say refactor your code so you can understand it first, then the
      error should be obvious.

      Thanks,

      Seth Rowe [MVP]



      Comment

      • \(O\)enone

        #4
        Re: Stupid question on syntax

        John wrote:
        If I take out the '& _' and bring it on the same line then it
        works...so something to do with &
        Looks to me like you just need to remove the "&".

        The line continuation sequence is just " _" (space, underscore) at the end
        of the line, no ampersand is required.

        But I do have to agree with Seth, that code is pretty hard to read!

        --

        (O)enone


        Comment

        • Ken Halter

          #5
          Re: Stupid question on syntax

          "John" <info@nospam.in fovis.co.ukwrot e in message
          news:OYMrMQu$IH A.1184@TK2MSFTN GP04.phx.gbl...
          If I take out the '& _' and bring it on the same line then it works...so
          something to do with &
          Yeah... I'd say 'AND & Flds(1)' wouldn't be valid in any language.


          Comment

          • Herfried K. Wagner [MVP]

            #6
            Re: Stupid question on syntax

            "John" <info@nospam.in fovis.co.ukschr ieb:
            If I take out the '& _' and bring it on the same line then it works...so
            something to do with &
            '&' is VB's string concatenation operator. '_' is used to indicate that a
            statement is broken up to the text line. If I understand your code snippet
            correctly, just remove the '&' operator.

            --
            M S Herfried K. Wagner
            M V P <URL:http://dotnet.mvps.org/>
            V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

            Comment

            • Bill McCarthy

              #7
              Re: Stupid question on syntax

              Hi John,

              If you are using VB 2008, you should use If(.....) rather than IIf(.....)


              "John" <info@nospam.in fovis.co.ukwrot e in message
              news:emRml0t$IH A.2060@TK2MSFTN GP05.phx.gbl...
              Hi
              >
              I have the following statement and I am getting the 'Expression expected'
              error on the &.
              >
              If Flds(0) = CStr(IIf(Reader .GetString(Read er.GetOrdinal(" AccNam")) Is
              Nothing, "", Reader.GetStrin g(Reader.GetOrd inal("AccNam")) )) AND & _
              Flds(1) = CStr(IIf(Reader .GetString(Read er.GetOrdinal(" AccNam")) Is
              Nothing, "", Reader.GetStrin g(Reader.GetOrd inal("AccNam")) )) then
              >
              Fld is an array of strings.
              >
              How can I fix it?
              >
              Many Thanks
              >
              Regards
              >
              >
              >

              Comment

              • Cor Ligthert[MVP]

                #8
                Re: Stupid question on syntax

                John,

                My answer is the same as from Seth.

                Why are you obfuscation your code for yourself?

                It gives you not any benefit to set it in one line, beside obfuscating (only
                the readable version), the dll will stay the same.

                Cor

                "John" <info@nospam.in fovis.co.ukschr eef in bericht
                news:OYMrMQu$IH A.1184@TK2MSFTN GP04.phx.gbl...
                If I take out the '& _' and bring it on the same line then it works...so
                something to do with &
                >
                Thanks
                >
                Regards
                >
                "rowe_newsgroup s" <rowe_email@yah oo.comwrote in message
                news:d3a346f0-b783-49a0-be4c-af32141e8882@e3 9g2000hsf.googl egroups.com...
                On Aug 15, 9:45 am, "John" <i...@nospam.in fovis.co.ukwrot e:
                >Hi
                >>
                >I have the following statement and I am getting the 'Expression expected'
                >error on the &.
                >>
                >If Flds(0) = CStr(IIf(Reader .GetString(Read er.GetOrdinal(" AccNam")) Is
                >Nothing, "", Reader.GetStrin g(Reader.GetOrd inal("AccNam")) )) AND & _
                >Flds(1) = CStr(IIf(Reader .GetString(Read er.GetOrdinal(" AccNam")) Is
                >Nothing, "", Reader.GetStrin g(Reader.GetOrd inal("AccNam")) )) then
                >>
                >Fld is an array of strings.
                >>
                >How can I fix it?
                >>
                >Many Thanks
                >>
                >Regards
                >
                Wow.
                >
                I'd say refactor your code so you can understand it first, then the
                error should be obvious.
                >
                Thanks,
                >
                Seth Rowe [MVP]

                >

                Comment

                Working...