Read 6 bytes floating from a file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Miguel Pinheiro
    New Member
    • Mar 2011
    • 1

    Read 6 bytes floating from a file

    Hello,

    I have an old fashion Database with several random access files and I need to import the data to a new Sql Server dababase the data.

    There are tables with 6 Bytes floating numbers fields and we have no Number data type with that length in VB.

    I tried and tried and... and can't find.

    I found this code in the ERP folder, is AlphaBasic. It use an envoirement namend A-shell from Microsabio .

    Code:
    MAP1 OOCUM'4750		! Cabecalhos de Documentos
      MAP2 SIT'4750,B,1	! Ocupado (Sim/Nao)
      MAP2 KEY2'4750		! Chave Secundaria
       MAP3 FCA'4750,S,4  	! Cliente/Fornecedor/Armazem
       MAP3 KEY'4750		! Chave Primaria
         MAP4 SERIE'4750,S,1	! Serie
         MAP4 TIPDOC'4750,S,1	! Tipo
         MAP4 NDOC'4750,S,5		! Numero
      MAP2 ARMZ'4750,S,3	! Armazem
      MAP2 NRINT'4750,B,3	! Numero Interno
      MAP2 SER'ORIG'4750,S,1	! Documento Origem
      MAP2 NUM'ORIG'4750,B,2	! Documento Origem
      MAP2 DATORIG'4750,S,8	! Data Documento Origem	
      MAP2 DATREC'4750,S,8	! Data Computador/Prazo 
      MAP2 DATDOC'4750,S,8	! Data Documento
    
    * * * Fields I Can't convert:
    
      MAP2 VALDES'4750,F,6	! Valor Desconto
      MAP2 VALPOR'4750,F,6	! Valor Portes
      MAP2 VALSEG'4750,F,6	! Valor Seguro
      MAP2 VALIMP'4750,F,6	! Valor IVA
      MAP2 VALDOC'4750,F,6	! Valor Iliquido
    
    * * * 
    
      MAP2 TRANSP'4750,S,1	! Codigo Transporte
      MAP2 FLAGEMI'4750,S,1	! Emitido (Sim/Nao)
      MAP2 COD'PAG'4750,B,1	! Codigo Condicoes Pagamento
      MAP2 VENDOR'4750,S,3    	! Vendedor
      MAP2 FNDOC'4750,S,6	! Documento Referencia
      MAP2 DATFACT'4750,S,8	! Data Documento Referencia
      MAP2 NMOV'4750,B,1	! Linhas Documento
    
    * * *
    
      MAP2 PAGO'4750,F,6	! 
    
    * * *
      MAP2 RESP'4750,B,1	! Linhas Satisfeitas
      MAP2 MOVANUL'4750,B,1	! Linhas Anuladas
      MAP2 ANULADO'4750,S,1	! Anulado (Sim/Nao)
      MAP2 FILLER'4750,S,23
    The Fields I Can't convert are Floating with 6 Bytes

    Thank you,

    Miguel
    Last edited by debasisdas; Mar 6 '11, 05:49 AM.
  • R MacDonald
    New Member
    • Mar 2011
    • 24

    #2
    Hello, Miguel,

    I have not done this in VB, but you may be able to use the BitConverter class to accomplish what you need. You will need to know how the 6-byte floating values are structured. This includes which byte is the most significant and which the least, and also which bits within the 48 bit array comprise the mantissa and which bits make up the exponent.

    You will need to move the 6 bytes (in the correct order) into a 64 bit Integer and then shift the exponent bits into the proper location for a Double precision floating value. You will need to extend the sign bit of the mantissa into the bits that have been "vacated" by shifting the exponent. You will also need to extend the sign bit of the exponent. Then use the Int64BitsToDoub le method of the BitConverter class to get a double precision floating value that VB can use.

    You might find the following reference helpful as you work on this project:



    Cheers,
    Randy
    Last edited by R MacDonald; Mar 8 '11, 08:52 PM. Reason: Forgot to mention extending the sign bit of the exponent.

    Comment

    Working...