Replace and/or Translate Legacy File Characters in

Good Morning! It was an easy night. My wife had band practice and the kids were gone (my oldest to work and the youngest to camp) so I had a lot of time to myself. Which sometimes can be nice too. :). Anyway, yes my youngest called again from camp and the nurse ended up taking the phone away because she was acting somewhat hysterical when she found out her mom wasn’t coming to get her. It also appears my dad,  who is at the same camp as the nature guide, told them not to allow her to leave camp. I am going to have to address that with him. I don’t disagree with not letting her leave but I didn’t like him stepping in like that. Oh well. So she will be coming home Friday and not a moment too soon from her opinion I am sure.

So today’s topic. This code was actually written years ago. Those of you who are involved with reading files from legacy systems such as AIX, UNIX will want to pay attention in particular. Also those of you who use the Dart Telnet components will find this interesting. Those of you who use IBM 3151 emulation (or other similar) on your systems, I found a way to translate the upper function keys. That could be the subject of a future post or if you want let me know you want that information and i will correspond with you directly.

Anyway, I had to find a way to translate what those systems do in a file to make a line break happen, a tab and etc. Usually though those files when brought to the Windows side would represent these markers as a simple square. It would do that because to Windows these characters had no meaning. But the actual information was there. It was just a matter of determining what was in it and what it meant. So here is what I came up with. This is assumes you are reading a single line of text from a flat file. If you need to, do a loop and and run this function. Or read the whole thing for all I care. 🙂

Public Sub TelnetDisplayData(ByVal showme As String)
            ‘Convert any \n\r to \r\n
            showme = showme.Replace(Chr(13) + Chr(10), vbCrLf)
            ‘Convert all naked \n to \r\n (2-step process)
            showme = showme.Replace(vbCrLf, Chr(10))
            showme = showme.Replace(Chr(10), vbCrLf)
            ‘Replace all Tabs with spaces
            showme = showme.Replace(Chr(9), "     ")
            ‘Remove <esc>[0m (all attributes off)
            showme = showme.Replace(Chr(27) + "[0m", "")
            ‘Remove <esc>[m (all attributes off)
            showme = showme.Replace(Chr(27) + "[m", "")
            TextBox1.Text = TextBox1.Text & showme ‘
        End Sub


  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: