不会啊!我在Win2000+vb6 去掉循环始过,正常呀?
另外
    Dim buff As String * 6000
    buff = value & Chr(0)
可以去掉后面的chr(0)为buff = value 应该同系统有关,于程序无关!

解决方案 »

  1.   

    谢谢兄弟出手,您事先删除了ini文件吗?请看下面的代码:(我加上了删除ini的一段)Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal Appname As String, ByVal KeyName As Any, ByVal NewString As Any, ByVal filename As String) As Integer
    Public Function WriteToIni(ByVal filename As String, ByVal section As String, ByVal key As String, ByVal value As String)
        Dim buff As String * 6000
        buff = value & Chr(0)
        WriteToIni = WritePrivateProfileString(section, key, buff, filename)
    End FunctionPrivate Sub Command1_Click()
        If Dir("c:\test.ini") <> "" Then Kill "c:\test.ini"
        If Dir("c:\testcopy.ini") <> "" Then Kill "c:\testcopy.ini"
        WriteToIni "c:\test.ini", "section1", "key1", "values1"
        '没有以下循环,testcopy.ini乱码
        '有了以下循环,testcopy.ini不乱码
        i = 0
        Do While i < 10000
            i = i + 0.001
        Loop
        
        FileCopy "c:\test.ini", "c:\testcopy.ini"  '请检查testcopy.ini是否正常
        MsgBox "ok"
    End Sub