I am working on a simple search program to find the position of a substring within a larger string. The code is at the end.
There are three text boxes:-
txtLargeString: holds the contents of a large text file (160,000 characters) (large string)
txtSearch: holds the short string I'm searching for (search string)
txtResult: holds the position number of the search string within the large string.
This works fine until the position of the search string exceeds about 65,536 (Integer range ??)
I've therefore declared the position variable as type Long but still, if position is > ~65K, a 0 is returned.
Is the problem to do with the InStr function, does InStr only return an integer. Any suggestions?
Private Sub cmdtest_Click()
Dim flag As String
Dim position As Long
flag = txtSearch.Text
position = InStr(txtLargeString.Text, flag)
txtResult.Text = position
End Sub
There are three text boxes:-
txtLargeString: holds the contents of a large text file (160,000 characters) (large string)
txtSearch: holds the short string I'm searching for (search string)
txtResult: holds the position number of the search string within the large string.
This works fine until the position of the search string exceeds about 65,536 (Integer range ??)
I've therefore declared the position variable as type Long but still, if position is > ~65K, a 0 is returned.
Is the problem to do with the InStr function, does InStr only return an integer. Any suggestions?
Private Sub cmdtest_Click()
Dim flag As String
Dim position As Long
flag = txtSearch.Text
position = InStr(txtLargeString.Text, flag)
txtResult.Text = position
End Sub