-
Jul 25th, 2019, 05:11 AM
#1
Thread Starter
Lively Member
Binary literal formating
When I use a Format Document feature (Ctrl+K, Ctrl+D), my binary literal gets reformatted so that all the leading zeros are removed. For example, &B0001 becomes &B1. How can this be avoided so that readability is not affected?
Apparently, I have to modify .editorconfig file to prevent such an "optimization", but I cannot find the relevant setting for it.
By the way, it looks like binary literals are not reformatted in C# projects.
-
Jul 25th, 2019, 10:47 AM
#2
Re: Binary literal formating
Post the code showing the usage of this please.
-
Jul 25th, 2019, 06:57 PM
#3
Thread Starter
Lively Member
Re: Binary literal formating
Code:
' Before
Select Case value And &B00111111
Case &B00000100 :
Case &B00010000 :
Case &B00100001 :
End Select
' After
Select Case value And &B111111
Case &B100 :
Case &B10000 :
Case &B100001 :
End Select
Last edited by riov; Jul 25th, 2019 at 11:16 PM.
-
Jul 25th, 2019, 08:14 PM
#4
Re: Binary literal formating
You must have the pretty listing option turned off (Tools:Options:Text Editor>Advanced.Editor Help.Pretty listing (reformatting) of code [ ])
Normally, that is defaulted On, so you would never be able to enter those leading zeros as each line would be reformatted automatically when you move away from the line.
So, you have the Pretty Listing turned off, but then select to do the pretty listing reformatting by selecting from the menu.
I don't know if there is a way to modify the rules of what the pretty Listing reformatting does, other than the obvious things they allow to modify such as indentation levels, smart indentation, etc...
-
Jul 25th, 2019, 11:15 PM
#5
Thread Starter
Lively Member
Re: Binary literal formating
Yes, Pretty listing option is turned off in my VS. I was not aware that it and Format Document do the same thing.
On the further investigation it looks like there is no way to disable this behavior. The best solution for now is the following:
Starting with Visual Basic 15.5, you can also use the underscore character (_) as a leading separator between the prefix and the hexadecimal, binary, or octal digits.
Code:
Dim number As Byte = &H_6A
So, the following line will not get reformatted:
Code:
Dim value = &B_00001001
Last edited by riov; Jul 26th, 2019 at 12:14 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|