Home  |  Index  |  Dotnet4all Snippets  |  Submit resources
About  |  Mail us  
Dotnet4all Logo
Reading Binary Coded Decimal in VB2003.net (Thursday, January 06, 2005)
 

Found the following interesting discussion in the Newsgroups:

Reading Binary Coded Decimal in VB2003.net
by:jeff M via .NET 247

I need to read a file created on a MVS. The file format is Binary Coded Decimal or BCD for short. I have used ftp to bring the file down from the mainframe to my windows pc in binary mode. My problem is if the character value on the MVS is ?C2? or ?B? in EBCDIC I get the following value in ?15? in Hex on the PC. What I want is ?C2?, where am I going wrong?

I have Visual Basic 2003.net for this project.

Please go easy on me as I?m new to VB and all of my experience to date has been programming on MVS and Unix systems.
Private Sub OpenAndProcessFile(ByVal sInputFileName As String)
Dim FileStream As System.IO.FileStream = New System.IO.FileStream(sInputFileName, _
IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.Read)
Dim StreamIn As System.IO.StreamReader = New System.IO.StreamReader(FileStream)
Dim tmp As Int16
Dim bHigh, bLow As Byte
Static first_time_through As Boolean = True
Dim count As Int16 = 0
While (StreamIn.Peek > -1) And (count < 110) ?try the first 110
count += 1
tmp = StreamIn.Read
Extract_Bits(tmp, bHigh, bLow, first_time_through)
If count = 10 Then
MsgBox("header")
MTXDisplay.AppendText(Chr(13) + Chr(10))
ElseIf ((count - 10) Mod 252) = 0 Then
MsgBox("Record")
MTXDisplay.AppendText(Chr(13) + Chr(10))
ElseIf (count > 2026) Then
count = 0
End If
End While
MsgBox("out of Loop")
StreamIn.Close()
FileStream.Close()
End Sub

Private Sub Extract_Bits(ByVal ByteIn As Int16, ByRef bHigh As Byte, ByRef bLow As Byte, _
ByRef first_time_through As Boolean)
bHigh = (ByteIn And &HF0) \ 16
bLow = (ByteIn And &HF)
If (first_time_through) Then
MTXDisplay.Text = Hex(bHigh) + Hex(bLow) ?Clear text
first_time_through = False
Else
MTXDisplay.AppendText(Hex(bHigh) + Hex(bLow + 48))
End If
End Sub
--------------------------------
From: jeff M

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>NCHfoc6XtUSaaHYHrLgrGA==</Id>


 Reply:
by:Cor Ligthert

 Hi Jeff,

I never did that with VB.net, however I found this page,

http://support.microsoft.com/default.aspx?scid=kb;en-us;216399

I think that that can help you?

Cor


 Reply:
by:duck_thunder@msn.com (Jeff)

 
I looked that page over and was unable to locate it in any of the
namespaces. I have done some further reading and it looks like it
could have something to do with one of the code pages. An example
would be :
Dim StreamIn As System.IO.StreamReader = New
System.IO.StreamReader(FileStream,
System.Text.Encoding.GetEncoding("ASCII"))

My problem is I can't seem to locate the correct one. Is their any
other way to read a file that would read only the binary value without
some type of conversion?(code page) or is their a extended ASCII code
page.

Any ideas or thoughts would help.

Thanks


 Reply:
by:Cor Ligthert

 Hi Jeff,

In my opinion you should not encode it at all before this routine, just read
the data, copy the code from the page in your program (where you translate
the old VB6 code to VB.net, however when I see it is almost only deleting
the $'s.

And than try,

Cor



Posted by Xander Zelders



 
Previous Posts
    - VB.Net
    - Help with Structure conversion to VB.NET
    - Populating cboBox using txtFile
    - Information about (un)plugging USB device
    - How to run a form in vb dot net with the form name...
    - Setting Form position
    - Problems Starting a VB windows Service
    - adapter Wizard
    - How to Insert recprd from datagrid to a table?
    - Datareader -how can I know "no of records" return ...

Archives
    - 08/01/2004 - 08/08/2004
    - 08/08/2004 - 08/15/2004
    - 08/15/2004 - 08/22/2004
    - 08/22/2004 - 08/29/2004
    - 08/29/2004 - 09/05/2004
    - 09/05/2004 - 09/12/2004
    - 09/12/2004 - 09/19/2004
    - 09/19/2004 - 09/26/2004
    - 09/26/2004 - 10/03/2004
    - 10/03/2004 - 10/10/2004
    - 01/02/2005 - 01/09/2005
    - 01/09/2005 - 01/16/2005
    - 01/30/2005 - 02/06/2005
    - 01/01/2006 - 01/08/2006


Disclaimer & Terms of Use  | DotNet4All.Com concept & © 2004 - 2007 by  Zelders²  - Holland