怎样可以做到让创建的txt文本进行自动随机添加内容
txt文档中内容格式预先设置好的,只是更改其中一两个值
例如正常工作直流(1),正常工作交流(2),断电(3),这样随机变换123

解决方案 »

  1.   

    不明白“自动随机添加”是什么意思。写文件还是要写代码的。你用 Open "文件名" For Append As #1 打开文件,Print #1, <你的值> 即可添加写入。记住最后要 Close #1。
      

  2.   

    Option ExplicitSub RandomAppend(ByVal FileName As String)
        Dim hFile As Integer
        Dim i As Long
        
        hFile = FreeFile()
        Open FileName For Append As #hFile
        
        Randomize
        i = Int(Rnd() * 3) + 1
        Select Case i
            Case 1: Print #hFile, "正常工作直流"
            Case 2: Print #hFile, "正常工作交流"
            Case 3: Print #hFile, "断电"
        End Select
        
        Close #hFile
    End SubPrivate Sub Command1_Click()
        RandomAppend "D:\temp\1.txt"
    End Sub