im trying to make a small app opens a title file, then searches it for a certain string & gives you total of occurences.
this is for a home program and its doing my head in ive searched all over the net for best way of doing it & no does it the way i need
i am very new to VB6, many years ago i did it But trying to get back into it now then move on to somthing more complex like c++
the main problem is sub searchFile()
it will only ever say 1 occurence but i dont no why.
my code
this is for a home program and its doing my head in ive searched all over the net for best way of doing it & no does it the way i need
i am very new to VB6, many years ago i did it But trying to get back into it now then move on to somthing more complex like c++
the main problem is sub searchFile()
it will only ever say 1 occurence but i dont no why.
my code
Code:
Option Explicit
Dim SearchStr As String
Dim Loadfile As String
Dim SearchFileContent As String
Dim found As Integer
Dim counter As Integer
Dim lengthofstring As Integer
Dim target As String
Private Sub Browse_Click()
On Error GoTo Error
Call OpenBrowseFile
Exit Sub
Error:
Call ErrorHandle
End Sub
Sub ErrorHandle()
MsgBox "An Error Happened", 2, "An Error Occured"
End Sub
Sub OpenBrowseFile()
'On Error GoTo Error:
OpenSaveDialog.Filter = "Text (*.txt) | *.txt"
OpenSaveDialog.InitDir = "c:\"
OpenSaveDialog.ShowOpen
If OpenSaveDialog.FileName = "" Then
' User canceled.
Else
' The FileName property contains the selected file name.
LoadPathName.Text = OpenSaveDialog.FileName
End If
Loadfile = LoadPathName.Text
Open Loadfile For Input As #1
SearchFileContent = Input(LOF(1), #1)
Close #1
End Sub
Private Sub StartSearch_Click()
TextFileContents.Text = SearchFileContent
Call SearchFile
Text1.Text = counter
End Sub
Sub SearchFile()
target = "test1"
lengthofstring = 0
counter = 0
found = 1
Do Until lengthofstring = 10
If InStr(1, SearchFileContent, target) = found Then
counter = counter + 1
found = found + 1
Else
End If
lengthofstring = lengthofstring + 1
Loop
End Sub