[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Pascal 6 byte Real to VB

Posted on 2000-03-04
6
Medium Priority
?
1,442 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: 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

Technology Partners: 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

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…
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…
Suggested Courses

656 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