Question: Thanks for the help!Visual Basic: Can you convert the code prvided that locates charccters in a string located in a label and returns the location.

Thanks for the help!Visual Basic: Can you convert the code prvided that locates charccters in a string located in a label and returns the location. What I need to do is open an external txt file, search it for specific characters that are hard coded into the program (j o h n d u t t), and return them to a label on an existing form. So the program starts, the formload opens a txt file, searches for the the hard coded characters ( j o h n d u t t) and form a string that is placed on the form's label: [John Dutt]. The txt file only needs to contain all the chacacters of the alphabet. It could be any external txt file the source is not important. It could just be (abcdefghijklmnopqrstuvwxyz) or part of a story, etc. as log as it contains all 26 characters. The existing code follows:

' Determine wether the string index is numeric.

If IsNumeric(txtStartIndex.Text) Then

'Determine wether a string to search for was entered.

If txtToFind.Text.Length > 0 Then

'Get the starting index for the search.

intStartIndex = CInt(txtStartIndex.Text)

'Search for the substring.

intFoundIndex = lblString.Text.IndexOf(txtToFind.Text, intStartIndex)

'Indicate wether the search string was found.

If intFoundIndex = -1 Then

lblResults.Text = "The string was not found."

Else

lblResults.Text = "The string was found at index " & intFoundIndex

End If

Else

'Display an error message for a empty search string.

MessageBox.Show("Enter a string to search for.")

End If

Else

'Display an error message for a non-numeric index.

MessageBox.Show("The index must be a number.")

End If

End Sub

Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click

' Close the form.

Me.Close()

End Sub

Thanks for the help!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!