Option Explicit Dim FileName As String
Private Sub Command1_Click() CommonDialog1.Filter = "文本文档(*.txt)|*.txt" CommonDialog1.ShowOpen FileName = CommonDialog1.FileName Dim ro, cl As Long Dim s, h, t As String ro = 0 cl = 0 MSHFlexGrid1.Rows = Getrows(FileName) MSHFlexGrid1.Cols = Getcols(FileName) Open FileName For Input As #1 While ro <> MSHFlexGrid1.Rows Line Input #1, s If Mid(s, 1, 1) <> "#" Then For cl = 0 To MSHFlexGrid1.Cols - 1 h = Trim(s) t = GetMyWord(h, cl + 1)'点击Command1就说ByRef参数类型不符 If t = "#" Then t = "" MSHFlexGrid1.TextMatrix(ro, cl) = t Next cl ro = ro + 1 End If Wend Close #1 End Sub
Private Function Getrows(filename2 As String) As Integer Dim p, aa As Integer Dim s As String p = 0 On Error GoTo a: b: Open FileName For Input As #1 While Not EOF(1) Line Input #1, s If Mid(s, 1, 1) <> "#" Then p = p + 1 End If Wend Close #1 Getrows = p Exit Function a: aa = MsgBox("没有选取文件", vbYesNo, "提示") If aa = vbYes Then Command1.Value = True GoTo b: End If
End Function
Private Function Getcols(filename2 As String) As Integer Dim p As Integer Dim s As String p = 1 On Error Resume Next Open FileName For Input As #1 Line Input #1, s Close #1 s = Trim(s) Do While InStr(s, " ") <> 0 s = Mid(s, InStr(s, " ")) s = Trim(s) p = p + 1 Loop Getcols = p End Function
Private Function GetMyWord(instring As String, j As Long) As String Dim i As Integer Dim st As String st = " " i = 0 Do While st <> "" instring = Trim(instring) st = Left(instring, InStr(instring, " ")) st = Trim(st) i = i + 1 If st = "" Then GetMyWord = instring Exit Function End If instring = Mid(instring, InStr(instring, " ")) instring = Trim(instring) If i = j Then GetMyWord = st Exit Function End If Loop End Function 到底哪出错了请高手帮忙,谢了。
[此贴子已经被作者于2005-7-31 10:28:30编辑过]