question

RandallBreneman-6024 avatar image
0 Votes"
RandallBreneman-6024 asked DewayneBasnett-7583 commented

Visual Studio 2022 VB.Net not recognizing colon for multiple statements on one line.

I am upgrading VB.NET projects from VS2015 to VS2022. Many lines use the colon for multiple statements on a single line, like

 Try : If MyDb IsNot Nothing Then MyDb.Dispose() Catch : End Try

This was, and should still be, acceptable per

Statements in Visual Basic | Microsoft Docs where it states, "You can have multiple statements on a single line separated by the colon (:) character."

Instead, I am getting errors like, "'Try' must end with a matching 'End Try'." I couldn't find any setting for this in Tools | Options. Am I missing something?



vs-generaldotnet-visual-basic
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

An opinion. This is, and always be, a terrible practice.

0 Votes 0 ·

1 Answer

LesHay-2099 avatar image
0 Votes"
LesHay-2099 answered RandallBreneman-6024 commented

Hi
This works OK

     Dim MyDb As String = "Freddy"
     Try : If MyDb IsNot Nothing Then : MyDb = "Brian" : End If : Catch ex As Exception : End Try
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@LesHay-2099 thanks. My goal was to avoid modifying all those code files but that just the price of upgrading sometimes. Lol, the older version was at least somewhat pretty. Newer code just won't do that anymore.

0 Votes 0 ·