- Dim pVals As Collection
- Private Function LeftStr(ByVal String1 As Variant, ByVal String2 As Variant)
- On Error Resume Next
- LeftStr = Left(String1, InStr(String1, String2) - 1)
- If Err Then LeftStr = ""
- End Function
- Private Function RightStr(ByVal String1 As Variant, ByVal String2 As Variant)
- On Error Resume Next
- RightStr = Right(String1, Len(String1) - Len(String2) - InStr(String1, String2) + 1)
- If Err Then RightStr = ""
- End Function Public Sub ReadFile(FileName As String)
- Dim fso As New FileSystemObject
- Dim ts As TextStream
- Dim pStr As String
- Dim pVal(2) As StringSet ts = fso.OpenTextFile(FileName, ForReading)
- Set pVals = New Collection
- Do While Not ts.AtEndOfStream
- pStr = Trim(ts.ReadLine)
- pVal(0) = LeftStr(pStr, " ")
- pStr = Trim(RightStr(pStr, " "))
- pVal(1) = LeftStr(pStr, " ")
- pVal(2) = Trim(RightStr(pStr, " "))
- pVals.Add pVal
- Loop
- End Sub
- Public Sub WriteFile(FileName As String)
- Dim mycon As New ADODB.Connection mycon.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & FileName & ";Persist Security Info=False"
- mycon.Open
- For i = 1 To pVals.Count
- mycon.Execute "insert into point values('" & Join(pVals(i), "','") & "')"
- Next i
- End Sub
上述代码存为TlsPoint类Sub lt()
Dim a As New TlsPoint
a.ReadFile "d:\point\point.txt"
a.WriteFile "d:\point\point.mdb"
End Sub这是Point.mdb的格式
|