Top Banner
Visual Basic C++ Diane Zak
93

Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

Dec 29, 2015

Download

Documents

Coral Haynes
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

Visual Basic C++

Diane Zak

Page 2: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

Microsoft© Small (But Powerful) Basic

Presented by Diane Zak

Page 3: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

1GB Silicone Wrist Band Flash Drive

You are welcome to take them home!

Page 4: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

OverviewWalk-throughs Code snippets ActivitiesWrap-up

Page 5: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

OVERVIEW

Page 6: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

What is it? 1. Language2. IDE3. Libraries

Created by: Vijaye Raji at Microsofthttp://smallbasic.com/

Page 7: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

Language Variables Assignment statements Concatenation, arithmetic , relational, logical operators Mathematical functions Graphics (shapes and controls) If statements, For and While loops Arrays Sequential access file processing Text (string) manipulation methods Sub procedures and events

Page 8: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

IDE

Intellisense

Help

Page 9: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

LibrariesArray MouseClock NetworkControls ProgramDesktop ShapesDictionary SoundFile StackFlickr TextGraphicsWindow TextWindowImageList TimerMath Turtle

Page 10: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

1. Language2. IDE3. Libraries

Page 11: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

Requirements? Small Basic

Windows XP, Vista, 7

.NET Framework 3.5

Page 12: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

Why would I want to learn it?

Page 13: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

Fun and easy way to introduce programming

Intro to Computers

Intro to Programming

College Freshmen Day

High School Recruitment

Page 14: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

How can I teach it?

Page 15: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

Turtle ObjectTextWindowsequence onlyor combined with selection

Page 16: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

TextWindowsequence, selection, repetition, sound, and random numbers

Page 17: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

GraphicsWindowand Turtlesequence onlyor combined with selection and repetition

Page 18: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

GraphicsWindowand Turtlesequence only

Page 19: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

GraphicsWindowsequence and repetition

Page 20: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

GraphicsWindowsequence, selection, repetition, random numbers, and counters

Page 21: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.
Page 22: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

GraphicsWindowsequence, selection, arrays, controls, and procedures

Page 23: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

GraphicsWindowsequence, selection, arrays, controls, and procedures

Page 24: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.
Page 25: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.
Page 26: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

Walk-throughs

Page 27: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

TextWindow

Page 28: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.
Page 29: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.
Page 30: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.
Page 31: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.
Page 32: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.
Page 33: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.
Page 34: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.
Page 35: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.
Page 36: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.
Page 37: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.
Page 38: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

On your own:

1.Enter a TextWindow.Write statement that displays the message “Gallons: ”

2.Enter a TextWindow.ReadNumber statement that assigns the user’s input to the gallons variable

Page 39: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.
Page 40: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

Arithmetic operations

+ addition (also can be used for concatenation)

– subtraction* multiplication/ division

Math.Power exponentiationMath.Floor integer division

Page 41: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

mpg = miles / gallons

Page 42: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

TextWindow.WriteLine(mpg)

Page 43: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.
Page 44: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.
Page 45: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

Math object’s Round method

mpg = Math.Round(mpg)

Page 46: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

String concatenation operator

+"Miles per gallon: " + mpg

Page 47: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.
Page 48: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.
Page 49: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.
Page 50: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

Publish

Page 51: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

Publish

Page 52: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.
Page 53: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

Import

Page 54: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.
Page 55: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

If Statement

If condition Thenstatements

[ElseIf condition Thenstatements]

[Elsestatements]

EndIf

Page 56: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

If mpg > 30 Then TextWindow.WriteLine("Great")Else TextWindow.WriteLine("Not great")EndIf

Page 57: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

Save using Mpg and then run. Then publish again.

Page 58: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.
Page 59: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

Graduate to Visual Basic

Page 60: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

Turtle

Page 61: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

1. Close the mpg program.2. Open a new document.3. Save the new document as

MyFirstTurtle.

Page 62: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

1. Create a 10 line program using the following commands. Keep in mind that the default height and width of the GraphicsWindow is 442 and 624 pixels, respectively.

2. Save and then run.

Turtle.Speed = number from 1 through 10Turtle.Move(number of pixels)Turtle.MoveTo(x, y) Turtle.TurnLeft()Turtle.TurnRight()

Page 63: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

1. Close the MyFirstTurtle program.2. Open the Hi.sb file contained in the

Class folder.3. Run the program.

Page 64: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.
Page 65: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

1. ' Lines 2 through 8 will center the GraphicsWindow2. GraphicsWindow.Hide()3. gwH = 4004. gwW = 2255. GraphicsWindow.Left = (Desktop.Width - gwW) / 26. GraphicsWindow.Top = (Desktop.Height - gwH) / 27. GraphicsWindow.Height = gwH8. GraphicsWindow.Width = gwW

10. ' Line 11 displays text on the title bar11. GraphicsWindow.Title = "Hi"

13. ' Line 14 shows the GraphicsWindow14. GraphicsWindow.Show()

16. ' Line 17 sets the Turtle's speed17. Turtle.Speed= 9

19. ' position turtle and draw left vertical line in H20. Turtle.X = 5021. Turtle.Y = 35022. Turtle.Move(250)

Page 66: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

24. ' reposition turtle and draw right vertical line in H

