Solved

Pascal 6 byte Real to VB

Posted on 2000-03-04
6
1,387 Views
Last Modified: 2008-03-04
I need to convert files created with Pascal to something I can read with Visual Basic.  How can I convert the 6 byte REAL datatype in PASCAL to the Double type of Visual Basic?
0
Comment
Question by:PsychoKiller
  • 3
  • 3
6 Comments
 

Accepted Solution

by:
wireman earned 500 total points
ID: 2585228
This may not be the exact answer you were looking for, but I don't know the range of the Real datatype in Pascal...
So I have included a quick sample of converting a collection of bytes (6) to a VB-long datatype.

Please let me know what the range of values is for Pascal-Real datatype.

<snip>
Option Explicit
'sample form by Arty Clark

Private Declare Sub CopyMemory Lib "KERNEL32" Alias "RtlMoveMemory" (hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)

Public Function Sample( _
        Optional B0 As Byte = 0, Optional B1 As Byte = 0, _
        Optional B2 As Byte = 0, Optional B3 As Byte = 0, _
        Optional B4 As Byte = 0, Optional B5 As Byte = 0) As Long
       
    Dim lba(7)      As Byte 'large byte array
    Dim lVar        As Long 'output var
   
    'load an array of bytes with data from a file
    lba(0) = B0:    lba(1) = B1:    lba(2) = B2:    lba(3) = B3
    lba(4) = B4:    lba(5) = B5:    lba(6) = 0:     lba(7) = 0
   
    'now copy the data from the array members into the var
    Call CopyMemory(lVar, lba(0), 8)
   
    'assign the function value
    Sample = lVar
    Exit Function
errorhandler:
    Exit Function
End Function

Private Sub Form_Load()
    Debug.Print Sample(255, 0, 0, 0, 0, 0)  'would translate to 255
    Debug.Print Sample(0, 1, 0, 0, 0, 0)    'would translate to 256
    Debug.Print Sample(1, 1, 0, 0, 0, 0)    'would translate to 257
    Debug.Print Sample(2, 1, 0, 0, 0, 0)    'would translate to 258
End Sub
0
 

Author Comment

by:PsychoKiller
ID: 2585272
Wireman,

Thanks, but this is not what I needed.  The alogrithm is much more complicated than just moving the values into a long variable.  The sign bit, exponent, and mantissa need to be parsed from the 6 bytes of the Pascal real data type, and I am not sure what is where.

Thanks for responing anyway.

Karl
0
 

Expert Comment

by:wireman
ID: 2585300
That is what I need to know to customize the function for you.

If you still program in Pascal, find out:
Upper limit
Lower Limit
Max number of decimal places
Max number of whole number places
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

Author Comment

by:PsychoKiller
ID: 2587504
Wireman,

I don't do Pascal.  VB and VC++ are my area's of expertise. (Oh yeah, IBM 370 Assembler, RPG II, COBOL, and REXX, but that was about 15 years ago :-)  Anyway, here are a few samples created by the Pascal program.  I would up the points on this for you but I don't know how.

Thanks,
Karl

Hex value    = Decimal Value
810000000000 = 1000
81A69BC42000 = 1001
814C37894100 = 1002

0
 

Author Comment

by:PsychoKiller
ID: 2602555
>>> How do you convert the 6 byte real values from Pascal to the double precision type of VB? <<<

Thanks for all the help guys.  I got it.  If you are intersted in the solution, drop me an e-mail.  It was a real bitch because VB has no bit shift operators, and multiplying by multiples of 2 caused overflow exceptions.  I will spend another few moments (when I get around to it) to clean it up a little more, but it works.

Thanks again,
Karl
0
 

Expert Comment

by:wireman
ID: 2606810
VB doesn't have any bit shift operations, but you can use and/or with API to do those operations too.

here are some usefule API for memory operations

' Note: VarPtr was incorporated into the language at VB5.
#If Win32 Then
   Private Declare Sub CopyMem Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
   Private Declare Function VarPtr Lib "VB40032.Dll" (pAny As Any) As Long
#Else
   Private Declare Sub CopyMem Lib "kernel" Alias "hmemcpy" (Destination As Any, Source As Any, ByVal Length As Long)
   Private Declare Function VarPtr Lib "VB40016.Dll" (pAny As Any) As Long
#End If

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Declare Sub FillMemory Lib "kernel32" Alias "RtlFillMemory" (Destination As Any, ByVal Length As Long, ByVal Fill As Long)
Private Declare Sub ZeroMemory Lib "kernel32" Alias "RtlZeroMemory" (Destination As Any, ByVal Length As Long)

Private Declare Function EqualMemory Lib "ntdll" Alias "RtlCompareMemory" (Destination As Any, Source As Any, ByVal Length As Long) As Long



0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question