Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Problem with If Then Else End If block in Visual Studio 2008 code editor

Problem with If Then Else End If block in Visual Studio 2008 code editor

Scheduled Pinned Locked Moved Visual Basic
csharpvisual-studioregexhelp
10 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mnemonic69
    wrote on last edited by
    #1

    I have this block of code in the code behind of a VB.NET web site: If (row.HasVersion(version)) Then retVal += String.Format( _ "Version: {0} Value: {1} <br />", _ version, row(columnName, version)) Else retVal += String.Format( _ "Version: {0} does not exist.<br />", version) End If Visual studio keeps reporting that 'Else' must be preceded by a matching 'If' or 'Else If' and 'End If' must be preceded by a matching 'If', but THEY DO all match!

    L D 2 Replies Last reply
    0
    • M mnemonic69

      I have this block of code in the code behind of a VB.NET web site: If (row.HasVersion(version)) Then retVal += String.Format( _ "Version: {0} Value: {1} <br />", _ version, row(columnName, version)) Else retVal += String.Format( _ "Version: {0} does not exist.<br />", version) End If Visual studio keeps reporting that 'Else' must be preceded by a matching 'If' or 'Else If' and 'End If' must be preceded by a matching 'If', but THEY DO all match!

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      mnemonic69 wrote:

      If (row.HasVersion(version)) Then retVal += String.Format( _

      Statements are separated by an NewLine in Visual Basic. Put an enter before the "then" keyword, and it should work :)

      I are Troll :suss:

      D D 2 Replies Last reply
      0
      • M mnemonic69

        I have this block of code in the code behind of a VB.NET web site: If (row.HasVersion(version)) Then retVal += String.Format( _ "Version: {0} Value: {1} <br />", _ version, row(columnName, version)) Else retVal += String.Format( _ "Version: {0} does not exist.<br />", version) End If Visual studio keeps reporting that 'Else' must be preceded by a matching 'If' or 'Else If' and 'End If' must be preceded by a matching 'If', but THEY DO all match!

        D Offline
        D Offline
        DaveAuld
        wrote on last edited by
        #3

        Its difficult to see the formatting you have used (stick the code in a pre block). There should be nothing immediately after the Then on the same line. Move the retVal += onto a new line.

        Dave Don't forget to rate messages!
        Find Me On: Web|Facebook|Twitter|LinkedIn
        Waving? dave.m.auld[at]googlewave.com

        1 Reply Last reply
        0
        • L Lost User

          mnemonic69 wrote:

          If (row.HasVersion(version)) Then retVal += String.Format( _

          Statements are separated by an NewLine in Visual Basic. Put an enter before the "then" keyword, and it should work :)

          I are Troll :suss:

          D Offline
          D Offline
          DaveAuld
          wrote on last edited by
          #4

          Eddy Vluggen wrote:

          Put an enter before after the "then"

          FTFY :)

          Dave Don't forget to rate messages!
          Find Me On: Web|Facebook|Twitter|LinkedIn
          Waving? dave.m.auld[at]googlewave.com

          M L 2 Replies Last reply
          0
          • D DaveAuld

            Eddy Vluggen wrote:

            Put an enter before after the "then"

            FTFY :)

            Dave Don't forget to rate messages!
            Find Me On: Web|Facebook|Twitter|LinkedIn
            Waving? dave.m.auld[at]googlewave.com

            M Offline
            M Offline
            mnemonic69
            wrote on last edited by
            #5

            Thanks Dave, problem sorted! I feel a right dummy now lol, - I'm a C# programmer and I'm only having to learn this damn new language because my college degree course uses VB

            D 1 Reply Last reply
            0
            • D DaveAuld

              Eddy Vluggen wrote:

              Put an enter before after the "then"

              FTFY :)

              Dave Don't forget to rate messages!
              Find Me On: Web|Facebook|Twitter|LinkedIn
              Waving? dave.m.auld[at]googlewave.com

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              That was a quick fix! Well spotted :thumbsup:

              I are Troll :suss:

              1 Reply Last reply
              0
              • L Lost User

                mnemonic69 wrote:

                If (row.HasVersion(version)) Then retVal += String.Format( _

                Statements are separated by an NewLine in Visual Basic. Put an enter before the "then" keyword, and it should work :)

                I are Troll :suss:

                D Offline
                D Offline
                Dave Kreskowiak
                wrote on last edited by
                #7

                Thankfully, this will no longer be a problem in VS2010.

                A guide to posting questions on CodeProject[^]
                Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                     2006, 2007, 2008
                But no longer in 2009...

                G 1 Reply Last reply
                0
                • M mnemonic69

                  Thanks Dave, problem sorted! I feel a right dummy now lol, - I'm a C# programmer and I'm only having to learn this damn new language because my college degree course uses VB

                  D Offline
                  D Offline
                  DaveAuld
                  wrote on last edited by
                  #8

                  I know the feeling! My degree course is all Java.......i am forever getting VB and Java syntax mixed up! And we have to use NetBeans and i am so used to Visual Studio.

                  Dave Don't forget to rate messages!
                  Find Me On: Web|Facebook|Twitter|LinkedIn
                  Waving? dave.m.auld[at]googlewave.com

                  1 Reply Last reply
                  0
                  • D Dave Kreskowiak

                    Thankfully, this will no longer be a problem in VS2010.

                    A guide to posting questions on CodeProject[^]
                    Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                         2006, 2007, 2008
                    But no longer in 2009...

                    G Offline
                    G Offline
                    Gideon Engelberth
                    wrote on last edited by
                    #9

                    I'm not sure where you get that idea. In VB a line in the form:

                    If condition Then statement

                    is a self-contained, single statement If that does not have a matching End If I have not heard that this will change in VB2010. What I have heard is that in some cases, you will not need an _ to extend a statement to a second line, but this is kind of the reverse issue.

                    D 1 Reply Last reply
                    0
                    • G Gideon Engelberth

                      I'm not sure where you get that idea. In VB a line in the form:

                      If condition Then statement

                      is a self-contained, single statement If that does not have a matching End If I have not heard that this will change in VB2010. What I have heard is that in some cases, you will not need an _ to extend a statement to a second line, but this is kind of the reverse issue.

                      D Offline
                      D Offline
                      Dave Kreskowiak
                      wrote on last edited by
                      #10

                      I screwed up. I was talking about the "_" character. I've always hated it. And, if using properly formatted code, it'll be eliminated in most cases it's used now. Hell, after playing with the Beta's and RC, it's gone in about 99% of my use cases.

                      A guide to posting questions on CodeProject[^]
                      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                           2006, 2007, 2008
                      But no longer in 2009...

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups