+ Reply to Thread
Results 1 to 5 of 5

how to write data and string to a text file

  1. #1
    Registered User
    Join Date
    10-07-2005
    Posts
    12

    how to write data and string to a text file

    I am very new to this. How do you write string and data to a file?
    For example, I want to write:
    "I am 28 years old"
    28 is a calculated number from a function!

  2. #2
    Dave Peterson
    Guest

    Re: how to write data and string to a text file

    Using VBA?

    Option Explicit
    Sub testme()

    Dim FileNum As Long
    Dim myYears As Long

    myYears = SomeFunction(DateSerial(2000, 12, 31))

    FileNum = FreeFile
    Close #FileNum
    Open "c:\myfile.txt" For Output As #FileNum
    Print #FileNum, "I am " & myYears & "years old"
    Close #FileNum

    End Sub
    Function SomeFunction(myDate As Date) As Long
    SomeFunction = DateDiff("yyyy", myDate, Date)
    End Function



    NewGuy100 wrote:
    >
    > I am very new to this. How do you write string and data to a file?
    > For example, I want to write:
    > "I am 28 years old"
    > 28 is a calculated number from a function!
    >
    > --
    > NewGuy100
    > ------------------------------------------------------------------------
    > NewGuy100's Profile: http://www.excelforum.com/member.php...o&userid=27935
    > View this thread: http://www.excelforum.com/showthread...hreadid=474907


    --

    Dave Peterson

  3. #3
    Max
    Guest

    Re: how to write data and string to a text file

    Perhaps something like this in say, C1:
    ="I am "&SUM(A1:B1)&" years old"

    --
    Rgds
    Max
    xl 97
    ---
    Singapore, GMT+8
    xdemechanik
    http://savefile.com/projects/236895
    --
    "NewGuy100" <[email protected]> wrote
    in message news:[email protected]...
    >
    > I am very new to this. How do you write string and data to a file?
    > For example, I want to write:
    > "I am 28 years old"
    > 28 is a calculated number from a function!
    >
    >
    > --
    > NewGuy100
    > ------------------------------------------------------------------------
    > NewGuy100's Profile:

    http://www.excelforum.com/member.php...o&userid=27935
    > View this thread: http://www.excelforum.com/showthread...hreadid=474907
    >




  4. #4
    RagDyer
    Guest

    Re: how to write data and string to a text file

    Depends on exactly what you're trying to do.

    If the 28 is the return of a function that is in, say cell D1, and you want
    the string to be in, say cell D20, then enter this in D20:

    ="I am "&D1&" years old."

    On the other hand, if you would want the cell containing the actual function
    to calculate the value *and* return it together with the string, you could
    have this in D1:

    ="I am "&DATEDIF(A3,B3,"y")&" years old."

    Where "DATEDIF(A3,B3,"y")" is the formula that returns the value 28.
    --
    HTH,

    RD
    ==============================================
    Please keep all correspondence within the Group, so all may benefit!
    ==============================================



    "NewGuy100" <[email protected]> wrote
    in message news:[email protected]...
    >
    > I am very new to this. How do you write string and data to a file?
    > For example, I want to write:
    > "I am 28 years old"
    > 28 is a calculated number from a function!
    >
    >
    > --
    > NewGuy100
    > ------------------------------------------------------------------------
    > NewGuy100's Profile:

    http://www.excelforum.com/member.php...o&userid=27935
    > View this thread: http://www.excelforum.com/showthread...hreadid=474907
    >



  5. #5
    Registered User
    Join Date
    10-07-2005
    Posts
    12
    I am sorry about that, I wanted to print it to a text file using vba. I haven't seen it using FileNum before. I've seen it using Write or something similar. Whats the difference between the Write function and thePrint function.
    Last edited by NewGuy100; 10-10-2005 at 10:08 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1