Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    May 2002
    Location
    Jerusalem, Israel
    Posts
    187
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Increment a Number With Decimal Point

    My Access 2010 database has a field called "versionno", which tracks the version number of the document. The following code is in the onclick event of a button that will increase the version number by one (if the version number field is empty, it inserts 1.0).

    Private Sub plusone_Click()
    If Not IsNull(Me.versionno) Then
    Me.versionno = Me.versionno + 1
    Else
    'If IsNull(Me.versionno) Then
    Me.versionno.Value = "1.0"
    End If
    End Sub

    This works fine, but I want the version number to always have a decimal point, followed by a zero (to be consistent with our numbering system elsewhere). The code above will change 1.0 to 2, although I want it displayed as 2.0. The field format is set to 1 decimal place, but it still doesn't add the .0 after the number.

    Can I force the .0 to be added programatically, or is there another method of always ensuring that the version number is followed by a .0?

    Thanks for your help,

    JoeK

  2. #2
    Administrator
    Join Date
    Jun 2010
    Location
    Portugal
    Posts
    12,519
    Thanks
    152
    Thanked 1,398 Times in 1,221 Posts
    I would risk saying that you probably should not be representing that by a single number. Most common representations use an "independent" number for each part of the version number in use. For example, my IE 9 version number is 9.0.8112.16421. This is not representable through a single number. If you just want to keep a major version and a minor version number (as in 1.0, 1.1, etc), use two numbers, one for the major version, another for the minor version. When displaying the version number, you just treat each part as a string, e.g.: versionNumber = majorVersion & "." & minorVersion.

  3. #3
    2 Star Lounger
    Join Date
    May 2002
    Location
    Jerusalem, Israel
    Posts
    187
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for your reply. In this database I'm only tracking released versions, so there is no need for a minor version number. That being so, I realize that I don't actually NEED the .0, but it just looks better on reports and whatnot.

    In any case, my intellectual curiosity about how to achieve this is piqued :-)

    Thanks,

    JoeK

  4. #4
    Administrator
    Join Date
    Jun 2010
    Location
    Portugal
    Posts
    12,519
    Thanks
    152
    Thanked 1,398 Times in 1,221 Posts
    To do what you want, you can simply use the FormatNumber function. For example, FormatNumber(2,1) will display 2.0. FormatNumber(1,2) will display 1.00. The function can use other parameters, but Access will help you with that, as you build the statement using the function.

  5. #5
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    Presumably the version is a number field in a table.

    Set the format property of the field to 0.0 and it will always display a decimal point.

    formatnumber.gif
    I tend to do what you do. I treat the decimal point version of the number as a minor version and the whole number as a major version.

    So I might go 1.0, 1.1, 1.2 then 2.0, 2.1, 2.2 ,2.3 then 3.0 etc. But I can understand why more major projects might well need a more elaborate system.
    Regards
    John



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
  •