vb 如何从TXT文件里读取出数字

2025-06-21 14:29:58
推荐回答(5个)
回答1:

用split
用2次就可以了
假如数据都存在str变量里面
第一次把每行分开
temp=split(str,vbcrlf)
a=split(temp(0),",")
b=split(temp(1),",")
c=split(temp(2),",")

结果为a的数组为 1,2,3
b的数组为 2,3,4
c的数组为 123,234,543

回答2:

我觉得你应该看看InStr()函数:
如果查找到字符串"/"就返回它在整个字符串中的位置。
如:l=instr(6,"vb,vb,我爱你vb,"vb")那么L返回的就是10
然后用mid()函数截取就行了!至于有字符串换回数字型你应该会吧?

回答3:

Public Enum OF
OpenFileOutput = 0
OpenFileInput = 1
OpenFileAppend = 2
End Enum
Public Function OpenFile(ByVal Files, Optional ByVal Text = "", Optional ByVal Mode As OF = 1)
On Error Resume Next
Select Case Mode
Case OpenFileInput
If Mid(Files, 1, 1) = "\" Then Files = App.Path & Files
Open Files For Input As #1
Do Until EOF(1)
Line Input #1, i
DoEvents
OpenFile = OpenFile & i & NL
Loop
Close #1
Case OpenFileOutput
If Mid(Files, 1, 1) = "\" Then Files = App.Path & Files
Open Files For Output As #1
Print #1, Text;
Close #1
Case OpenFileAppend
If Mid(Files, 1, 1) = "\" Then Files = App.Path & Files
Open Files For Append As #1
Print #1, Text
Close #1
End Select
End Function
Private Sub Form_Load()
Dim ReadFile
ReadFile = OpenFile("\1.txt", , OpenFileInput)
For Each i In Split(ReadFile, vbCrLf)
j = j + 1
If i <> "" And j = 1 Then s = Split(i, "/")(2)
If i <> "" And j = 2 Then n = Split(i, "/")(2)
If i <> "" And j = 3 Then c = s & "," & n & "," & Split(i, "/")(2)
Next
For i = 1 To Len(s)
a = a & Mid(s, i, 1) & ","
Next
a = Left(a, Len(a) - 1)
For i = 1 To Len(n)
b = b & Mid(n, i, 1) & ","
Next
b = Left(b, Len(b) - 1)
MsgBox a
MsgBox b
MsgBox c
End Sub

回答4:

ommand1_Click()
Dim A$
Open "C:\1.txt" For Input As #1
A = StrConv(InputB$(LOF(1), #1), vbUnicode)
Close #1
A = ","
Open "C:\1.txt" For Output As #1
Print #1, "{"
Print #1, A
Print #1, "}"
Close #1
MsgBox "OK!"
End Sub

回答5:

sorry,vb不是我擅长的