解决方案 »

  1.   

    试试看这个 Open "D:\chat.txt" For Output As #1
    a = Text1.Text
    Print #1,  a
    Close #1
      

  2.   

    先以Open "C:\1.ini" For output As #1方式打开,再close
    再以Open "C:\1.ini" For Binary As #1打开 并写入
      

  3.   

    二进制方式写文件,是有这个问题。可以先删除旧文件再写。如果你不介意文件大小的话:
    Dim byt() as Byte, i As IntegerRedim byt(19)
    '初始化 byt
    Open "C:\1.ini" For Binary As #1
    n = EOF(1) - 1
    If n > 19 Then
        Redim Preserve byt(n)
        For i = 20 To n
            byt(i) = 32
        Next i
    End If
    Put #1,,byt
    Close #1
      

  4.   

    唉,看来也没有什么好的简洁的办法,我倒是想到一个:就是先写入文件,然后再把文件缩短为写入内容的长度:    Dim byt(19) as Byte
        '///////////////////这儿初始化byt
        Open "C:\1.ini" For Binary As #1
        Put #1,,byt
        Close #1    '接下来就是缩短文件
        Dim SA As SECURITY_ATTRIBUTES
        hFile = CreateFile("C:\1.ini", GENERIC_READ Or GENERIC_WRITE, 0, SA, OPEN_EXISTING, 0, 0)
        SetFilePointer hFile, 20, 0, FILE_BEGIN
        SetEndOfFile hFile
        CloseHandle hFile
      

  5.   

    其实我只是想当然以为在Open ... For Binary语句里面就可以实现,如果实在不行就算了,就只有Kill了之后再写了。。