Download presentation
Presentation is loading. Please wait.
1
Hints on Chapter 5
2
Exercise 1 Read pp 236-240 2 times. It contains all needed info.
The code is fairly the same as listing 5-4 What do those numbers mean? …read it. That should be all you need to know. By the way: e. is the event, in this case, of clicking on the link. The computer will help you by creating that subroutine when you click the linklabel. The links become link 0 and link 1, which is wat IndexOf(e.Link) determines.
3
Exercise 2 Be careful of endless loops Save regularly
If your program freezes, your choices in order: VB.net stop button Ctrl-break Ctrl-alt-delete, end task for your project
4
Exercise 2 step by step Read pages 230 - 232 Make your form with
Rich Text Box Button Change the property to make the rich text box say the funny phrase. Insert the code from listing 5-3 that is most appropriate Modify it to make it italic rather than bold Test your program…one instance should be italic. Once that works…continue…
5
Exercise 2 step by step Why are you still using fntBold? Give yourself a pat on the back if you already changed it to fntItalic, a meaningful name. fntItalic only needs to be Dimensioned once, even though we will use it for several instances of the font being used. Now that your project works for one instance we can prepare for multiple occurrences….
6
Exercise 2 continued According to page 230, the Find() method will return a value, so instead of simply making the method call, RichTextBox1.Find(“your desired text”) you will need to get the return value of that method. So let’s dim a variable intPosition that tells us where the desired text was found. Then assign the method’s return value to intPosition (simply assign what is on the right of the equal sign to what is on the left, as we have done often). Add Debug.WriteLine(intPosition) so we can spy on the value of intPosition Run your program. Look at the output window at the bottom of your screen. It will tell you the value of intPosition
7
The special Find options
Now, change our Find method using the code from page 232: The string is the same as before Start is replaced by intPosition Options….let’s just use RichTextBoxFinds.None as we have no special options SAVE YOUR PROGRAM AGAIN BEFORE CREATING YOUR DO LOOP
8
Continuing… Now, if you already are trying to fit Do loops in there, you may be eating too much of the elephant at once. Now let’s “do our do”… Surround your 2 lines of code that occur more than once in your do loop. The condition of our Do loop has something to do with the text-not-found value, right? It keeps going until the desired text is no longer found. Did I say run it? Oh no! You may have found an endless loop! Before you run it, you will need to add intPosition +=1 to add one to your position. Otherwise it keeps finding the same text…FOREVER!!!!! Since you are adding 1 to intPosition, this may change the value you choose for your loop condition.
9
And finally… Save your program and run it.
If your program freezes you are in an endless loop. Try the stop button. The computer is doing the same thing over and over and over and over
10
And when it finally works…
You may need to change some things about your loop if it is endless CONGRATULATIONS !
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.