比如说有一个文件temp.txt,内容是:
speed=12
gx=4
gy=7
gz=3
xx=1
yy=2
zz=3等上千个数,如何用VB编程将这些数据读入到一个数组a()中?注意:是只读数据,要过滤掉前面的字符恳请高手相助,感激不尽!!
speed=12
gx=4
gy=7
gz=3
xx=1
yy=2
zz=3等上千个数,如何用VB编程将这些数据读入到一个数组a()中?注意:是只读数据,要过滤掉前面的字符恳请高手相助,感激不尽!!
解决方案 »
- 请教大家一个关于每周从几号好几号的问题?
- 一个比较急的问题,基于SERVER 2003 R2 X64操作系统上的程序运行问题
- 如何用VB生成Visio文件?高分求助。
- VB中想使用API函数卸载已知句柄的窗体。用了DestroyWindow,窗体是没了,但是再次加载那个窗体怎么也回不来了。。。
- 怎样获得端口输入的数据?比如读码机,刷卡机等的数据。
- 求救,VB6.0打包问题,等待
- ADO,DAO,RDO与ODBC等有什么区别又有什么联系,如何区分??
- vb与vc的结构传递问题。
- Help!!!那位大虾能告诉我怎么才能往类模块的public方法传送自定义数据结构!!我编得太郁闷了!
- 基础性问题,关于函数
- AutoCAD2000不支持VBA保存当前文档?
- 北京户口问题
Dim a As String
a = "speed = 12 gx = 4 gy = 7 gz = 3 xx = 1 yy = 2 zz = 3"
Dim b() As Stringb = Split(a, "=")
Dim i As Integer
For i = 0 To UBound(b)
b(i) = Val(b(i))
Print b(i)
NextEnd Sub
temp.txt文件可能如下:
speed=12
gx=4
gy=7
gz=3
xx=1
yy=2
zz=3
....temp.txt文件也可能如下:
speed=12 gx=4 gy=7 gz=3 xx=1 yy=2 zz=3
....temp.txt文件也可能如下:
speed=12,gx=4,gy=7,gz=3,xx=1,yy=2,zz=3
....
dim h as long'将文本内容读入变量s
h=freefile
open "c:\temp.txt" for binary as h
s=space(lof(h))
get h,,s
close'然后可以按上面yarui0301的方法处理
'不过最好加个判断
dim i as long
dim a() as stringa=split(s,"=")
for i=0 to ubound(a)
if trim(a(i))<>"" then a(i)=val(a(i))
next
Private Sub Form_Load()
Open "c:\temp.txt" For Input As #1
aa = StrConv(InputB(LOF(1), 1), vbUnicode)
Close #1
End SubPrivate Sub Command1_Click()
s = Split(aa, vbNewLine)
For i = 0 To UBound(s)
If s(i) <> "" Then
ss = Split(s(i), "=")
Print Val(ss(1))
End If
Next i
End Sub
dim fso as filesystemobjectdim stream as textstream
set stream = fso.opentextfile("c:\temp.txt",forreading)dim content as string
content = stream.readall()dim arr() as string
arr = split(content,vbcrlf)dim i as long
for i=lbound(arr) to ubound(arr)
dim temp() as string
temp = split(arr(i),"=")
call dict.add(temp(0),temp(1))
next
Option Explicit
Dim a$, n%, k%, c$(), d%Private Sub Form_Click()
n = 0
Open App.Path & "\temp.txt" For Input As #1
Do Until EOF(1)
n = n + 1
Line Input #1, a
ReDim c(n)
d = Len(a)
k = InStr(1, a, "=")
c(n) = Right(a, (d - k + 1))
Print "c(" & n & ")=" & c(n)
Loop
Close #1
End Sub
嘻嘻