0

txt ファイルからデータを読み取り、それを整数配列に保存しました。その配列をExcelシートにエクスポートしたいのですが、結果が正しくない理由がわかりません。私を助けてください。

Input #1, n

'Now construct the (n x n) matrix that will hold the problem and read in the problem from the input file
ReDim ProbMatrix(1 To n, 1 To n) As Integer

Dim someNumber As Integer
Dim startPosition As Long
Dim endPosition As Long
Dim temp As String

Do While Not (EOF(1))
    startPosition = Seek(1)  '// capture the current file position'
    Line Input #1, temp      '// read an entire line'
    endPosition = Seek(1)    '// determine the end-of-line file position'
    Seek 1, startPosition    '// jump back to the beginning of the line'

    '// read numbers from the file until the end of the current line'
    For i = 1 To n
        For j = 1 To n
            Do While Not (EOF(1)) And (Seek(1) < endPosition)
                Input #1, someNumber
                ProbMatrix(i, j) = someNumber
                MsgBox ProbMatrix(i, j)
            Loop
        Next j
    Next i        
Loop    
Close #1        

Dim NewProbMatrix() As Integer
Dim act As Action
NewProbMatrix = makeInitialSolution(ProbMatrix, n)
Cells(1, 1) = n
For i = 1 To n
    For j = 1 To n
        Cells(i + 1, j) = ProbMatrix(i, j)
    Next
Next

Application.Save
Workbooks.Close
MsgBox ("Finished")
4

2 に答える 2

0

これを試して

With Thisworkbook.Activesheet
.Cells(1, 1).value = n
For i = 1 To n
    For j = 1 To n
        .Cells(i + 1, j).value = ProbMatrix(i, j)
    Next
Next
End With

これが役に立てば幸いです、乾杯

于 2013-05-23T00:13:31.540 に答える