-
- VBForums
- Visual Basic
- Visual Basic .NET
- [RESOLVED] vb.net 2019 line continuation character question
-
Dec 3rd, 2019,12:58 AM #1 Thread Starter Lively Member [RESOLVED] vb.net 2019 line continuation character question I have always used an underscore with a preceding space "_" to shorten lines. In VB.NET 2019, after typing the underscore and return key, after I click away VB.net deletes the underscore and adds a bunch of spaces at the beginning of the new line. Is this normal behavior? -
Dec 3rd, 2019,01:34 AM #2 Re: vb.net 2019 line continuation character question Yes it is. The line continuation character has been virtually obsolete since about 2008 I think. If you break a line in a place that could never be a legitimate end of line, e.g. after a dot or other operator, then the compiler will automatically detect that and treat it as a single expression. -
Dec 3rd, 2019,02:33 AM #3 Thread Starter Lively Member Re: vb.net 2019 line continuation character question Ok, thanks! So you're saying I can just make a space and press enter, and don't have to physically type the underscore? -
Dec 3rd, 2019,06:43 AM #4 Re: vb.net 2019 line continuation character question Originally Posted by ZviT Ok, thanks! So you're saying I can just make a space and press enter, and don't have to physically type the underscore? Don't wait...give it a try Please remember next time...elections matter! -
Dec 3rd, 2019,08:14 AM #5 Re: vb.net 2019 line continuation character question Originally Posted by ZviT Ok, thanks! So you're saying I can just make a space and press enter, and don't have to physically type the underscore? What would the space be for? -
Dec 3rd, 2019,08:41 AM #6 Thread Starter Lively Member Re: vb.net 2019 line continuation character question Originally Posted by jmcilhinney What would the space be for? Because the instructions from Microsoft from 2015 say "The underscore must be immediately preceded by a space and immediately followed by a line terminator (carriage return)" Which is also why I don't know why you say that the underscore hasn't been needed since 2008. -
Dec 3rd, 2019,08:42 AM #7 Thread Starter Lively Member Re: vb.net 2019 line continuation character question I don't know why this post duplicated itself. I don't see an option to delete. -
Dec 3rd, 2019,08:45 AM #8 Re: vb.net 2019 line continuation character question Please remember next time...elections matter! -
Dec 3rd, 2019,08:55 AM #9 Hyperactive Member Re: vb.net 2019 line continuation character question Originally Posted by jmcilhinney Yes it is. The line continuation character has been virtually obsolete since about 2008 I think. If you break a line in a place that could never be a legitimate end of line, e.g. after a dot or other operator, then the compiler will automatically detect that and treat it as a single expression. Yes, that was one of the earliest things I discovered about VB.net (although I think it must not be just the compiler, since it detects this situation 'as one types'). It's even clever enough to understand that there are some situations (in which it couldn't tell whether or not it was a 'legitimate end-of-line') in which the line continuation character is not obsolete (and is still needed, as well as 'allowed', in some situations), as in ... Code: txt3.Text = "This is a bit of text ... " _ & "this is a bit more of it" ... the point being that, without the underscore, VS would not know whether or not it had got to a true 'end-of-line'. One probably shouldn't do that, since one obviously could (probably should) avoid this situation by putting the concatenation operator at the end of the first line (rather than the start of the second one) (in which case VS will remove the continuation character, even if one types it), but perhaps not everyone will think of that (or realise that there 'is a difference'). The one silly thing one should avoid doing (and similar is true of many/most languages) is trying to force a physical new line (of code) within a quoted string. If one does that, VS realises that it is not a 'legitimate end-of-line' (no balanced quote marks), hence that it is a two-line statement, but includes the underscore character (and usually some spaces at the start of the second line of text, due to 'indents' in the code) as part of the string ... Code: txt3.Text = "This is a bit of text ... _ and this is a bit more of it" Kind Regards, John -
Dec 3rd, 2019,09:04 AM #10 Re: vb.net 2019 line continuation character question Originally Posted by ZviT Because the instructions from Microsoft from 2015 say "The underscore must be immediately preceded by a space and immediately followed by a line terminator (carriage return)" Which is also why I don't know why you say that the underscore hasn't been needed since 2008. The highlighted Note section of that page (just under the bit about the space) says to look at the "Implicit line continuation" section of this page: https://docs.microsoft.com/en-us/dot...e-continuation ...which gives lots of different examples without the underscore or space (all of the examples are variations of the kind of thing that jmcilhinney referred to in post #2). -
Dec 3rd, 2019,05:19 PM #11 Re: vb.net 2019 line continuation character question Originally Posted by ZviT Because the instructions from Microsoft from 2015 say "The underscore must be immediately preceded by a space and immediately followed by a line terminator (carriage return)" Which is also why I don't know why you say that the underscore hasn't been needed since 2008. If the underscore must be preceded by a space and there's no underscore, what would the space be for? The space was needed so that it was clear that the underscore wasn't part of the line of code. If there's no more need for the underscore then there's no more need for a space to clarify the meaning of the underscore. In actual fact, I would expect that, if you did include a space and no underscore, the IDE would just remove the space. That is, if automatic formatting (pretty listing) is enabled. -
Dec 3rd, 2019,09:57 PM #12 Thread Starter Lively Member Re: vb.net 2019 line continuation character question Originally Posted by jmcilhinney If the underscore must be preceded by a space and there's no underscore, what would the space be for? The space was needed so that it was clear that the underscore wasn't part of the line of code. If there's no more need for the underscore then there's no more need for a space to clarify the meaning of the underscore. In actual fact, I would expect that, if you did include a space and no underscore, the IDE would just remove the space. That is, if automatic formatting (pretty listing) is enabled. Yes, it's clear now. Also, after reading further down the page as @si_the_geek mentioned, cleared things up. Thank you guys for all the help! -
- VBForums
- Visual Basic
- Visual Basic .NET
- [RESOLVED] vb.net 2019 line continuation character question
Posting Permissions - You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
- BB code is On
- Smilies are On
- [IMG] code is On
- [VIDEO] code is On
- HTML code is Off
Forum Rules | Click Here to Expand Forum to Full Width |
0 Response to "What is a Ine Continuation in Visual Basic"
Post a Comment