final exam help please

doro40282

Newcomer
Joined
Dec 12, 2003
Messages
6
Hello, I am new to vb.net. This is my second small final exam project for class. I have to have a text box with some text in it. Then I have put a word in a field such as box and then in anothe field I have to enter another word such as rocks. What I then have to do is hit a button that will search the text in the textbox for the word box and replace it with the word rocks for example. Any one have any ideas. I am pretty inexperienced at programming.

I know I have to use strings though. I looked at the strings replace method but I got confused. Im not sure what the code should look like any help would be greatly appreciated.
 
Should I somehow put the contents of the textbox into a string. then use a for statement or something with a sunstring (x. s.length) so that it seaches for the same length as the word I want to change. or textbox1.text.substring (0, x-1) Sorry if this sounds bad I am pretty inexperienced at programming but I find it very interesting. I think this was what my teacher was talking about,
 
You don't have to do anything like you said. Do what Robby showed you. In that example, TextBox1 is the TextBox which you search for the word. It uses the Replace method of it to replace each word that you specify for the first argument with the word you specify in the second argument. Then it returns the modified string. Put that code in the Click event of your button. What you also have to do is substitute the hardcoded values with the values from the textboxes which specify what to look for, and with what to replace it.
 
How about sending your search text to a function that finds the position within the text box starting from the beginning! Here is an example of the function;


Public Function FindText(ByVal strText As String, ByVal intStartingPoint As Integer) As Integer
'Initialize return value to false by default
Dim returnValue As Integer = -1
Dim intIndexToText As Integer
'Ensure that search string has been specified and a valid starting point
If strText.Length > 0 And intStartingPoint >= 0 Then
'Obtain location of the search string
intIndexToText = rtbViewer.Find(strText, intStartingPoint, RichTextBoxFinds.MatchCase)
'Determine whether the text was found
If intIndexToText >= 0 Then
returnValue = intIndexToText
End If
End If
Return returnValue
End Function

You can then call the function again starting at an point past the last occurrance.
 
Back
Top