How to use VB in the text file stored in the array number, please master pointin

Such as E disk text file has the following numbers, each number on both sides have two commas, how to use VB to read only digital, and to digital deposit numerical array.
,25,
,30,
,10,
,23,
,22,
,31,
,2,
,2,
,8,
,15,
,12,
,8,
,4,
,27,
,30,
,18,

Started by Kathy at February 01, 2016 - 6:32 AM

With the split function, try it

Posted by Beau at December 02, 2016 - 3:52 AM

Open "E:\ database.Txt" For Input As #1

St = ""
Z = ""
Do Until EOF(1)
Line Input #1, Z
St = St & Z & Chr(13) 'The first step
Loop
Close #1

shuzhu = Split(St, ",", -1) 'The second step

Print shuzhu(0)
Print shuzhu(1)
Print shuzhu(2)
Print shuzhu(3)
Print shuzhu(4)
Print shuzhu(5)
Print shuzhu(6)
Print shuzhu(7)
Print shuzhu(8)
Print shuzhu(9)
Print shuzhu(10)
Print shuzhu(11)
Print shuzhu(12)
Print shuzhu(13)

Segmentation using the split function, some of the array is empty, and the array named as an array of strings. I want the array but not ah! Ask for advice!

Posted by Kathy at December 13, 2016 - 4:26 AM

Software engineering is put in your E disk the same directory and then running


Private Sub Command1_Click()
Dim Sz 'Array
Dim Str 'The contents of the file
Str = OpenFile(App.Path & "\The file 1.txt")
Str = Replace(Str, ",", "") 'The useless digital replace
Sz = Split(Str, vbCrLf) 'Character into the array

MsgBox "The first second are array: " & Sz(0) & "--" & Sz(1)
MsgBox "All the contents of the array is: " & vbCrLf & Join(Sz, vbCrLf)
End Sub
'┏〓〓〓〓〓〓〓〓〓 OpenFile,start 〓〓〓〓〓〓〓〓〓┓
'[Introduction]:
'Open the file
Function OpenFile(FileName, Optional ErrInfo As String) As String
'[mycode_id:19],edittime:2012/9/5 19:48:31
On Error GoTo Err1
Dim Fs, TextFile
Set Fs = CreateObject("Scripting.FileSystemObject")
Set TextFile = Fs.OpenTextFile(FileName)
OpenFile = TextFile.ReadAll ' Read the entire file information
Exit Function
Err1:
ErrInfo = Err.Description
End Function
'┗〓〓〓〓〓〓〓〓〓 OpenFile,end 〓〓〓〓〓〓〓〓〓┛

Posted by Jessica at December 27, 2016 - 5:23 AM

Combined with the upstairs master it, the problem is Shuzhu is an array of strings, ask how to put it into numerical array?

Private Sub Form_Click()

Dim shuzhu() As String
St = ""
Z = ""
Open "E:\ database 01E:\ database 01E:\数据库\尾数\数据库01\002\文件1.txt2\ 1.txt database file \ \ mantissa2\ 1.txt database file \ \ mantissa" For Input As #1

Do Until EOF(1)
Line Input #1, Z
St = St & Z & Chr(13) 'The first step
Loop
Close #1

St = Replace(St, ",", "") 'The useless digital replace

shuzhu = Split(St, Chr(13), -1)

Print shuzhu(0)
Print shuzhu(1)
Print shuzhu(2)
Print shuzhu(3)
Print shuzhu(4)
Print shuzhu(5)
Print shuzhu(6)
Print shuzhu(7)
Print shuzhu(8)
Print shuzhu(9)
Print shuzhu(10)
Print shuzhu(11)
Print shuzhu(12)
Print shuzhu(13)

End Sub

Posted by Kathy at January 04, 2017 - 5:58 AM

Combined with the upstairs master it, the problem is Shuzhu is an array of strings, ask how to put it into numerical array?

Private Sub Form_Click()

Dim shuzhu() As String
St = ""
Z = ""
Open "E:\数据库\尾数\数据库01\002\文件1.txt" For Input As #1

Do Until EOF(1)
Line Input #1, Z
St = St & Z & Chr(13) 'The first step
Loop
Close #1

St = Replace(St, ",", "") 'The useless digital replace

shuzhu = Split(St, Chr(13), -1)'''The problem is Shuzhu is an array of strings, ask how to put it into numerical array?

Posted by Kathy at January 12, 2017 - 6:19 AM


Private Sub Command1_Click()
Open "F:\data.txt" For Input As #1

Dim shuzhu() As Single
Dim Count As Single
Count = 0

Do Until EOF(1)
Line Input #1, z
ReDim Preserve shuzhu(Count) As Single
shuzhu(Count) = CSng(Mid(z, 2, Len(z) - 2)) 'The first method
Count = Count + 1
st = st & z & Chr(13) 'The first step
Loop
Close #1

'shuzhu = GetData(st) 'Second kinds of methods
Print shuzhu(0)
Print shuzhu(1)
Print shuzhu(2)
Print shuzhu(3)
Print shuzhu(4)
Print shuzhu(5)
Print shuzhu(6)
Print shuzhu(7)
Print shuzhu(8)
Print shuzhu(9)
Print shuzhu(10)
Print shuzhu(11)
Print shuzhu(12)
Print shuzhu(13)


End Sub



Private Function GetData(ByVal Data As String) As Single()
Dim BakArr() As String
Dim DataArr() As Single
Dim i As Single
Data = Replace(Data, ",", "")
BakArr = Split(Data, Chr(13))

ReDim DataArr(UBound(BakArr)) As Single

For i = 0 To UBound(BakArr) - 1
DataArr(i) = CSng(BakArr(i))
Next

GetData = DataArr
End Function

Posted by Mandy at January 13, 2017 - 6:06 AM