第一次发帖
我想从txt中读取数据作为记录保存到acess中 请各位大虾帮忙下,本人程序新手。
txt文本格式如下:
1968 1 1
67 47 56 45 50 63 60 0 47 54
41 27 51 65 56 81 61 57 34 47
67 93 59 63 108 79 67 78 71 114
59 85 148 122 152 134 122 126 125 107
102 71 65 96 106 103 107 143 78 108
117 90 67 74 78 129 66 63 72 105
134 24 31 24 5 41 33 38 44 39
51 50 53 64 72 1 45 38 72 51
32 125 55 29 62 110 114
1968 1 2
61 22 47 39 49 60 54 0 58 75
59 52 68 117 83 99 84 56 50 66
97 149 128 109 143 151 124 120 131 127
128 98 135 122 140 125 104 129 120 112
90 78 67 85 102 109 82 134 81 95
147 83 45 60 75 135 68 55 55 107
124 36 11 40 22 64 40 55 45 53
51 64 75 92 74 34 36 75 74 62
45 141 57 33 89 110 127
......
预期保存在ACESS中的记录格式是1968-1-1 67 1站
1968-1-2 61 1站
....
1968-1-1 47 2站
1968-1-2 22 2站
....请问如何实现啊 ?
我想从txt中读取数据作为记录保存到acess中 请各位大虾帮忙下,本人程序新手。
txt文本格式如下:
1968 1 1
67 47 56 45 50 63 60 0 47 54
41 27 51 65 56 81 61 57 34 47
67 93 59 63 108 79 67 78 71 114
59 85 148 122 152 134 122 126 125 107
102 71 65 96 106 103 107 143 78 108
117 90 67 74 78 129 66 63 72 105
134 24 31 24 5 41 33 38 44 39
51 50 53 64 72 1 45 38 72 51
32 125 55 29 62 110 114
1968 1 2
61 22 47 39 49 60 54 0 58 75
59 52 68 117 83 99 84 56 50 66
97 149 128 109 143 151 124 120 131 127
128 98 135 122 140 125 104 129 120 112
90 78 67 85 102 109 82 134 81 95
147 83 45 60 75 135 68 55 55 107
124 36 11 40 22 64 40 55 45 53
51 64 75 92 74 34 36 75 74 62
45 141 57 33 89 110 127
......
预期保存在ACESS中的记录格式是1968-1-1 67 1站
1968-1-2 61 1站
....
1968-1-1 47 2站
1968-1-2 22 2站
....请问如何实现啊 ?
Dim fs, f, s
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile(sFileName, 1)
s = f.readall '将整个文件内容读入 s
f.Close: Set f = Nothing: Set fs = Nothing
Dim LineText, sWord
For Each LineTxt In Split(s, vbcdrf)
For Each sWord In Split(LineText, " ")
'LineText 为每一行的文本,如“67 47 56 45 50 63 60 0 47 54”
'sWord 为每一行中用空格分开的数字字符,如“67”,“47”,“56”等
'
'此处添加写入过程
'
Next sWord
Next LineText
感谢 但是请教下 我的每行数据的间隔无规律 有时候间隔一个空格 有时候是三个空格 这样怎么以空格为间隔能读取数据啊 我不太会用split 函数啊 ,也请高人指教。
Dim fs, f, s
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile(sFileName, 1)
s = f.readall '将整个文件内容读入 s
f.Close: Set f = Nothing: Set fs = Nothing '将两个以上的空格替换成一个空格
While InStr(1, s, " ") > 0
s = Replace(s, " ", " ")
Wend Dim LineText, sWord
For Each LineTxt In Split(s, vbcdrf)
For Each sWord In Split(LineText, " ")
'LineText 为每一行的文本,如“67 47 56 45 50 63 60 0 47 54”
'sWord 为每一行中用空格分开的数字字符,如“67”,“47”,“56”等
'
'此处添加写入过程
'
Next sWord
Next LineText