Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

VB file processing questions

stanclarkstanclark Posts: 5Member
I'm a new VB coder, converting from mainframe COBOL. I have to write a program that reads in mainframe files in one format
and write the data out in a new format.

In COBOL there are record layout structures. I've defined TYPEs for each record layout, incoming and outgoing. The records
are fixed in length but most have filler bytes of spaces filling out each record. The first character in each record indicates
which type of record it is (H for header, D for detail...).

Is there an easy way to read a record, determine which type it is and move the entire record into the corresponding TYPE
for reformating.

Has anyone out there ever written code like this?

Comments

  • lionblionb Posts: 1,688Member ✭✭
    : I'm a new VB coder, converting from mainframe COBOL. I have to write a program that reads in mainframe files in one format
    : and write the data out in a new format.
    :
    : In COBOL there are record layout structures. I've defined TYPEs for each record layout, incoming and outgoing. The records
    : are fixed in length but most have filler bytes of spaces filling out each record. The first character in each record indicates
    : which type of record it is (H for header, D for detail...).
    :
    : Is there an easy way to read a record, determine which type it is and move the entire record into the corresponding TYPE
    : for reformating.
    :
    : Has anyone out there ever written code like this?
    :

    Here is some example

    Private Sub Command1_Click()

    ' Open file

    Open "c: est.txt" For Input As #1

    Do Until EOF(1)

    Line Input #1, NextLine 'read line

    If Left(NextLine, 1) = "H" Then 'check for 'H"
    'do something
    Else
    If Left(NextLine, 1) = "D" Then 'check foer "D"
    'do something else
    End If
    Loop

    Close #1
    End Sub
  • qbjunkie007qbjunkie007 Posts: 29Member
    : : I'm a new VB coder, converting from mainframe COBOL. I have to write a program that reads in mainframe files in one format
    : : and write the data out in a new format.
    : :
    : : In COBOL there are record layout structures. I've defined TYPEs for each record layout, incoming and outgoing. The records
    : : are fixed in length but most have filler bytes of spaces filling out each record. The first character in each record indicates
    : : which type of record it is (H for header, D for detail...).
    : :
    : : Is there an easy way to read a record, determine which type it is and move the entire record into the corresponding TYPE
    : : for reformating.
    : :
    : : Has anyone out there ever written code like this?
    : :
    :
    : Here is some example
    :
    : Private Sub Command1_Click()
    :
    : ' Open file
    :
    : Open "c: est.txt" For Input As #1
    :
    : Do Until EOF(1)
    :
    : Line Input #1, NextLine 'read line
    :
    : If Left(NextLine, 1) = "H" Then 'check for 'H"
    : 'do something
    : Else
    : If Left(NextLine, 1) = "D" Then 'check foer "D"
    : 'do something else
    : End If
    : Loop
    :
    : Close #1
    : End Sub
    :
    This code will only work properly if the file is straight ASCII text. If the files are binary, then they cannot be read that way because all you get is junk. The file would need to be opened for binary, and you would need to know a lot more about the structure of the file in order to get the information properly. I am not an expert at working with binary files, so hopefully someone else can go further.

    David
  • stanclarkstanclark Posts: 5Member
    Thanks for the help.

    The data is not binary so that does make it easier but some of the files, I'm finding out now, aren't all
    the same length. How does the 'NextLine' work? Does it use a end-of-record character to know when to stop reading data?
    I think I know how to deal with these variable lengths as long as I'm sure to get one record at a time.

  • GenjuroGenjuro Posts: 913Member
    : Thanks for the help.
    :
    : The data is not binary so that does make it easier but some of the files, I'm finding out now, aren't all
    : the same length. How does the 'NextLine' work? Does it use a end-of-record character to know when to stop reading data?
    : I think I know how to deal with these variable lengths as long as I'm sure to get one record at a time.
    :

    Yes, it uses ASCII characters 10 and 13 (or just ascii 13?) to check for end of lines.

  • lionblionb Posts: 1,688Member ✭✭
    : : : I'm a new VB coder, converting from mainframe COBOL. I have to write a program that reads in mainframe files in one format
    : : : and write the data out in a new format.
    : : :
    : : : In COBOL there are record layout structures. I've defined TYPEs for each record layout, incoming and outgoing. The records
    : : : are fixed in length but most have filler bytes of spaces filling out each record. The first character in each record indicates
    : : : which type of record it is (H for header, D for detail...).
    : : :
    : : : Is there an easy way to read a record, determine which type it is and move the entire record into the corresponding TYPE
    : : : for reformating.
    : : :
    : : : Has anyone out there ever written code like this?
    : : :
    : :
    : : Here is some example
    : :
    : : Private Sub Command1_Click()
    : :
    : : ' Open file
    : :
    : : Open "c: est.txt" For Input As #1
    : :
    : : Do Until EOF(1)
    : :
    : : Line Input #1, NextLine 'read line
    : :
    : : If Left(NextLine, 1) = "H" Then 'check for 'H"
    : : 'do something
    : : Else
    : : If Left(NextLine, 1) = "D" Then 'check foer "D"
    : : 'do something else
    : : End If
    : : Loop
    : :
    : : Close #1
    : : End Sub
    : :
    : This code will only work properly if the file is straight ASCII text. If the files are binary, then they cannot be read that way because all you get is junk. The file would need to be opened for binary, and you would need to know a lot more about the structure of the file in order to get the information properly. I am not an expert at working with binary files, so hopefully someone else can go further.
    :
    : David
    :
    Working with binary files, which is quite rare for COBOL files, you have to know record length and each variables lengths. At the meantime, the last condition is very familiar for COBOL programmers because working with COBOL files you must know record length and each variables lengths. For example
    COBOL

    10 Name
    12 LastName pic x(20).
    12 FirstName pic x(10).
    12 MidInt pic x.

    Compare VB

    Type of Name
    LastName string *20
    FirstName string*10
    MidInt string*1

  • lionblionb Posts: 1,688Member ✭✭
    : Thanks for the help.
    :
    : The data is not binary so that does make it easier but some of the files, I'm finding out now, aren't all
    : the same length. How does the 'NextLine' work? Does it use a end-of-record character to know when to stop reading data?
    : I think I know how to deal with these variable lengths as long as I'm sure to get one record at a time.
    :
    :
    'NextLine' is just a string. LineInput function recognizes the end of a line when it comes to the carriage return/line feed sequence, it does not include that sequence when it reads the line into the variabl.
Sign In or Register to comment.