Your SlideShare is downloading. ×
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

# 3.6 debugging aids

774

Published on

Published in: Technology, Art & Photos
0 Comments
0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
Your message goes here
• Be the first to comment

• Be the first to like this

No Downloads
Views
Total Views
774
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
12
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
•  Slide Notes:In this program, you first display an ellipse on the graphics window. Next, you use the SetOpacity operation of the Shapes object to set the opacity level of the ellipse. You place this code within a For…EndFor loop, to change the opacity with every single iteration. Similarly, you set the zoom level of the ellipse within the same loop.  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.  The TextWindow.WriteLine operation can help you trace the value of “i” on every iteration of the For…EndFor loop. The value of “i” gets displayed in a separate text window, enabling you to easily detect the bug and fix it.Code:GraphicsWindow.Height = 400GraphicsWindow.Width = 600Ellipse = Shapes.AddEllipse(200,200)Shapes.Move(Ellipse,200,100)For i = 1 To 5Program.Delay(1000)Shapes.SetOpacity(Ellipse,5*i) Shapes.Zoom(Ellipse,i * 0.4,i * 0.4) TextWindow.WriteLine(&quot;Value of i at this moment is &quot; + i) EndFor
• Code:Sourcepath = Program.Directory+&quot;Sourcedata.txt&quot;Destpath = Program.Directory+&quot;dest&quot;file.CopyFile(Sourcepath,Destpath)TextWindow.WriteLine(File.ReadContents(File.ReadContents(destPath+&quot;data.txt&quot;)))
• Code:Sourcepath = Program.Directory+&quot;Sourcedata.txt&quot;Destpath = Program.Directory+&quot;dest&quot;TextWindow.WriteLine(file.CopyFile(Sourcepath,Destpath))TextWindow.WriteLine(File.ReadContents(File.ReadContents(destPath+&quot;data.txt&quot;)))
• Solution:Please Note: Ensure that a folder containing the images exists at the path specified in the program.ImagePath = program.Directory + &quot;img&quot; i = 1GraphicsWindow.Width = 600GraphicsWindow.Height = 450GraphicsWindow.Top = (Desktop.Height-450) / 2GraphicsWindow.left = (Desktop.Width-600) / 2 GUI()SmallBasicImage = File.GetFiles(ImagePath) GraphicsWindow.DrawResizedImage(SmallBasicImage[i], 50, 50, 500, 300) Controls.ButtonClicked = SlideShowSub GUI GraphicsWindow.BackgroundColor=&quot;LightSlateGray&quot; GraphicsWindow.FontSize=25 nxtBtn = Controls.AddButton(&quot;&lt;&quot;,50,370) bckBtn = Controls.AddButton(&quot;&gt;&quot;,500,370) Controls.SetSize(nxtBtn, 50, 50)Controls.SetSize(bckBtn, 50, 50) EndSubSubSlideShowIfControls.GetButtonCaption(Controls.LastClickedButton) = &quot;&gt;&quot; ThenIfi &lt; Array.GetItemCount(SmallBasicImage) Theni = i + 1 images[i] = ImageList.LoadImage(SmallBasicImage[i]) GraphicsWindow.DrawResizedImage(images[i], 50, 50, 500, 300) TextWindow.WriteLine(&quot;Image Name:&quot; + SmallBasicImage[i]) EndIfEndIfIfControls.GetButtonCaption(Controls.LastClickedButton) = &quot;&lt;&quot; ThenIfi &gt; 1 Theni = i - 1 images[i] = ImageList.LoadImage(SmallBasicImage[i]) GraphicsWindow.DrawResizedImage(images[i], 50, 50, 500, 300) TextWindow.WriteLine(&quot;Image Name:&quot; + SmallBasicImage[i]) EndIfEndIfEndSub
• ### Transcript

• 1. Microsoft® Small Basic
Debugging Aids
Estimated time to complete this lesson: 1 hour
• 2. Debugging Aids
In this lesson, you will learn about:
Using the TextWindow.WriteLine operation to debug your programs.
• 3. 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.
• 4. 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.
• 5. 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.
• 6. 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.
• 7. 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.
• 8. 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.
• 9. The file may not be present at the specified source.
• 10. 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.
• 11. 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!
• 12. Let’s Summarize…
Congratulations! Now you know how to:
Use the TextWindow.WriteLine operation to debug programs.
• 13. 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.