locked
32 bit Access to 16 bit legacy application RRS feed

  • Question

  • Thank you for taking the time to read my question.

    I am sending data from MS Access to a legacy application. My understanding from the vendor is that it does "16-bit rounding". For example, when I send a list of items that has a total weight of 1000, the legacy system sees it as 999.9999.

    Is there a way that I can send data from MS Access 2016 to my legacy system in 16-bit instead of 32 or 64 bit?

    Both MS Access and the legacy applications are on Windows Server 2016.

    Thanks!

    Example, these equal 1000, but when I send it to the legacy application the application sees it as 999.9999:

    32.504
    19.647
    9.823
    9.823
    5.889
    4.912
    3.733
    3.443
    2.947
    1.965
    1.178
    0.982
    0.824
    0.598
    0.524
    0.329
    0.286
    0.266
    0.193
    0.082
    0.052

    • Edited by mbrad Tuesday, April 21, 2020 8:54 PM
    Tuesday, April 21, 2020 8:52 PM

Answers

  • No, that is not really possible.

    Humans think of fractional numbers differently than binary computers. Much has been written about this topic (should not be hard to find) and the bottom line is: this is normal and the apps and users should account for it.

    Btw, they add up to 100, not 1000.


    -Tom. Microsoft Access MVP

    • Marked as answer by mbrad Wednesday, April 22, 2020 1:17 PM
    Tuesday, April 21, 2020 10:40 PM
  • Your question is not clear.

    That data sent "as is" will be read by the other system. So, it can do whatever the heck it wants.

    The data you have can be sent or read or added up. If you add up the above numbers then you get 100.

    You get this result even if you use a 16 bit system now. 

    You can use a variable type of single in your VBA - this will produce the SAME results if you were say running 16 DOS computer, and declared a data type of single in Access.

    Remember, computers don't hold real (floating) numbers to an exact amount. 

    You can see this rounding EVEN if you fire up the LATEST 64 bit version of Access.

    Note this code in VBA (and you can EVEN run this code in Excel, and you get the SAME results!!!).

    VBA - Access - use single variable type:

    Public Sub TestAdd() Dim MyNumber As Single Dim I As Integer For I = 1 To 10 MyNumber = MyNumber + 1.01 Debug.Print MyNumber Next I End Sub Here is the output of the above: 1.01 2.02 3.03 4.04 5.05 6.06 7.070001 8.080001 9.090001 10.1

    You can see that even Access as adding just a few numbers is already making a mistake.

    However, the numbers you are outputting do add up to 100, and they will on a 16 bit system.

    If I fire up my old copy of DOS 5.0, and write this code (QuickBasic was part of dos 5), we have this code:

       DIM intF          AS INTEGER
       DIM strF          AS STRING
       DIM strOneLine    AS STRING
                
       
       DIM mytotal       AS SINGLE
       DIM OneValue      AS SINGLE
       DIM strOneValue   AS STRING
                
       
       mytotal = 0
          
       strF = "c:\TEST1\D.TXT"
          
       intF = FREEFILE
       OPEN strF FOR INPUT AS intF
             
       DO WHILE EOF(intF) = False
             ' get one line of data
            LINE INPUT #intF, strOneValue
            OneValue = VAL(strOneValue)
            mytotal = mytotal + OneValue
            PRINT mytotal, OneValue, strOneValue
       LOOP
       CLOSE
       PRINT "-------------------"
                                                 
       PRINT "Total = "
       PRINT mytotal
       

    The above outputs the same as Access. Same result!!!

    So you can use 16 bit format numbers. Whatever your code in Access does to output that data should do its math with single variable types. The result should be the same. As above shows?

    Running Access x64 bits on a x64 bit machine? 

    We get a result of 100 as a total.

    And as above shows, running DOS 5.0 and old QuickBasic (actually QBASIC), we see the same result.

    So the numbers as outputted are correct. I suspect that target system WILL in fact result in a value of 100, but you want the total to be 99.999. Your output is the issue here. 

    If you can do your calculations with VBA "single" variables, then your output should match the 16 bit software unless they are using some different math.

    edit:

    The output of that above code, in DOS 5.0, or the latest version of Access is this:

     32.504        32.504       32.504
     52.151        19.647       19.647
     61.974        9.823        9.823
     71.797        9.823        9.823
     77.686        5.889        5.889
     82.598        4.912        4.912
     86.331        3.733        3.733
     89.774        3.443        3.443
     92.721        2.947        2.947
     94.686        1.965        1.965
     95.864        1.178        1.178
     96.846        0.982        0.982
     97.67         0.824        0.824
     98.268        0.598        0.598
     98.792        0.524        0.524
     99.121        0.329        0.329
     99.40701      0.286        0.286
     99.673        0.266        0.266
     99.866        0.193        0.193
     99.94801      0.082        0.082
     100           0.052        0.052
    -------------------
    Total = 100

    Access VBA code for above:

    Sub MyAddTest()
    
       ' open a text file, read each value, add it up.
       
       Dim intF          As Integer
       Dim strF          As String
       Dim strOneLine    As String
       
       
       Dim mytotal       As Single
       Dim OneValue      As Single
       Dim strOneValue   As String
       
       
       mytotal = 0
       
       strF = "c:\test4\sampledata.txt"
       
       intF = FreeFile
       Open strF For Input As intF
       
       Do While EOF(intF) = False
          ' get one line of data
          Line Input #intF, strOneValue
          OneValue = strOneValue
          mytotal = mytotal + OneValue
          Debug.Print mytotal, OneValue, strOneValue
       Loop
       Close
       Debug.Print "-------------------"
       
       Debug.Print "Total = " & mytotal
       
    
    End Sub

    Regards,

    Albert D. Kallal (Access MVP 2003-2017)

    Edmonton, Alberta Canada




    • Edited by Albert D. Kallal Wednesday, April 22, 2020 2:35 AM
    • Marked as answer by mbrad Wednesday, April 22, 2020 1:20 PM
    Wednesday, April 22, 2020 2:30 AM

