Solved

Pascal 6 byte Real to VB

Posted on 2000-03-04
6
1,401 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

749 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