Problem with If Then Else End If block in Visual Studio 2008 code editor
-
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!
-
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!
-
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!
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 theretVal +=
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 -
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:
-
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
-
-
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:
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... -
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
-
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...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.
-
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.
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...