Assume we have a form that will accept two data values via t
Assume we have a form that will accept two data values via textboxes - a string of text (the textbox, is named txtString) and a value to be searched for (txtTarget). It also has a button (named btnSeek) that will hold the code we write here. The goal is to display the starting location of the first occurrence of the target value in the string using a massage box. Provide AB statements to determine the value sought and display it via a message box. Show any variable declarations (if you Use variables, declare them).
Solution
Sub btnSeek_Click()
Dim Index As Integer = txtString.IndexOf(txtTarget)
return Index
End Sub
The above given sub function will do the required task. And here it uses the builtin function IndexOf() to find the first occurence of the substring in the given string and returns the position if any occurence is present.
public Function Find() As Integer
Sub btnSeek_Click()
Dim length As Integer = txtTarget.Length
Dim found As Integer =-1
For iPosition As Integer =0 to len(txtString)
If txtString.SubString(iPosition,length) = txtTarget Then
Return iPosition
End If
Next iPosition
Return -1
End Sub
End Function
These VB statements are used to identify the first occurence of substring in the given string
