Results 1 to 10 of 10

Thread: write to text file

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2005
    Posts
    14

    write to text file

    how can i do this? ive been trying all day, and i cant figure it out.

    some help please?

    -Presise

  2. #2

  3. #3
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: write to text file

    The difference between the two is Output erases whats in the file (if the file exists) and writes it. Otherwise it creates the file then writes it.

    Append also creates the file if it does not exist, but instead of erasing the contents of the file when it does exist, it continues to write. And Rhinobull, it goes like this. In bold is where I corrected you:

    VB Code:
    1. Open "c:\temp\test.txt" For Output As #1
    2.     Print [b]#1,[/b] "line1"
    3.     Print [b]#1,[/b] "line2"
    4. Close #1
    5.  
    6. 'AND/OR
    7.  
    8. Open "c:\temp\test.txt" For Append As #1
    9.     Print [b]#1,[/b] "line3"
    10.     Print [b]#1,[/b] "line4"
    11. Close #1

  4. #4
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: write to text file

    VB Code:
    1. Open "c:\temp\test.txt" For Output As #1
    2.     Print #1, "line1";
    3.     Print #1, "line2";
    4. Close #1
    5.  
    6. 'AND/OR
    7.  
    8. Open "c:\temp\test.txt" For Append As #1
    9.     Print #1, "line3";
    10.     Print #1, "line4";
    11. Close #1

    so it doesnt add vbcrlfs

  5. #5

    Thread Starter
    New Member
    Join Date
    Aug 2005
    Posts
    14

    Re: write to text file

    thanks, but exactly how would i use this?

    [edit] nvm, i figured it out. thank you.
    Last edited by PresiseFA; Aug 18th, 2005 at 01:18 PM.

  6. #6
    Hyperactive Member eranfox's Avatar
    Join Date
    May 2001
    Posts
    492

    Re: write to text file

    Hello PresiseFA,

    you can also use Write insted of Print

    VB Code:
    1. Print #1,,"Hello","resiseFA"
    2. Write #1,"Hello","resiseFA"

    inside the text file you will have two rows:
    the first row will look like this:
    Hello resiseFA

    the second row will look like this:
    "Hello","resiseFA"

    also with Print and Write you can put the result of a matematic calc like:

    VB Code:
    1. Print #1,2*3;
    2. Write #1,2*3;

    inside the text file you will see the result of 2*3 (6)

    Best Regards,
    ERAN

    P.S: Try to read more on the MSDN how to read and write to a file in a RANDOM Order

    small example:
    VB Code:
    1. Private Type myStracture
    2.            iID As Integer
    3.            sLastName As String * 40
    4.            sFirstName As String * 20
    5. End Type
    6.  
    7. dim EmpRecord as myStracture
    8. EmpRecord.iID = "12345"
    9. EmpRecord.sLastName = "Fox"
    10. EmpRecord.sFirstName = "Eran"
    11.  
    12. Open "C:\MyFile.txt for Random As #1 Len = Len(EmpRecord)
    13.  
    14. Put #1,EmpRecord 'write on record to the file
    15.  
    16. Get #1,1,EmpRecorde 'get the 1st Record in the file
    17.  
    18. Seek #1,4  ' go to the 4th Record in the file

    Good Luck
    ERAN
    Eran Fox
    ASSEMBLER,C,C++,VB6,SQL...

  7. #7
    Lively Member
    Join Date
    Dec 2004
    Location
    E...A...R...T...H
    Posts
    88

    Re: write to text file

    Quote Originally Posted by PresiseFA
    thanks, but exactly how would i use this?

    [edit] nvm, i figured it out. thank you.
    Here, i hope it helps

    Edit: Saw above too late.
    Attached Files Attached Files
    Normality is what you make it.

  8. #8
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: write to text file

    Hey I remember you, XeonTeam. It's been awhile.

  9. #9

  10. #10

    Thread Starter
    New Member
    Join Date
    Aug 2005
    Posts
    14

    Re: write to text file

    thanks for the help, all of you. but this was for a bug report system in my game. i had to set it up to record the players name, and the bug they reported, so its like:

    "Test reported: the chat doesnt work"

    =) it works fine now tho..

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