Solved

Pascal 6 byte Real to VB

Posted on 2000-03-04
6
1,371 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:PsychoKiller
Comment Utility
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
Comment Utility
>>> 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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now