RT。
Public Function WirteFile(ByVal TXTFile As String, ByVal inText As String) As Long
    Dim fn As Integer
    fn = FreeFile
    Open TXTFile For Binary As #fn
        Put #fn, , inText
    Close #fn
End FunctionFunction ReadFile(TXTFile As String) As String
    Dim fn As Integer
    fn = FreeFile
    Open TXTFile For Binary Access Read As #fn
        ReadFile = Space(FileLen(TXTFile))
        Get #fn, , ReadFile
    Close #fn
End Function

解决方案 »

  1.   

    这样是不是你要的啊?
    open "yourfilename" for output as #1
        print #1,""
    close #1
      

  2.   

    什么叫清零哈?
    open ../*.txt for output as #1
    print #1,""
    close #1
      

  3.   

    是这样的,文本文件A中有“ABCDEFGHIJKLMN”我用上面的代码写入:
    WirteFile c:\A.txt,"ABCDEF"
    文件中的“GHIJKLMN”还在。
      

  4.   

    封装了一个函数SetFileSize:Option Explicit
    Private Const FILE_BEGIN = 0
    Private Const OFS_MAXPATHNAME = 128
    Private Const OF_READWRITE = &H2
    Private Type OFSTRUCT
            cBytes As Byte
            fFixedDisk As Byte
            nErrCode As Integer
            Reserved1 As Integer
            Reserved2 As Integer
            szPathName(OFS_MAXPATHNAME) As Byte
    End Type
    Private Declare Function OpenFile Lib "kernel32" (ByVal lpFileName As String, lpReOpenBuff As OFSTRUCT, ByVal wStyle As Long) As Long
    Private Declare Function SetFilePointer Lib "kernel32" (ByVal hFile As Long, ByVal lDistanceToMove As Long, ByVal lpDistanceToMoveHigh As Long, ByVal dwMoveMethod As Long) As Long
    Private Declare Function SetEndOfFile Lib "kernel32" (ByVal hFile As Long) As Long
    Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As LongPrivate Sub Command1_Click()
        SetFileSize "e:\mc\ttt.dat", 0
    End SubPrivate Sub SetFileSize(ByVal FileName As String, ByVal FileSize As Long)
        Dim hFile As Long
        Dim OF As OFSTRUCT
        hFile = OpenFile(FileName, OF, OF_READWRITE)
        SetFilePointer hFile, FileSize, 0, FILE_BEGIN
        SetEndOfFile hFile
        CloseHandle hFile
    End Sub
      

  5.   

    或者你先kill文件,然后写入文件
      

  6.   

    以顺序文件方式打开文件再关闭就行了啊Open "x:\xxx\xxx.txt" For Output As #1
    Close #1
      

  7.   

    Open TXTFile For Binary As #fn关键是 Binary 这个关键字,以二进制方式打开的文件有点类似“重写”
    如果文件里面有10个字节的内容,现在从第1个字节位置开始写入3个字节,那么原来10个字节中的后7个字节的内容还是在的,所以代码改成这样就可以了
    Public Function WirteFile(ByVal TXTFile As String, ByVal inText As String) As Long
        Dim fn As Integer
        fn = FreeFile
        Open TXTFile For output As #fn
            print #fn,inText
        Close #fn
    End FunctionFunction ReadFile(TXTFile As String) As String
        Dim fn As Integer
        fn = FreeFile
        Open TXTFile For Input Access Read As #fn
        ReadFile = strconv(inputb(lof(fn),#fn),vbunicode)        
        Close #fn
    End Function
      

  8.   

    Open "文件名" For Output As #1
    Close #1
    这样就是个0字节的文件