Private Sub Command1_Click ()
Dim lngFn As Long, strT As String
LngFn=FreeFile
Open "e: \ 1. Dat" For Binary As # lngFn
StrT=Space (LOF (lngFn))
The Get # 1, and strT
Close # lngFn
Dim As Long a
SArr=Split (strT, vbCrLf)
A=1
Txt1. Text=Split (sArr (0), "") (a)
For a=1 To 6
If (txt1. Text="") Then
End the If
Next a
End Sub
CodePudding user response:
According to vbCrLf into an array, each row,Each line of data, and then press the space, into the array,
The array is the first,
CodePudding user response:
Remember to use the Trim removes white Spaces at the end of,CodePudding user response:
Private Sub Command1_Click ()
Dim lngFn As Long, strT As String, sArr () As String, I As Long
LngFn=FreeFile
Open "e: \ 1. Dat" For Input As # lngFn
Do Until EOF (lngFn)
The Line Input # lngFn strT
StrT=Trim (strT)
The Do While InStr (strT, Space (2))
StrT=Replace (strT, Space (2), Space (1))
Loop
SArr=Split (strT, Space (1))
If sArr (0)="1" Then
MsgBox "' 1 'is found."
The Exit Do
End the If
Loop
Close # lngFn
End Sub
CodePudding user response:
Actually my data format is on the picture, because I want to draw on the second column of the cloud, but due to some count of three, some accounts for four, I use the
Txt1. Text=Split (sArr (2), "") (12) can bring up when four of 10.0, 9.7, but want to obtain three again into the Split (sArr (2)," ") (13), so want to use loop statements, from FH column after the first space (txt1. Text=Split (sArr (2), "") (8)) began to move, if is a space will continue to adjust after a, if not the blank space is the value assigned to txt1. Text, seek advice ~ ~ ~ ~
CodePudding user response:
The Do While InStr (strT, Space (2))StrT=Replace (strT, Space (2), Space (1))
Loop
Replace multiple consecutive Spaces for a space, and then cut,
CodePudding user response:
In fact I think you this data format can be said to be "very specification", should be very good deal with,To read each line of content strT:
Dim strT As String
Dim CV As Double 'CV type with a String or Double, according to your need to order
Dim p1 & amp; , p2 As Long
StrT="XXXXXXXX" 'strT value for each row of data content
P1=InStr (W, strT, "")
'the value of W here, refers to the first column data FH takes up the width of the
'in the front of the data such as line 1:0 3 Spaces, plus the number 0, a total of four characters, W is 4;
'because there are several Spaces behind the numerical, W is 5, 6, but don't increase too much,
P2=InStr (InStr (p1, strT, ""), strT," ")
'in the second column of the Cloud data:
CV=Val (Mid $(strT, p1, p2, p1)) '" numerical value with the Double
CV=LTrim $(Mid $(strT, p1, p2, p1)) '" text "value in the String
CodePudding user response:
The sixth floor of the mentality is very good also, the file as a field fixed-width record to deal with,In fact, if not for artificial reading "beautiful", field separated by a comma or tabs (Tab), easier to machine processing, can even as external database, using ADO object to query,
CodePudding user response:
By the way, suddenly thought of, it's the "record" is a fixed width aligned, so for each "fields",Can directly use Mid $(strT, ps, W) in the form of the data "dig out", and that several Instr () function call is unnecessary,
Ps is begin from which characters, W is to take how many characters;
Just read the file content about, can choose the more reasonable ps and the value of W, ensure that won't put each field "effective content" removed,
Then, cooperate to Trim $() or Val () put "dig out" data processing line:
Try to use the trim "text results" removes white Spaces at the end of, if you want to "the numerical results with Val" convert numerical,
CodePudding user response:
So structured data, directTrim (mids (lines variables, location, length))
Which take not to come out?