Results 1 to 10 of 10

Thread: [RESOLVED] Write to a .txt file & some other things....

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Location
    Madison, WI
    Posts
    136

    Resolved [RESOLVED] Write to a .txt file & some other things....

    I am looking for the simplest way to write to a .txt file, that has a seperate header area, subhead area, and single entries. The data needs to pull from tables in a SQL database and from pre defined values.
    Can anyone help?
    Thanks.

  2. #2
    Lively Member Neoharuo's Avatar
    Join Date
    Aug 2005
    Posts
    100

    Re: Write to a .txt file & some other things....

    Can you give us an example of what you are looking for? (Formatting)
    "I aim to misbehave."
    Captain Mal Reynolds

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Location
    Madison, WI
    Posts
    136

    Re: Write to a .txt file & some other things....

    Here is a sample of what I am going after:

    101 07500005113918269450458081136A094101MARTIN & KINGSLY BANK ABS SERVICES INC
    5200ABS SERVICES INC 1391830098PPDLOAN PYMT 050808050808 1075000050000001
    62729147959214000202 0000049243NMB00001 SCHMIDT, SARA A. RA0075000050000001
    820000113100920707970000599142600000599142601391826998 075000050000001
    9000001000114000011310092070797000200914260000059914260
    9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
    9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
    9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
    9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
    9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999

  4. #4
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Cochin, India
    Posts
    350

    Re: Write to a .txt file & some other things....

    Please expain what this sample means. which is head, subhead etc

  5. #5
    Frenzied Member Zakary's Avatar
    Join Date
    Mar 2005
    Location
    Canada, Quebec, Montreal
    Posts
    1,654

    Re: Write to a .txt file & some other things....

    Quote Originally Posted by callydata
    I am looking for the simplest way to write to a .txt file, that has a seperate header area, subhead area, and single entries. The data needs to pull from tables in a SQL database and from pre defined values.
    Can anyone help?
    Thanks.
    Well a good way to do so is by usage for IO.StreamWriter.

    Peudo code:
    Code:
    Open File using IOStreamWriter
    
    WriteFileHeader()
    
    Do Loop for all record
          ' Write This product header
          Do Loop Until The Same product
              ' Write Product Detail from the current record
          Loop
          ' Write This product footer
    Loop
    WriteFileFooter()
    
    Close IO.StreamWriter
    Hope it help!

    PS
    I use Product just as exemple I can't be anything else
    Using VS 2010 on Fw4.0

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Location
    Madison, WI
    Posts
    136

    Re: Write to a .txt file & some other things....

    Header:
    101 07500005113918269450458081136A094101MARTIN & KINGSLY BANK ABS SERVICES INC

    SubHead:
    5200ABS SERVICES INC 1391830098PPDLOAN PYMT 050808050808 1075000050000001

    Entry:
    62729147959214000202 0000049243NMB00001 SCHMIDT, SARA A. RA0075000050000001

    Footer:
    9000001000114000011310092070797000200914260000059914260
    9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
    9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
    9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
    9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
    9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999

    So some of this content will be constant, and other parts of the content will be pulled from a table.
    Any ideas are appreciated!

  7. #7
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Write to a .txt file & some other things....

    Simple....

    VB Code:
    1. Dim oFile As System.IO.File
    2. Dim oWrite As System.IO.StreamWriter
    3.  
    4. 'creates text file
    5. oWrite = oFile.CreateText(...pathtofile... ex. "c:\mydata.txt"...)
    6.  
    7. 'writes data by line
    8. oWrite.WriteLine(...header...)
    9. oWrite.WriteLine(...sub header...)      
    10. oWrite.WriteLine(...data...)
    11.  
    12. 'flushes data to file and closes it      
    13. oWrite.Close()

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Location
    Madison, WI
    Posts
    136

    Re: Write to a .txt file & some other things....

    NOt so fast gigemboy....
    VB Code:
    1. oWrite.WriteLine(...sub header...)
    some of the info should be pulled from a table, what kind of statement would that be?

    thanks!!

  9. #9
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Write to a .txt file & some other things....

    That was the code to write the info to the text file once you got it over from the data tables... 'tis all.. should've written it on there.. but I thought it was evident

    Pulling data from SQL tables is going to require data access contstructs, sql queries, etc... not a particulary "easy" task.. better to find a link to read up on it.. I don't have any off hand, and haven't "delved" into the matter at all... maybe someone else can post a good link...

  10. #10
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416

    Re: Write to a .txt file & some other things....

    Yeah if you know some in ADO.NET then you could fetch the data in sql put in a datatable then loop to your datatable for writing to the txt file.

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