程序里生成的数组是动态改变的,现在我想写到文本文件中去,想要得到格式如下:a11 a12 a13 … a1n
a21 a22 a23 … a2n
…  …  …  … …
am1 am2 am3 … amn其实就是一个矩阵,m和n每次是不一样的,
程序中的数组是a(m,n)
请问如何做。

解决方案 »

  1.   

    Option ExplicitPrivate Sub Command1_Click()
            Dim M As Long
            Dim N As Long
            Dim OutStr As String
            Dim A() As String
            
            '............................
            
            For M = 0 To UBound(A, 1)
                For N = 0 To UBound(A, 2)
                    OutStr = A(M, N) & OutStr & Chr(vbKeyTab)
                Next
                OutStr = OutStr & Chr(13)
            Next
            WritTextFile "C:\DEMO.TXT", OutStr
    End Sub'
    '写TEXT文件
    '函数:WritTextFile
    '参数:FileName 目标文件名.WritStr 写到目标的字符串.
    '返回值:成功 返回文件内容.失败  返回""
    '注:如果同名,目标字符串将覆盖原文件内容.
    Public Function WritTextFile(Filename As String, WritStr As String) As Boolean
    '/保存文件
        Dim FileID As Long, ConTents As String
        Dim A As Long, B As Long
        
        On Error Resume Next
        
        FileID = FreeFile
        Open Filename For Output As #FileID
             Print #FileID, WritStr
        Close #FileID
        WritTextFile = (Err.Number = 0)
        Err.Clear
    End Function