Put# Statement

āĻāĻ•āϟāĻŋ āϏāĻŽā§āĻĒāĻ°ā§āĻ•āĻŋāϤ āĻĢāĻžāχāϞ⧇ āϰ⧇āĻ•āĻ°ā§āĻĄ āĻ…āĻĨāĻŦāĻž āĻāĻ•āϟāĻŋ āĻŦāĻžāχāύāĻžāϰāĻŋ āĻĢāĻžāχāϞ⧇ āĻŦāĻžāχāĻŸā§‡āϰ āĻ•ā§āϰāĻŽ āϞ⧇āĻ–āĻž āĻšā§ŸāĨ¤

tip

Use Print# statement to print data to a sequential text file. Use Write# statement to write data to a sequential text file with delimiting characters.


Syntax:

Put Statement diagram


Put [#]fileNum, [recordNum|filePos], variable

Parameters:

fileNum: Any integer expression that defines the file that you want to write to.

recordNum, filePos: For relative files (random access files), the number of the record that you want to write.

āĻŦāĻžāχāύāĻžāϰāĻŋ āĻĢāĻžāχāϞ⧇āϰ āϜāĻ¨ā§āϝ (āĻŦāĻžāχāύāĻžāϰāĻŋ āϤāĻĨā§āϝ āύāĻŋāĻŦ⧇āĻļāύ), āĻĢāĻžāχāϞ⧇ āĻŦāĻžāχāĻŸā§‡āϰ āĻ…āĻŦāĻ¸ā§āĻĨāĻžāύ āϝ⧇āĻ–āĻžāύ⧇ āφāĻĒāύāĻŋ āϞ⧇āĻ–āĻž āĻļ⧁āϰ⧁ āĻ•āϰāϤ⧇ āϚāĻžāύāĨ¤

variable: Name of the variable that you want to write to the file.

āϏāĻ‚āĻļā§āϞāĻŋāĻˇā§āϟ āĻĢāĻžāχāϞ⧇āϰ āϜāĻ¨ā§āϝ āύ⧋āϟ: āϝāĻĻāĻŋ āϖ⧁āϞ⧁āύ āĻ¸ā§āĻŸā§‡āϟāĻŽā§‡āĻ¨ā§āĻŸā§‡āϰ Len āĻŦāĻžāĻ•ā§āϝāĻžāĻ‚āĻļ⧇ āωāĻ˛ā§āϞ⧇āĻ–āĻŋāϤ āϰ⧇āĻ•āĻ°ā§āĻĄā§‡āϰ āĻĻ⧈āĻ°ā§āĻ˜ā§āϝ⧇āϰ āϏāĻžāĻĨ⧇ āϭ⧇āϰāĻŋā§Ÿā§‡āĻŦāϞ⧇āϰ āĻŦāĻŋāώ⧟āĻŦāĻ¸ā§āϤ⧁ āύāĻž āĻŽāĻŋāϞ⧇ āϤāĻžāĻšāϞ⧇, āύāϤ⧁āύāĻ­āĻžāĻŦ⧇ āϞ⧇āĻ–āĻž āϰ⧇āĻ•āĻ°ā§āĻĄā§‡āϰ āĻļ⧇āώ āĻāĻŦāĻ‚ āĻĒāϰāĻŦāĻ°ā§āϤ⧀ āϰ⧇āĻ•āĻ°ā§āĻĄā§‡āϰ āĻŽāĻ§ā§āϝāĻŦāĻ°ā§āϤ⧀ āĻĢāĻžāρāĻ•āĻž āĻ¸ā§āĻĨāĻžāύ āϞ⧇āĻ–āĻž āĻšāĻšā§āϛ⧇ āĻāĻŽāύ āĻĢāĻžāχāϞ⧇āϰ āĻŦāĻŋāĻĻā§āϝāĻŽāĻžāύ āĻĄāĻžāϟāĻžāϰ āϏāĻžāĻĨ⧇ āĻĒā§āϝāĻžāĻĄ āĻ•āϰāĻž āĻšāĻŦ⧇āĨ¤

āĻŦāĻžāχāύāĻžāϰāĻŋ āĻĢāĻžāχāϞ⧇āϰ āϜāĻ¨ā§āϝ āύ⧋āϟ: āϭ⧇āϰāĻŋā§Ÿā§‡āĻŦāϞ⧇āϰ āĻŦāĻŋāώ⧟āĻŦāĻ¸ā§āϤ⧁ āϏāĻŽā§‚āĻš āωāĻ˛ā§āϞ⧇āĻ–āĻŋāϤ āĻ¸ā§āĻĨāĻžāύ⧇ āϞ⧇āĻ–āĻž āĻšā§Ÿ āĻāĻŦāĻ‚ āϏāĻ°ā§āĻŦāĻļ⧇āώ āĻŦāĻžāχāĻŸā§‡āϰ āĻļ⧇āώ⧇ āĻĢāĻžāχāϞ āĻĒā§Ÿā§‡āĻ¨ā§āϟāĻžāϰāϟāĻŋ āϏāϰāĻžāϏāϰāĻŋ āϏāĻ¨ā§āύāĻŋāĻŦ⧇āĻļ āĻ•āϰāĻžāύ⧋ āĻšā§ŸāĨ¤ āϰ⧇āĻ•āĻ°ā§āĻĄā§‡āϰ āĻŽāĻ§ā§āϝ⧇ āϕ⧋āύ āĻĢāĻžāρāĻ•āĻž āĻ¸ā§āĻĨāĻžāύ āĻĨāĻžāĻ•āϤ⧇ āĻĒāĻžāϰāĻŦ⧇ āύāĻžāĨ¤

Example:

Example:


Sub ExampleRandomAccess
    Dim iNumber As Integer
    Dim sText As Variant REM āĻ…āĻŦāĻļā§āϝāχ āĻāĻ•āϟāĻŋ āϭ⧇āϰāĻŋā§Ÿā§‡āĻ¨ā§āϟ āĻšāĻŦ⧇
    Dim aFile As String
    aFile = "c:\data.txt"
    iNumber = Freefile
    Open aFile For Random As #iNumber Len=32
    Seek #iNumber,1 REM Position at beginning
    Put #iNumber,, "This is the first line of text" REM Fill line with text
    Put #iNumber,, "This is the second line of text"
    Put #iNumber,, "This is the third line of text"
    Seek #iNumber,2
    Get #iNumber,,sText
    Print sText
    Close #iNumber
    iNumber = Freefile
    Open aFile For Random As #iNumber Len=32
    Get #iNumber,2,sText
    Put #iNumber,,"This is a new text"
    Get #iNumber,1,sText
    Get #iNumber,2,sText
    Put #iNumber,20,"This is the text in record 20"
    Print Lof(#iNumber)
    Close #iNumber
End Sub