| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 508 人关注过本帖
标题:请教。。。TXT文件读取.....
只看楼主 加入收藏
冰域寒游
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2006-9-7
收藏
 问题点数:0 回复次数:5 
请教。。。TXT文件读取.....
TXT文件内容如下:
0003020342 20070531204442 02 1 0 2
0000584976 20070531204450 02 1 0 2
0011368552 20070531205349 02 1 0 2
0002441734 20070531205350 02 1 0 2
0011381183 20070531205519 02 1 0 2
0011369541 20070531205543 02 1 0 2
0000579197 20070531205554 02 1 0 2
0003030167 20070531205607 02 1 0 2
0000570433 20070531205921 02 1 0 2
0000581170 20070531205930 02 1 0 2
0003016829 20070531205933 02 1 0 2
0003016821 20070531205936 02 1 0 2
0011373961 20070531210039 02 1 0 2
0015728130 20070531210039 02 1 0 2
0011363725 20070531210045 02 1 0 2
0002442308 20070531210136 02 1 0 2
我想从文件里读取前面两项数据到变量里。。并保存到ACCESS数据库里...
请哪位大哥帮帮忙呀....
搜索更多相关主题的帖子: TXT 文件 
2007-06-06 10:04
ouzhiguang
Rank: 1
来 自:湖南长沙
等 级:新手上路
威 望:1
帖 子:240
专家分:0
注 册:2007-5-18
收藏
得分:0 

用TEXT存?你怎么不用xls表格存这些数据?????
然后在写进去啊

2007-06-06 12:57
ouzhiguang
Rank: 1
来 自:湖南长沙
等 级:新手上路
威 望:1
帖 子:240
专家分:0
注 册:2007-5-18
收藏
得分:0 

Private Sub Command1_Click()
Dim strfilename As String
Dim strline As String
Dim filenum As String
CommonDialog1.Filter = "所有文件(*.*)|*.*"
CommonDialog1.FilterIndex = 1
CommonDialog1.ShowOpen
strfilename = CommonDialog1.FileName
Text1.Text = ""
filenum = FreeFile
If strfilename <> "" Then
Adodc1.Refresh
Open strfilename For Input As filenum

Do While Not EOF(filenum)
Line Input #filenum, strline
For i = 1 To Len(Trim(strline))
s = Mid(Trim(strline), i, 1)
If s = " " Then
Adodc1.Recordset.AddNew
Adodc1.Recordset("user") = Trim(Mid(strline, 1, i))
Adodc1.Recordset.Update
Text2.Text = Text2.Text + Trim(Mid(strline, 1, i)) + Chr(13) + Chr(10)
s1 = Trim(Mid(strline, i))
For j = 1 To Len(s1)
If Mid(s1, j, 1) = " " Then

Adodc1.Recordset("date") = Trim(Mid(s1, 1, j))
Adodc1.Recordset.Update
Text3.Text = Text3.Text + Trim(Mid(s1, 1, j)) + Chr(13) + Chr(10)

Exit For

End If


Next j

Exit For

End If

Next i

Text1.Text = Text1.Text + strline + Chr(13) + Chr(10)
Loop
Close filenum
End If

End Sub

Private Sub Command2_Click()
End
End Sub

2007-06-06 14:01
冰域寒游
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2006-9-7
收藏
得分:0 

谢谢这位大哥。。

゛.洅愛啲丗堺.í 沒铕誰対吥起誰. ヽoo.o┈ 抵铕誰◇吥懂嘚珍惜誰.σЭ
2007-06-06 14:18
ouzhiguang
Rank: 1
来 自:湖南长沙
等 级:新手上路
威 望:1
帖 子:240
专家分:0
注 册:2007-5-18
收藏
得分:0 

做了一下修改,我本写文本还不熟悉!只有这样做了!
Private Sub Command1_Click()
Dim strfilename As String
Dim strline As String
Dim filenum As String
CommonDialog1.Filter = "所有文件(*.*)|*.*"
CommonDialog1.FilterIndex = 1
CommonDialog1.ShowOpen
strfilename = CommonDialog1.FileName
Text1.Text = ""
filenum = FreeFile
If strfilename <> "" Then

Open strfilename For Input As filenum

Do While Not EOF(filenum)
Line Input #filenum, strline
Text1.Text = Text1.Text + strline + Chr(13) + Chr(10)
Loop
Close filenum
End If

End Sub

Private Sub Command2_Click()
End
End Sub

Private Sub Command3_Click()
Text2.Text = ""
Text3.Text = ""
If Text1.Text = "" Then Exit Sub

CommonDialog1.FilterIndex = 1

strfilename = CommonDialog1.FileName
Text1.Text = ""
filenum = FreeFile
If strfilename <> "" Then
Adodc1.Refresh
Open strfilename For Input As filenum

Do While Not EOF(filenum)
Line Input #filenum, strline
For i = 1 To Len(Trim(strline))
s = Mid(Trim(strline), i, 1)
If s = " " Then
Adodc1.Recordset.Find ("user = '" & Trim(Mid(strline, 1, i)) & "'")
If Adodc1.Recordset.EOF Or Adodc1.Recordset.BOF Then
Adodc1.Recordset.AddNew
End If
Adodc1.Recordset("user") = Trim(Mid(strline, 1, i))
Adodc1.Recordset.Update

Text2.Text = Text2.Text + Trim(Mid(strline, 1, i)) + Chr(13) + Chr(10)
s1 = Trim(Mid(strline, i))
For j = 1 To Len(s1)
If Mid(s1, j, 1) = " " Then

Adodc1.Recordset("date") = Trim(Mid(s1, 1, j))
Adodc1.Recordset.Update
Text3.Text = Text3.Text + Trim(Mid(s1, 1, j)) + Chr(13) + Chr(10)

Exit For

End If


Next j

Exit For

End If

Next i

Text1.Text = Text1.Text + strline + Chr(13) + Chr(10)
Loop
Close filenum
End If

End Sub

2007-06-06 14:40
yinhonghao
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2007-6-6
收藏
得分:0 
楼上的大哥是强人,跟你混了!!!!
2007-06-06 21:22
快速回复:请教。。。TXT文件读取.....
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.023999 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved