Results 1 to 9 of 9

Thread: [RESOLVED] Assembly Version Formatting

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2022
    Posts
    28

    Resolved [RESOLVED] Assembly Version Formatting


    I have a quick question about the Assembly Version Formatting... (referring to lblRev.Text)

    I'm putting together an about screen that has the App information like the version, up time, date, etc.

    I would like for it to format all of the numbers I include (including zeros before the number).

    Here's my code.
    Code:
    ' Add any initialization after the InitializeComponent() call.
            Dim dt As Date = File.GetLastWriteTime(Application.ExecutablePath)
            lblLastdate.Text &= dt.ToString("MMM d, yyyy h:mm tt")
    
            lblRev.Text &= My.Application.Info.Version.ToString
    
            lblLastBoot.Text &= started.ToString("MMM d, yyyy h:mm:ss tt")
            lblCopyRight.Text &= My.Application.Info.Copyright
    My Assembly Version Information is 2.2.2023.0309 (Version 2.2: YYYY:MMDD) is how I am naming the version so that I can keep track of things for my personal info.
    I've included an image of the settings below.

    Name:  AssemblyInfo.jpg
Views: 573
Size:  29.2 KB

    But when it formats it, it removes the zero before the 3 (2.2.2023.309). I know it's not a huge deal, but if I can keep the zero, I'd prefer it. Is there any way to format this so that it keeps the zero or does Visual Studio just remove it?

    Thanks for anyone who can help me with this.

  2. #2
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: Assembly Version Formatting

    You can create a function to do this yourself:-
    Code:
        Private Function FormatVersion(ByVal version As String) As String
    
            Return String.Join(".", From s In version.Split(".").Select(
                                        Function(value, index)
                                            If index = 2 OrElse index = 3 Then Return value.PadLeft(4, "0"c)
    
                                            Return value
                                        End Function))
    
        End Function
    
    Tested with this:-
    Code:
    Debug.WriteLine(FormatVersion("1.2.430.20"))
    Produces this output:-
    Code:
    1.2.0430.0020
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  3. #3
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: Assembly Version Formatting

    Here's a slightly more simplified version:-
    Code:
        Private Function FormatVersion(ByVal version As String) As String
    
            Return String.Join(".", version.Split(".").
                               Select(Function(value, index) If(index = 2 OrElse index = 3, value.PadLeft(4, "0"c), value)))
    
        End Function
    
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Assembly Version Formatting

    The My.Application.Info.Version property is type Version and the Major, Minor, Build and Revision properties of that are type Integer. Numbers don't have leading zeroes, so you have to add them yourself if you want your string representation to contain them, e.g.
    vb.net Code:
    1. Dim v = My.Application.Info.Version
    2. Dim versionText = $"{v.Major}.{v.Minor}.{v.Build}.{v.Revision:0000}"
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Aug 2022
    Posts
    28

    Re: Assembly Version Formatting

    Quote Originally Posted by jmcilhinney View Post
    The My.Application.Info.Version property is type Version and the Major, Minor, Build and Revision properties of that are type Integer. Numbers don't have leading zeroes, so you have to add them yourself if you want your string representation to contain them, e.g.
    vb.net Code:
    1. Dim v = My.Application.Info.Version
    2. Dim versionText = $"{v.Major}.{v.Minor}.{v.Build}.{v.Revision:0000}"
    jmcilhinney,

    Thanks for the help! So here's my new code and it works perfectly how I wanted it to. I'm going to do some other stuff now hahaha! That was brilliant and I appreciate it very much.

    Thanks to everyone else who responded as well. I love this site and everyone who takes the time to reach out and help others in need. Hopefully one day I'll get to the point where I'm helping others as well haha.

    Marking this as [Resolved]

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Aug 2022
    Posts
    28

    Re: Assembly Version Formatting

    Quote Originally Posted by Niya View Post
    You can create a function to do this yourself:-
    Code:
        Private Function FormatVersion(ByVal version As String) As String
    
            Return String.Join(".", From s In version.Split(".").Select(
                                        Function(value, index)
                                            If index = 2 OrElse index = 3 Then Return value.PadLeft(4, "0"c)
    
                                            Return value
                                        End Function))
    
        End Function
    
    Tested with this:-
    Code:
    Debug.WriteLine(FormatVersion("1.2.430.20"))
    Produces this output:-
    Code:
    1.2.0430.0020
    Not exactly what I was looking for, but thanks for reaching out. I do appreciate it.

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Aug 2022
    Posts
    28

    Re: Assembly Version Formatting

    Quote Originally Posted by Niya View Post
    Here's a slightly more simplified version:-
    Code:
        Private Function FormatVersion(ByVal version As String) As String
    
            Return String.Join(".", version.Split(".").
                               Select(Function(value, index) If(index = 2 OrElse index = 3, value.PadLeft(4, "0"c), value)))
    
        End Function
    
    Now this may be something more practical, but jmcilhinney's response is exactly what I was looking for.

    I am going to give your suggestion on this option a try as I may be able to use it for my other application where I'm doing something a bit different. Thank you so much Niya for always looking out on my posts haha you have helped me in the past a great deal!!! So I'm always looking for your replies for sure! Thanks again.

  8. #8
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: [RESOLVED] Assembly Version Formatting

    jmc's solution is better than mine. Use that instead
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

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

    Re: [RESOLVED] Assembly Version Formatting

    Because we did not have a versioning system and are relatively small I used this

    Major - year
    Minor - month
    Build - day
    Revision - a number or 24 hour time
    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

Tags for this Thread

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