Results 1 to 5 of 5

Thread: Binary literal formating

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2010
    Posts
    117

    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.

  2. #2
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,754

    Re: Binary literal formating

    Post the code showing the usage of this please.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2010
    Posts
    117

    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.

  4. #4
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    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...

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2010
    Posts
    117

    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
  •  



Click Here to Expand Forum to Full Width