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 នៃ​សេចក្តី​ថ្លែង​ការ​ Open ដក​ឃ្លា​ចន្លោះ​ចុង​នៃ​កំណត់​ត្រា​ដែល​បាន​សរសេរ​ថ្មី និង​កំណត់​ត្រា​បន្ទាប់​ត្រូវ​បាន​ពង្រីក​ឲ្យ​វែង​ជាមួយ​ទិន្នន័យ​ដែល​មាន​ស្រាប់​ពី​ឯកសារ ដែល​អ្នក​កំពុង​សរសេរ​ទៅ ។

ចំណាំ​សម្រាប់​ឯកសារ​គោល​ពីរ ៖ មាតិកា​នៃ​អថេរ​ត្រូវ​បាន​សរសេរ​ទៅ​ទីតាំង​ដែល​បាន​បញ្ជាក់​ និង​ទ្រនិច​ឯកសារ​ត្រូវ​បាន​បញ្ចូល​ដោយ​ផ្ទាល់​បន្ទាប់​ពី​បៃ​ចុង​ក្រោយ ។ គ្មាន​ដក​ឃ្លា​នៅ​សល់​រវាង​កំណត់​ត្រា ។

Example:

Sub ExampleRandomAccess
    Dim iNumber As Integer
    Dim sText As Variant REM Must be a variant
    Dim aFile As String
    aFile = "~/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" ' 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

Please support us!