Home > Software engineering >  VB to extract the text generator matrix and save the data
VB to extract the text generator matrix and save the data

Time:10-03

Request 1: not TXT text document types, MCA, but can use notepad to open, the inside of the need to extract the data generator matrix
Require 2: extract text documents, to choose their own text document the location of the import, extract when programming rather than directly address
Require 3: can save the data, their freedom of choice to save data text's address

Difficult point 1: mainly text documents with some characters, need to skip a few lines of characters began to extract data
Difficult point 2: hope to be able to address free choice import and save! Instead of directly input address




This is my code, but I don't know why, always remind compiler error

Option Explicit
Private Sub GetData (ByVal strFile As String)
Dim intFNo As Long
Dim strD As String
Dim isData As Boolen
Dim lngIndex As Long

StrData=https://bbs.csdn.net/topics/Space (100000) 'apply memory, 2 times greater than the maximum amount of data, because the data in the add a semicolon (;)


IntFNo=FreeFile
The Open strFile For Input As # intFNo

LngIndex=1
The Do While Not EOF (intFNo)
The Line Input # intFNo, strD

If isData Then
If strD & lt;> "& lt; & gt;" Then
Mid (strData, lngIndex, Len (Trim (strD)) + 1)=Trim (strD) & amp; ";" 'to extract data
'the data format for: data; The data; The data; The data;
'if you want to convert data: bytd=split (strdata, ";" )

LngIndex=lngIndex + Len (Trim (strD)) + 1
The Else
MsgBox "data extraction is completed, please save"
The Exit Do
End the If

The Else
If strD="& lt; & gt;" Then
IsData=https://bbs.csdn.net/topics/True
End the If
End the If
Loop

Close # intFNo
End Sub
Private strData extracted data As a String '

Private Sub Command1_Click () 'select files
On Error GoTo err

CommonDialog1. FileName=""
CommonDialog1. Filter="*. MCA | *. MCA | *. TXT | *. *", "
CommonDialog1. CancelError=True
CommonDialog1. ShowOpen 'opens the file selection dialog

If CommonDialog1. FileName & lt;> "" Then
Text1. Text=CommonDialog1. FileName 'selected FileName
GetData (Text1. Text) 'extract data
End the If
Err:
End Sub

Private Sub Command2_Click ()
On Error GoTo err

CommonDialog1. FileName=""
CommonDialog1. Filter="*. MCA | *. MCA | *. TXT | *. *", "
CommonDialog1. CancelError=True
CommonDialog1. ShowSave 'open the save file dialog

If CommonDialog1. FileName & lt;> "" Then
Text2. Text=CommonDialog1. FileName 'save the file name of the

'save the file under the code
Dim intFNo As Long
IntFNo=FreeFile
The Open Text2. Text For the Output As # intFNo

Print # intFNo, strD 'save to file
Close # intFNo

End the If
Err:
End Sub


CodePudding user response:

Well, thank you.
  •  Tags:  
  • VBA
  • Related