Home > Software engineering >  Seek help from a great god!!!!!!
Seek help from a great god!!!!!!

Time:09-16

How to use vba to realize the query string in the file and the number of rows the query to the string of files, which are listed out, don't write in the code query terms

CodePudding user response:

Read Input file
Instr search string

Under the specific usage of Google,

CodePudding user response:

Because win10 outfit vb6, written in VBS script, you can consult:
 Set fso=createobject (" scripting. Filesystemobject ") 
Curdir=fso. Getparentfoldername (wscript. Scriptfullname)
Path=fso. Buildpath (curdir, "test. TXT")

Target=inputbox (" please enter to find content: ")

Set the stream=fso. Opentextfile (path, 1, False)
The content=stream. Readall
Stream. Close

ArrLines=Split (content, VBCRLF)
For I=lbound (arrlines) To ubound (arrlines)
If InStr (arrlines (I), target) & gt; 0 Then
Msgbox "the first" & amp; (I + 1) & amp; ":" & amp; Arrlines (I)
End the If
Next

Msgbox "search!"

CodePudding user response:

 Function TT (STRB) 
Dim aa, bb, cc
Dim strFile As String
Dim intFile As Integer
Dim strData As String
StrFile="d: \ 1. TXT"
IntFile=FreeFile
The Open strFile For Input As intFile
Stra=StrConv (InputB (FileLen (strFile), intFile), vbUnicode)
The Debug. Print stra
The Close intFile
'-- -- -- -- -- -- -- -- -- -- -- -- -- --
Aa=InStr (1, stra, STRB)
Bb=Mid (stra, 1, aa)
Cc=Len (Replace (bb, vbCrLf, ""))
The Debug. Print (aa - cc) \ 2 + 1
TT=(aa - cc) \ 2 + 1
End the Function

CodePudding user response:

 Function TT (STRB, path) 
Dim aa, bb, cc, intFile, strData
IntFile=FreeFile
The Open path For Input As intFile
Stra=StrConv (InputB (FileLen (path), intFile), vbUnicode)
The Close intFile
Aa=InStr (1, stra, STRB)
Bb=Mid (stra, 1, aa)
Cc=Len (Replace (bb, vbCrLf, ""))
TT=(aa - cc) \ 2 + 1
End the Function

CodePudding user response:

Vb6, wrong

CodePudding user response:

 
FilePath file's absolute path SearchStr 'Search function to find the string
'if found a string and returns the position of the string, otherwise it returns an empty string
'as for the absolute path to the file correctly or not, whether is empty, go check

Public Function Search (As FilePath String, SearchStr As String) As String
Dim StrData As String 'temporary variables
Dim Row As Integer 'definition line
Dim Col As Integer 'definition list

Open FilePath For Input As # 1 'opens the file

Do Until (EOF) (1) 'Until the cycle (Until the end of the file)
The Row Row count + 1=Row + 1 '
Line Input # 1, StrData 'Line read in temporary variable

If InStr (StrData, SearchStr) & lt;> If found string
0 Then 'Col=InStr (StrData, SearchStr 'assignment to the Col of the position of the string
Exit the Do 'Exit loop
End the If
Loop

If Col & lt;> If found string
0 Then 'Search=CStr (Row) & amp; ", "& amp; CStr (Col) 'in the form of rows, the columns "" return a string location, convenient for later processing
End the If
Close # 1 'Close the file
End the Function
  •  Tags:  
  • VBA
  • Related