All replies

  • No, that is not really possible.

    Humans think of fractional numbers differently than binary computers. Much has been written about this topic (should not be hard to find) and the bottom line is: this is normal and the apps and users should account for it.

    Btw, they add up to 100, not 1000.


    -Tom. Microsoft Access MVP

    • Marked as answer by mbrad Wednesday, April 22, 2020 1:17 PM
    Tuesday, April 21, 2020 10:40 PM
  • Your question is not clear.

    That data sent "as is" will be read by the other system. So, it can do whatever the heck it wants.

    The data you have can be sent or read or added up. If you add up the above numbers then you get 100.

    You get this result even if you use a 16 bit system now. 

    You can use a variable type of single in your VBA - this will produce the SAME results if you were say running 16 DOS computer, and declared a data type of single in Access.

    Remember, computers don't hold real (floating) numbers to an exact amount. 

    You can see this rounding EVEN if you fire up the LATEST 64 bit version of Access.

    Note this code in VBA (and you can EVEN run this code in Excel, and you get the SAME results!!!).

    VBA - Access - use single variable type:

    Public Sub TestAdd() Dim MyNumber As Single Dim I As Integer For I = 1 To 10 MyNumber = MyNumber + 1.01 Debug.Print MyNumber Next I End Sub Here is the output of the above: 1.01 2.02 3.03 4.04 5.05 6.06 7.070001 8.080001 9.090001 10.1

    You can see that even Access as adding just a few numbers is already making a mistake.

    However, the numbers you are outputting do add up to 100, and they will on a 16 bit system.

    If I fire up my old copy of DOS 5.0, and write this code (QuickBasic was part of dos 5), we have this code:

       DIM intF          AS INTEGER
       DIM strF          AS STRING
       DIM strOneLine    AS STRING
                
       
       DIM mytotal       AS SINGLE
       DIM OneValue      AS SINGLE
       DIM strOneValue   AS STRING
                
       
       mytotal = 0
          
       strF = "c:\TEST1\D.TXT"
          
       intF = FREEFILE
       OPEN strF FOR INPUT AS intF
             
       DO WHILE EOF(intF) = False
             ' get one line of data
            LINE INPUT #intF, strOneValue
            OneValue = VAL(strOneValue)
            mytotal = mytotal + OneValue
            PRINT mytotal, OneValue, strOneValue
       LOOP
       CLOSE
       PRINT "-------------------"
                                                 
       PRINT "Total = "
       PRINT mytotal
       

    The above outputs the same as Access. Same result!!!

    So you can use 16 bit format numbers. Whatever your code in Access does to output that data should do its math with single variable types. The result should be the same. As above shows?

    Running Access x64 bits on a x64 bit machine? 

    We get a result of 100 as a total.

    And as above shows, running DOS 5.0 and old QuickBasic (actually QBASIC), we see the same result.

    So the numbers as outputted are correct. I suspect that target system WILL in fact result in a value of 100, but you want the total to be 99.999. Your output is the issue here. 

    If you can do your calculations with VBA "single" variables, then your output should match the 16 bit software unless they are using some different math.

    edit:

    The output of that above code, in DOS 5.0, or the latest version of Access is this:

     32.504        32.504       32.504
     52.151        19.647       19.647
     61.974        9.823        9.823
     71.797        9.823        9.823
     77.686        5.889        5.889
     82.598        4.912        4.912
     86.331        3.733        3.733
     89.774        3.443        3.443
     92.721        2.947        2.947
     94.686        1.965        1.965
     95.864        1.178        1.178
     96.846        0.982        0.982
     97.67         0.824        0.824
     98.268        0.598        0.598
     98.792        0.524        0.524
     99.121        0.329        0.329
     99.40701      0.286        0.286
     99.673        0.266        0.266
     99.866        0.193        0.193
     99.94801      0.082        0.082
     100           0.052        0.052
    -------------------
    Total = 100

    Access VBA code for above:

    Sub MyAddTest()
    
       ' open a text file, read each value, add it up.
       
       Dim intF          As Integer
       Dim strF          As String
       Dim strOneLine    As String
       
       
       Dim mytotal       As Single
       Dim OneValue      As Single
       Dim strOneValue   As String
       
       
       mytotal = 0
       
       strF = "c:\test4\sampledata.txt"
       
       intF = FreeFile
       Open strF For Input As intF
       
       Do While EOF(intF) = False
          ' get one line of data
          Line Input #intF, strOneValue
          OneValue = strOneValue
          mytotal = mytotal + OneValue
          Debug.Print mytotal, OneValue, strOneValue
       Loop
       Close
       Debug.Print "-------------------"
       
       Debug.Print "Total = " & mytotal
       
    
    End Sub

    Regards,

    Albert D. Kallal (Access MVP 2003-2017)

    Edmonton, Alberta Canada




    • Edited by Albert D. Kallal Wednesday, April 22, 2020 2:35 AM
    • Marked as answer by mbrad Wednesday, April 22, 2020 1:20 PM
    Wednesday, April 22, 2020 2:30 AM
  • Hi Tom,

    Thank you for your reply. Helpful once again. :-)

    Thank you also for pointing out they total 100... I copied the wrong column from Excel where I'm tracking my results.

    I hope you and yours are healthy and safe!

    Wednesday, April 22, 2020 1:18 PM
  • Hi Albert,

    Thank you very much for a GREAT response. Thank you also for testing in DOS! Above and beyond.

    Sorry for posting data that added to 100. I copied the wrong column from my Excel sheet where I'm tracking my results.

    I'm sending 1000.0000 to the legacy system but when the legacy system adds up my numbers is gets 999.9999

    325.0400
    196.4700
    98.2300
    98.2300
    58.8900
    49.1200
    37.3300
    34.4300
    29.4700
    19.6500
    11.7800
    9.8200
    8.2400
    5.9800
    5.2400
    3.2900
    2.8600
    2.6600
    1.9300
    0.8200
    0.5200
    1000.0000


    I found it odd that the data I'm sending has precision to 2 decimal places, but when the legacy system adds them up it gets precision to 4 decimal places... more than I'm sending.

    It seems I will just have to live with this.

    I wish you and yours health.

    Thanks

    Wednesday, April 22, 2020 1:25 PM
  • Well, lets run the same code with your new data. With the above routine, all I have to do this cut + paste your data into the document.

    And, wonders of wonders - access ALSO spits out that 999 number.

    So, two things:

    I was correct in my assumptions that using "single" in Access will and should produce the same results as that legacy system. (single data type in access is a 16 bit floating - VERY good chance that older system is using that data size.

    Running that "older" basic in DOS 5.0, also produces the same result.

    And, here is the output from the above sample access VBA:

    3 columns are:

    Running total          floating number          string read by access

     325.04        325.04       325.0400
     521.51        196.47       196.4700
     619.74        98.23        98.2300
     717.97        98.23        98.2300
     776.86        58.89        58.8900
     825.98        49.12        49.1200
     863.31        37.33        37.3300
     897.74        34.43        34.4300
     927.21        29.47        29.4700
     946.86        19.65        19.6500
     958.64        11.78        11.7800
     968.46        9.82         9.8200
     976.7         8.24         8.2400
     982.68        5.98         5.9800
     987.92        5.24         5.2400
     991.21        3.29         3.2900
     994.0699      2.86         2.8600
     996.7299      2.66         2.6600
     998.6599      1.93         1.9300
     999.4799      0.82         0.8200
     999.9999      0.52         0.5200
    -------------------
    Total = 999.9999

    So, in fact, not only can you add up numbers and see/get/show the SAME result, but any other calculations that other program can be re-created in Access, and you get the same results.

    So, yes you can in fact "emulate" the 16 bit system in Access by using a single data type in VBA.

    Edit: it also seems that the numbers you are receiving are "formatted" for output to show 4 decimal places. We could also do that in Access with a format command and again even produce the same outputs.

    Regards,

    Albert D. Kallal  (Access MVP 2003-2017)

    Edmonton, Alberta, Canada


    Sunday, April 26, 2020 3:39 AM