Home > Software engineering >  To extract the CSV file contents as required
To extract the CSV file contents as required

Time:10-19

My CSV file content is:
Date, $Time, PV1 p2v, PV3
03/23/12, 17:40:26, 102102102
03/23/12, 17:45:26, 110110110
03/23/12, 17:50:26, 118118118
03/23/12, 17:55:26, 125126126
03/23/12, 18:00:26, 133133133
I want to show as required in the vb text box with a column or a few columns: such as the four columns
The Date $Time p2v PV3
03/23/12 17:40:26 102 102
03/23/12 17:45:26 110 110
03/23/12 17:50:26 118 118
03/23/12 17:55:26 126 126
03/23/12 18:00:26 133 133
How to make up

CodePudding user response:

 dim as long I 
Dim STR as string
Dim the data () as string, lines () as string
Open "XXX. CSV" for input as # 1
STR=input (lof (1), 1)
Close # 1
Lines=split (STR, VBCRLF)
For I=lbound (lines) to ubound (lines)
Data=https://bbs.csdn.net/topics/split (lines (I), ", ")
If I=lbound (lines) then
Text1. Text=data (0) & amp; "" & amp; Data (1) & amp; "" & amp; Data (3) & amp; "" & amp; Data (4)
The else
Text1. Text=text1. Text & amp; VBCRLF & amp; Data (0) & amp; "" & amp; Data (1) & amp; "" & amp; Data (3) & amp; "" & amp; Data (4)
End the if
Next

CodePudding user response:

 dim as long I 
Dim STR as string, r as string
Dim the data () as string, lines () as string
Open "XXX. CSV" for input as # 1
STR=input (lof (1), 1)
Close # 1
Lines=split (STR, VBCRLF)
For I=lbound (lines) to ubound (lines)
Data=https://bbs.csdn.net/topics/split (lines (I), ", ")
If I=lbound (lines) then
R=data (0) & amp; "" & amp; Data (1) & amp; "" & amp; Data (3) & amp; "" & amp; Data (4)
The else
R=r & amp; VBCRLF & amp; Data (0) & amp; "" & amp; Data (1) & amp; "" & amp; Data (3) & amp; "" & amp; Data (4)
End the if
Next
Text1. Text=r

This can be a bit faster,

CodePudding user response:

 
Dim strData As String
Dim reg As Object, the match As Object
Open "XXX. CSV" For Input As # 1
StrData=https://bbs.csdn.net/topics/Input (LOF (1), 1)
Close # 1
The Set reg=CreateObject (" vbscript. RegExp ")
Reg. Global=True
Reg. The Pattern="(. *?) , (. *?) , (. *?) , (. *?) , ([^ \ r \ n] *)
"The Set matchs=reg. The Execute (strData)
For Each match matchs In
The Debug. Print match. SubMatches (0) & amp; ", "& amp; Match. SubMatches (1) & amp; ", "& amp; Match. SubMatches (3) & amp; ", "& amp; Match. SubMatches (4)
Next

CodePudding user response:

It can be as an external database query,

CodePudding user response:

 
Dim (a) As String, strLine As String
Open "XXX. CSV" For Input As # 1
Text1=""
Do Until EOF (1)
The Line Input # 1, strLine
A=Split (strLine, ", ")
If Ubound (a)=4 Then
A (3)="" 'Remove p2v
StrLine=Replace (Join (a, Space (1)), Space (2), Space (1))
Text1=Text1 & amp; StrLine & amp; VbcrLf
End the If
Loop
Close # 1
  • Related