Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting ASCII to EBCDIC 1

Status
Not open for further replies.

meckeard

Programmer
Aug 17, 2001
619
US
Hi guys,

I am in need of some help in regards to converting ASCII to EBCDIC in a VB 6 app.

The following article returns a results but it doesn't seem to match any EBCDIC or ASCII table that I find:


Has anyone done something like this before?

As far as a third party tool, I can't use one. This must be done in-house :(

Thanks!
 
The reverse conversion (EBCDIC to ASCII) was recently discussed in detail in thread222-1288126.
 
My first post in that thread illustrates doing it both ways.
 
OK, dumb question...how to I verify that it's working correctly? I'm looking at conversaion tables and my results don't match. It's quite possible I'm not truly understanding what my results should be though.

Thanks,
Mark
 
One of the problems is that there are various different EBCDIC - so you have to use the right code page for the particular EBCDIC you are targetting. The one I use in the example is IBM's
 
As you can see, quite a lot of EBCDICs (but quite why I was using IBM's Greek EBCDIC for my example now escapes me ...)
 
What are you getting the data from? A mainframe? If so look into what single byte character set translation table you are using and it should tell you the code page number.

Swi
 
Maybe more detail is in order. Sorry, I try hard to keep my posts to a minimum so I don't innundate people with too much info.

I have hundreds of records in a text file that needs to be converted to EBCDIC so that a vendor can import it in to their system. Unfortunately, details are sketchy at this point, so I'm just trying to get a head start.

Here is a sample record from my text file:

"5555-5555",37082," 18193"," ",0.00,10108290," 15"," 18193","20061117"

My goal is to write a VB app that opens this file, reads each line, converts it to the EBCDIC equivalent and writes it to a new file. Another process picks up this new file an hour later and sends it to the vendor for importing.

Hopefully that sheds some light on what I'm processing and what I'm trying to achieve.

Thanks,
Mark
 
You will need to find out from the vendor what code page that they would like the EBCDIC data in.

Swi
 
They are telling me IBM.

With that said, can anyone tell me the best way to test my code?

Thanks,
Mark
 
IBM it is. The vendor has confirmed this.

Using my string above and the code provided by strongm, let's assume I pass in my first value of "5555-5555". As it stands now, my result is:

????<square - no key to represent this>????

This doesn't seem right since I can randomly change a number within this string and still get the same results.

Here is the code that I'm using:

Private Function etoa(strSource As String) As String
Dim buffer() As Byte
Dim buffer2() As Byte
Dim lLenb As Long

ReDim buffer(Len(strSource) - 1)
ReDim buffer2(LenB(strSource) - 1)
lLenb = LenB(strSource) - 1
buffer = StrConv(strSource, vbFromUnicode)
MultiByteToWideChar CP_EBCDIC, 0&, buffer(0), -1, buffer2(0), lLenb
etoa = buffer2
End Function

Thanks,
Mark

 
>my result is:


You have to bear in mind that VB is ASCII based - so when it tries to display an EBCDIC character it actually tries to display an ASCII character.

This can be confusing because the ASCII character is NOT the ASCII character originally represented before the conversion to EBCDIC.

Blame IBM for all this rubbish ...
 
Let me start by saying thanks to you all for your help and insight.

So I guess I'm still left not knowing if my code works. Can I tell once it's written to a text file? That's what I'll be writing to and what will get sent to the vendor.

Thanks,
Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top