VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Simple routine to convert an ASCII file to an EBCDIC file.

by Mike Parker (2 Submissions)
Category: Files/File Controls/Input/Output
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Fri 14th September 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Simple routine to convert an ASCII file to an EBCDIC file.

Rate Simple routine to convert an ASCII file to an EBCDIC file.



'------------------------------------------------------------------------------------------------------------------------------
'  Sub         ConvertFile
'
'  Inputs:     None
'
'  Returns:    Nothing
'
'  Comments:   Perform the following steps:
'              1.  Open the file to be converted
'              2.  Open the file to store the converted data
'              3.  Read 1 line at a time of the input file
'              4.  Convert each character and add it to a string
'              5.  Write the string to the output file
'
'              The converted file will be sent to the IBM.  Since the IBM prefers only capital letters, we convert the
'              characters of the input file to upper case before doing the conversion.
'------------------------------------------------------------------------------------------------------------------------------

   Dim intFileNum As Integer        'Used for opening the input file
   Dim intFile2 As Integer          'Used for opening the output file
   Dim strInput As String           'String to hold the data read from the input file
   Dim strOutput As String          'String to hold the data written to the output file
   Dim i As Integer                 'Used as a counter

   intFileNum = FreeFile
   Open "c:\ftpibm.txt" For Input As #intFileNum
   intFile2 = FreeFile
   Open "c:\ftpibm.ebc" For Output As #intFile2
   Do While Not EOF(intFileNum)
      Input #intFileNum, strInput
      For i = 1 To Len(strInput)
         strOutput = strOutput & Chr(intConvert(Asc(UCase$(Mid$(strInput, i, 1)))))
      Next
      Print #intFile2, strOutput
   Loop
   Close #intFileNum
   Close #intFile2

End Sub

Public Function intConvert(intChar As Integer)
'------------------------------------------------------------------------------------------------------------------------------
'  Function    intConvert
'
'  Inputs:     intChar - the Ascii value of a character being passed
'
'  Returns:    the equivalent EBCDIC value
'
'  Comments:   EBCDIC is the character set used by IBM.  Not all ASCII characters are in EBCDIC (e.g. a comma).
'------------------------------------------------------------------------------------------------------------------------------

   Select Case intChar
      Case 32: intConvert = 64
      Case 33: intConvert = 90
      Case 34: intConvert = 127
      Case 35: intConvert = 123
      Case 36: intConvert = 91
      Case 37: intConvert = 108
      Case 39: intConvert = 125
      Case 40: intConvert = 77
      Case 41: intConvert = 93
      Case 42: intConvert = 92
      Case 43: intConvert = 78
      Case 44: intConvert = 94
      Case 45: intConvert = 96
      Case 46: intConvert = 75
      Case 47: intConvert = 97
      Case 48 To 57: intConvert = intChar + 192
      Case 58: intConvert = 122
      Case 59: intConvert = 94
      Case 60: intConvert = 76
      Case 61: intConvert = 126
      Case 62: intConvert = 110
      Case 63: intConvert = 111
      Case 64: intConvert = 124
      Case 65 To 73: intConvert = intChar + 128
      Case 74 To 82: intConvert = intChar + 135
      Case 83 To 90: intConvert = intChar + 143
      Case 91: intConvert = 192
      Case 92: intConvert = 121
      Case 93: intConvert = 208
      Case 95: intConvert = 109
      Case 96: intConvert = 95
      Case 97 To 105: intConvert = intChar + 32
      Case 106 To 114: intConvert = intChar + 39
      Case 115 To 122: intConvert = intChar + 47
      Case 123: intConvert = 192
      Case 124: intConvert = 79
      Case 125: intConvert = 208
      Case 126: intConvert = 161
   End Select

End Function


Download this snippet    Add to My Saved Code

Simple routine to convert an ASCII file to an EBCDIC file. Comments

No comments have been posted about Simple routine to convert an ASCII file to an EBCDIC file.. Why not be the first to post a comment about Simple routine to convert an ASCII file to an EBCDIC file..

Post your comment

Subject:
Message:
0/1000 characters