View stunning SlideShares in full-screen with the new iOS app!Introducing SlideShare for AndroidExplore all your favorite topics in the SlideShare appGet the SlideShare app to Save for Later — even offline
View stunning SlideShares in full-screen with the new Android app!View stunning SlideShares in full-screen with the new iOS app!
Microsoft® Small Basic Debugging Aids Estimated time to complete this lesson: 1 hour
Debugging Aids In this lesson, you will learn about: Using the TextWindow.WriteLine operation to debug your programs.
Debugging Even a minor bug in a program can defeat the efforts of the programmer! Debugging is a method of detecting and resolving bugs in your computer program. Every programmer develops the skill to detect bugs and debug his or her program. While working on large programs, programmers write debugging support code that is not included in the final program. This is to determine the point where a program fails to run.
TextWindow.WriteLine As a Debugging Helper So how can you debug programs in Small Basic? To debug your program, you can use the TextWindow.WriteLine operation. This operation acts as a debugging helper, and it provides information to help debug your program.
TextWindow.WriteLine As a Debugging Helper In this program, you first display an ellipse on the graphics window. In case your program does not run as expected, you need to debug it! This is when you can use the TextWindow.WriteLine operation as a debugger. It can help you trace the value of “i” on every iteration of the For…EndFor loop. The value of “i” is displayed in a separate text window, enabling you to easily detect a bug and fix it. Let’s look at an example that uses the TextWindow.WriteLine operation for debugging.
TextWindow.WriteLine As a Debugging Helper Oh! The image you requested is not visible on the graphics window. It’s time to debug your code! Now, let’s use the TextWindow.WriteLine operation in another program and see how it can help you debug the program. In this example, you use the Flickr object to download a photo from www.flickr.com and display it on the graphics window.
TextWindow.WriteLine As a Debugging Helper One of the possibilities could be unavailability of an Internet connection or no access to the website. To check this possibility, you can use the TextWindow.WriteLine operation for displaying the path of the image from the website. If the Internet connection is working fine, the path of the image will be displayed in the text window. Otherwise, the text window will not display any path. As you can see, the text window is not displaying the path of the image, which means you are not connected to the Internet.
TextWindow.WriteLine As a Debugging Helper You may not see the contents of the file in the text window because:
The specified source or destination may be incorrect.
The file may not be present at the specified source.
The name of the specified file may be incorrect.
Now, let’s write a program to copy a file and display its contents in the text window. Now how do we detect the error? It’s time to debug your code once again… In this example, if the CopyFileoperation is successful, the text window displays the contents of the file.
TextWindow.WriteLine As a Debugging Helper Let’s use the TextWindow.WriteLine operation to detect the error. You can modify your program and use TextWindow.WriteLine to display the return value of the CopyFile operation in the text window which will either be SUCCESS or FAILED. So, if your program is unable to run due to the CopyFile operation error, you immediately know about it!
Let’s Summarize… Congratulations! Now you know how to: Use the TextWindow.WriteLine operation to debug programs.
It’s Time to Apply Your Learning… A program creates a slide show of images in the graphics window. All these images are stored in a local folder. With every mouse click, a new image is displayed in the graphics window. Use the TextWindow.WriteLine operation as a debugging helper by displaying the path of each image in the text window.