Today I opened a visual basic project which has several lines that declare some strings, which contain comma separated data. I amended one of the strings, rebuilt and closed the project. When I came to test it, there was an error. When I looked at the code, I discovered that the strings on lines after the one I had amended had also changed - they had spaces inserted after the commas.
Has anyone seen normal strings incorrectly having formatting applied by the IDE in visual studio 2015?
It seems like the string is being formatted as if it were code. I would suspect this has something to do with String Interpolation, though these are legacy projects that do not use it.
Edit, FWIW the code is similar to this, I've renamed the fields and headings to try keep it short.
fullColumnMappingsBuilder.Append(",field1,field2,field3,field4,field5,field6,field7,field8,field9,field10")
fullColumnHeadingsBuilder.Append(",heading1,heading2,heading3,heading4,heading5,heading6,heading7,heading8,heading9,heading10")
If clientCode = "ML" Then
fullColumnMappingsBuilder.Append(",mlField")
fullColumnHeadingsBuilder.Append(",mlHeading")
End If
defaultColumnMappingsBuilder.Append(",morefields1,morefields2,morefields3,morefields4")
defaultColumnHeadingsBuilder.Append(",moreHeadings1,moreHeadings2,moreHeadings3,moreHeadings4")
My edit was to simply add in field11 and heading11, and save. But the code ended up looking like this:
fullColumnMappingsBuilder.Append(",field1,field2,field3,field4,field5,field6,field7,field8,field9,field10,field11")
fullColumnHeadingsBuilder.Append(",heading1,heading2,heading3,heading4,heading5,heading6,heading7,heading8,heading9,heading10,heading11")
If clientCode = "ML" Then
fullColumnMappingsBuilder.Append(", mlField")
fullColumnHeadingsBuilder.Append(", mlHeading")
End If
defaultColumnMappingsBuilder.Append(", morefields1, morefields2, morefields3, morefields4")
defaultColumnHeadingsBuilder.Append(", moreHeadings1, moreHeadings2, moreHeadings3, moreHeadings4")
The problem is that the IDE has inserted spaces after the commas on lines that I did not edit.
Well, I think I know how I did it. If you start with something like this:
Public Class Class1
Sub New()
Dim string1 As String = "Hello there world asdfj asldfkja sad "
Dim string2 As String = "some code like words dim private as object sub"
End Sub
End Class
I think I must have taken the first double quotes character off the declaration of string1, and then moved the position of the text cursor to a different line. In previous versions of visual studio, the IDE would have marked the first line as being in error.
Now we have multi-line strings, it thinks you have a multi-line string running from the quotes at the end of the first line up to string2 As String", and that the following text is code, and so it gets changed (in this case the keywords are capitalized).
Dim string2 As String = "some code Like words Dim Private As Object Sub"
I'll just have to be more careful when editing strings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With