VB调用TXT特定字段并储存
发布网友
发布时间:2023-09-15 04:17
我来回答
共3个回答
热心网友
时间:2024-12-12 05:51
花了一早上调了,希望对你有帮助
Private Sub Command1_Click()
Dim con As ADODB.Connection
Dim rst As ADODB.Recordset
Set con = New ADODB.Connection
con.Provider = "microsoft.jet.oledb.4.0"
con.ConnectionString = "data source=C:\hcp1.mdb"'自己改一下路径
con.Open
Set rst = New ADODB.Recordset
rst.Open "select * from test", con, adOpenKeyset, adLockOptimistic
Dim mystr, myarr
Open "c:\1.txt" For Input As #1’改路径
Do While Not EOF(1)
Line Input #1, mystr
If Mid(mystr, 15, 1) = "A" Then
myarr = Split(mystr, ",", -1, 1)‘分割字符串
MsgBox myarr(3)
rst.AddNew
rst.Fields(1).Value = myarr(0): rst.Fields(2) = myarr(1): rst.Fields(3) = myarr(2): rst.Fields(4) = myarr(3): rst.Fields(5) = myarr(4)
rst.Update
End If
If Mid(mystr, 15, 1) = "C" Then
myarr = Split(mystr, ",", -1, 1)
rst.AddNew
rst.Fields(1).Value = myarr(0): rst.Fields(2) = myarr(1): rst.Fields(3) = myarr(2): rst.Fields(4) = myarr(3): rst.Fields(5) = myarr(4)
rst.Update
End If
If Mid(mystr, 15, 1) = "F" Then
myarr = Split(mystr, ",", -1, 1)
rst.AddNew
rst.Fields(1).Value = myarr(0): rst.Fields(2) = myarr(1): rst.Fields(3) = myarr(2): rst.Fields(4) = myarr(3): rst.Fields(5) = myarr(4)
rst.Update
End If
Loop
Set rst = Nothing
Set con = Nothing
End Sub
热心网友
时间:2024-12-12 05:51
呵呵,好好学vb,这些别问了吧,去看看数组和txt的读写方法就是了很基础的
热心网友
时间:2024-12-12 05:52
看到有符号分隔的想到了什么?就是Read+自定义类型+一维数组嘛