CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2000
    Posts
    57

    Formatted READ and WRITE to a text file

    Is there a way to do formatted READ and WRITE to a text file using VB. For example in fotran we have a function like
    read(id,'(4i5,f10.0,i5)',err=110,end=110npnt,ntft,ntsv,ntip,damp,n411

    The second parameter tells that read four integers of length 5, one float of length 10 with nothing after decimal and then one integer of length 5. At the end there is a variable list in which these values are retrieved,
    Similarly for write we have
    write(id,'(a80)') titl
    This function writes titl to file in a 80 character long field.
    How can we achieve similar functionality in VB

    regards
    ali.



  2. #2
    Join Date
    Apr 2001
    Posts
    4

    Re: Formatted READ and WRITE to a text file

    Hi

    1. You can use .ini files: if you have to archive fixed data, for code see
    http://www.vb-world.net/demos/ini/index.html

    2. just code for reading and writing data:

    Dim InputData 'input an output string

    Open fullpath_2_textfile For Input As #1
    Line Input #1,InputData
    Close #1

    Open fullpath_2_textfile For Writing As #2
    Write #2,InputData
    Close #2

    You may also open the number #1 and #2 or much more together like:

    Dim InputData 'input an output string

    Open fullpath_2_textfile For Input As #1
    Open fullpath_2_textfile For Writing As #2
    Line Input #1,InputData
    Inputdata = "This string will be stored in the text file"
    Write #2,InputData
    Inputdata = "This will be the second string!"
    Write #2,InputData
    Close #1
    Close #2

    !!!If you use this methode, the string shall have " -characters aroud the string. You have to remove them while reading each string.

    For fixed data I use ini-files -> faster and better code










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

Featured