25. Turtle.PenUp()26. Turtle.X = 10027. Turtle.Angle = 18028. Turtle.PenDown()29. Turtle.Move(250)

Page 67: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

31. ' reposition turtle and draw horizontal line in H

32. Turtle.PenUp()33. Turtle.Y = 20034. Turtle.TurnRight()35. Turtle.PenDown()36. Turtle.Move(50)

Page 68: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

38. ' reposition turtle and draw vertical line in i

39. <lift the pen>40. <set the turtle’s X property to 150>41. <set the turtle’s Y property to 350>42. <turn the turtle to the right>43. <put the pen down>44. <move the turtle appropriately>

Page 69: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

38. ' reposition turtle and draw vertical line in i

39. Turtle.PenUp()40. Turtle.X = 15041. Turtle.Y = 35042. Turtle.TurnRight()43. Turtle.PenDown()44. Turtle.Move(200)

Answer

Page 70: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

Drawing Shapes

46. ' draw circle above vertical line in i47. <use the GraphicsWindow’s DrawEllipse method (Hint: use 145 and 100 for X and Y, and use 10 for the width and height>

Page 71: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

Drawing Shapes

46. ' draw circle above vertical line in i47. GraphicsWindow.DrawEllipse(145, 100, 10, 10)

Answer

Page 72: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

1. Complete Lines 49 through 65.2. Save and then run.

Page 73: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

Images and Sound

Page 74: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

1. Close the Hi program.2. Open the PicViewer.sb file

contained in the Class folder.3. Run the program to see the effect

of the existing code.

Page 75: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

13. ' Lines 14 through 16 load the images and assign names to each14. imgBirds = ImageList.LoadImage(Program.Directory + "\birds.jpg")15. imgCat = ImageList.LoadImage(Program.Directory + "\cat.jpg")16. imgTheEnd = ImageList.LoadImage(Program.Directory + "\TheEnd.jpg")

18. ' Lines 20 through 22 make each loaded image a Shape object that can19. ' be moved, animated, shown, hidden, or rotated20. birds = Shapes.AddImage(imgBirds)21. cat = Shapes.AddImage(imgCat)22. theEnd = Shapes.AddImage(imgTheEnd)

Page 76: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

24. ' Lines 25 through 27 position each Shape object at the right edge of the GraphicsWindow25. Shapes.Move(birds, 650, 0)26. Shapes.Move(cat, 650, 0)27. Shapes.Move(theEnd,650, 0)

29. ' Lines 31 through 33 hide each Shape object (this is necessary because the30. ' AddImage method automatically displays them on the GraphicsWindow31. Shapes.HideShape(birds)32. Shapes.HideShape(cat)33. Shapes.HideShape(theEnd)

35. ' Line 36 shows the GraphicsWindow36. GraphicsWindow.Show()

Page 77: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

38. ' enter the code to play a wav file named PicViewer.wav

39. <Use the Sound object’s Play method, the Program object’s Directory method, and the concatenation operator to play the "\PicViewer.wav" file.>

Page 78: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

38. ' enter the code to play a wav file named PicViewer.wav39. Sound.Play(Program.Directory + "\PicViewer.wav")

Answer

Page 79: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

41. ' Lines 42 through 44 show the birds Shape object, animate it, and then delay the program

42. Shapes.ShowShape(birds)43. Shapes.Animate(birds, -500, 0, 6000)44. Program.Delay(4000)

Page 80: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

1. Complete Lines 46 through 54.2. Save and then run.3. For an additional challenge,

complete the DIFFERENT VERSION section.

Page 81: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

Events and

Sub Procedures

Page 82: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

1. Close the PicViewer program.2. Open a new document.3. Save the new document as Hello.

Page 83: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

1. Enter the following two lines of code:txtName = Controls.AddTextBox(100, 50)btnHello = Controls.AddButton("Hello", 100, 100)

2. Save and then run.

Page 84: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

1. Enter Controls followed by a period.2. Press the down arrow until the ButtonClicked

event is selected.

Page 85: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

Finish the statement as follows:

Controls.ButtonClicked = OnButtonClick

Page 86: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

Now we need to create the OnButtonClick event procedure. Enter the following lines of code:

5. Sub OnButtonClick6. myName = Controls.GetTextBoxText(txtName)7. GraphicsWindow.ShowMessage(myName, "Name Entry")8. EndSub

Page 87: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

1. Save and then run.2. Click the text box and then type your

name.3. Click the Hello button.

Page 88: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.
Page 89: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

ActivitiesNow it’s time for you to have some

fun!

Page 90: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

Take your pick:

1.Create the Space Invaders game using the handout provided to you.2.Look in the EXE folder on your flash drive for a program you might like to create. Then, locate the partially completed .sb file on your flash drive. The FolderContents.doc file on your flash drive provides some additional information about the program.3.Create your own Small Basic program.4.Check out the Coin Toss.sb program in the Coin Toss folder.5.Import one or more of the following programs/games:

XHX455 (Click Shapes) KXM316-0 (Calculator)CBX615 (Flower) LWL206-3 (Music Notes)MDJ923 (Paddle Game) PMT149 (Bouncing Balls)

Page 91: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

Thank you for coming!

Page 92: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

I hope you enjoyed the presentation

Page 93: Visual BasicC++ Diane Zak. Microsoft © Small (But Powerful) Basic Presented by Diane Zak.

Have a great day!