Solved

Pascal 6 byte Real to VB

Posted on 2000-03-04
6
1,390 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
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…

856 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