Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems using Instr with very large strings??

Status
Not open for further replies.

ALSav

Technical User
Feb 21, 2001
66
GB
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
 
VB help says Instr Returns a Variant (Long) specifying the position of the first occurrence of one string within another.

One way around it is to break the large string into smaller parts.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top