Results 1 to 6 of 6

Thread: help with reading from a comma delimited file

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    2

    help with reading from a comma delimited file

    ok heres the issue I'm attempting to read from a comma delimited file, the values are put into a structure (employeerecords) i want to know how i can access the separate sections of this structure i will provide my code so far, i apologize for the comments I'm making sure i know whats going on, I'm new to this, the code currently just dumps the whole file into a textbox, i would like to be able to access and manipulate the individual fields but i am at a genuine loss.
    Thanks
    Code:
    'structure for the array, the values are declared in the order they appear more below.
        Structure EmployeeRecords
            Dim surname As String  'as first field before comma is the surname 
            Dim firstname As String 'as second field after surname is firstname 
            Dim nationalininsurance As String 'etc.
            Dim taxcode As String
            Dim hoursworked As Integer
            Dim rateofpay As Integer
        End Structure
        
    Dim employeearray As EmployeeRecords ' stating that employeearray is now the structure employee records 
        Dim currentline As String
        ' this is the name i have decided to give to the variable where the line which is taken from the file is stored 
        'to be later used to input said line into a text box 
    
        Private Sub inputfile()
            FileOpen(1, "C:\Users\Alex\Documents\Visual Studio 2008\Employee Doc.txt", OpenMode.Input)
            Do While Not EOF(1)
                currentline = LineInput(1)
                TextBox1.Text = TextBox1.Text & currentline & vbNewLine
            Loop
        End Sub

  2. #2
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: help with reading from a comma delimited file

    You posted in the wrong forum. This is for VB6 and your code is .Net.

    Secondly, if you have multiple employee records in the file (in new lines) you need to create an array of the EmployeeRecord structure type.

    In a structure, you access the properties using . like with all other objects.

    Dim employeerec As EmployeeRecords
    MsgBox employeerec.surname

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    2

    Re: help with reading from a comma delimited file

    Thank you so much gah i can't believe i didn't think of that and i'm terribly sorry for posting in the wrong area, i'm new here .net, i will remember thank you for your advice

  4. #4
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: help with reading from a comma delimited file

    No problem. I'll tell one of the Mods to move the thread to the .Net forum.

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: help with reading from a comma delimited file

    Moved To VB.NET

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: help with reading from a comma delimited file

    Get rid of that VB6-esque file I/O for a start. Generally you should use types from the System.IO namespace for file I/O. In this case though, I'd suggest using the TextFieldParser, which is specifically designed for reading delimited and fixed-width text files. The MSDN documentation provides code examples.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width