7,762
社区成员
发帖
与我相关
我的任务
分享
Option Explicit
Dim iData()
Private Sub Form_Load()
Static n As Integer
Open "C:\1.txt" For Input As #1
Do Until EOF(1)
ReDim Preserve iData(n)
Line Input #1, iData(n)
n = n + 1
Loop
Close #1
End Sub
Public Function Pipedat2D(ByVal nRow As Long, ByVal nCol As Long) As String
Pipedat2D = Split(iData(nRow - 1), " ")(nCol - 1)
End Function
Private Sub Command1_Click()
MsgBox Pipedat2D(3, 1)
End Sub
Public strPipedata2D() As String
Public Populated As Boolean
Public Function Get_Pipedat2D(ByVal i As Long, ByVal j As Long) As String
If Not Populated Then
Init_Pipedata_Array
End If
If i <= UBound(strPipedata2D, 1) And j <= UBound(strPipedata2D, 2) Then
Get_Pipedat2D = strPipedata2D(i, j)
End If
End Function
Public Sub Init_Pipedata_Array()
Dim r As Long, c As Long, i As Long, j As Long
Dim strRow As String, strCol() As String
Dim strTmp() As String, OK As Boolean
Open "c:\def\¹ÜϵÅäÖÃ.txt" For Input As #1
Do Until EOF(1)
Line Input #1, strRow
strCol = Split(strRow, " ")
If r = 0 Then
c = UBound(strCol)
ElseIf c > UBound(strCol) Then
MsgBox "Bad file!"
Exit Sub
End If
ReDim Preserve strTmp(c, r)
For j = 0 To c
strTmp(j, r) = strCol(j)
Next j
r = r + 1
Loop
OK = True
Close #1
If Not OK Then Exit Sub
ReDim strPipedata2D(1 To r, c)
For i = 1 To r
For j = 0 To c
strPipedata2D(i, j) = strTmp(j, i - 1)
Debug.Print strPipedata2D(i, j) & " ";
Next j
Debug.Print ""
Next i
Populated = True
End Sub
同样,行的基数是 1 为起点。Public Function Pipedat2D(ByVal i As String, ByVal j As String)
Dim strRow As String, strCol() As String, n As Long
Open App.Path & "\def\管系配置.txt" For Input As #1
n = 1
Do Until EOF(1)
Line Input #1, strRow
If n = i Then
strCol = Split(strRow, " ")
If j <= UBound(strCol) Then
Pipedat2D = strCol(j)
End If
Close #1
Exit Function
End If
n = n + 1
Loop
Close #1
End Function