Public Function ListA(Path As String,Sz() As String,objA As Object) As Integer '声明Path路径,Sz字符串数组,ObjA对象形参 Dim a1 As String '一个临时变量 Dim Temp As String '呵呵,又是一个临时变量 Dim Js As Integer '饿,还是一个临时变量 Js = 0 '初始化获取行数变量值为0 Open Path For Input As #1 '输出list2.lis文件 '使用Js变量获取整个lis文件的长度 Do Until EOF(1) = True Line Input #1,Temp Js = Js + 1 Loop Close #1 '----------------------------------------------- Open Path For Input As #2 For i = 0 To Js \ 2 - 2 Line Input #2,a1 objA.AddItem a1 Next i '----------------------------------------------- '这里本想用For循环代替的,但好像容易溢出,鬼知道怎么回事 Line Input #2,Temp '将文本中间两行废话读进temp变量 Line Input #2,Temp ' '----------------------------------------------- ReDim Sz(Js \ 2 - 2) '重新定义a2数组 For i2 = 0 To Js \ 2 - 2 'JS总行数减去两行废话剩下的再除以上面和下面两个 Line Input #2,Sz(i2) Next i2 Close #2 '关闭文件 ListA = Js / 2 - 2 + 1 End Function
之后再调用
Dim ListTextNumber() As String Private Sub Form_Load() Dim ReturnList As Integer ReturnList = ListA(App.Path & "\ListItem.Item",ListTextNumber,List1) End Sub该函数可以读取某个文件的信息,并且返回到列表框。