Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSC 230 (Blum)1 Visual Basic 2005 Hello World Fall 2005 T. Blum.

Similar presentations


Presentation on theme: "CSC 230 (Blum)1 Visual Basic 2005 Hello World Fall 2005 T. Blum."— Presentation transcript:

1 CSC 230 (Blum)1 Visual Basic 2005 Hello World Fall 2005 T. Blum

2 CSC 230 (Blum)2 Start/All Programs/Microsoft Visual Studio 2005/Microsoft Visual Studio 2005

3 CSC 230 (Blum)3 This takes a long time the first time you start Visual Studio on a particular computer. I recommend starting VS on a bunch of computer in case you have to move from “your” computer some day.

4 CSC 230 (Blum)4 You may be asked about your default environment settings. My suggestion is General Development.

5 CSC 230 (Blum)5 Click on Project next to Create in the Recent Project panel or go to File/New Project

6 CSC 230 (Blum)6 Choose Visual Basic and Window Applications (not done yet).

7 CSC 230 (Blum)7 Change the Name textbox (should change the Solution Name as well). Use the Browse button to determine the project’s location.

8 CSC 230 (Blum)8 Result so far.

9 CSC 230 (Blum)9 With the “form” highlighted, go to the Properties Window and change the (Name) property (e.g. to “FrmHelloWorld”) Properties Window: If you don’t have the Properties Window showing, you can get it by going to View/ Properties Window on the menu bar

10 CSC 230 (Blum)10 Right click on the Form file shown in the Solution Explorer and select Rename from the Context sensitive menu

11 CSC 230 (Blum)11 Enter a name for the file (e.g. FrmHelloWorld.vb) containing the file containing your Visual Basic code

12 CSC 230 (Blum)12 Change the Text Property of the Form.

13 CSC 230 (Blum)13 Go to File/Save All

14 CSC 230 (Blum)14 A look at the files and folders created in My Computer.

15 CSC 230 (Blum)15 Place the mouse over the Toolbox tab, the toolbox emerges. To hold it in place click on the tack icon.

16 CSC 230 (Blum)16 Click on the Button button and then when the mouse is moved over the form it turns into a cross hairs icon. Drag from the upper left to lower right hand corner of where you would like the button placed.

17 CSC 230 (Blum)17 The Button can be moved by using the clicking on Pointer and then placing the mouse in the center (obtaining the four-arrow icon) and dragging.

18 CSC 230 (Blum)18 Resizing To change the size, move the mouse to the edge of the button to obtain the two headed icon and then drag. One can also change the Location and Size by editing the appropriate settings in the Properties Window.

19 CSC 230 (Blum)19 I prefer my properties to be alphabetized, so I clicked the Alphabetical button. You can go back to categorized by clicking that button.

20 CSC 230 (Blum)20 Change the (Name) property (e.g. to btnMessage).

21 CSC 230 (Blum)21 Naming Conventions The items placed on the form are known as “controls.” You should rename any control that you are going to have appear in your code. It is traditional to give VB control names a prefix indicating the type of control (in this case “btn” for button). The rest of the name should describe the purpose of the control and typically starts with a capital letter (in this case “Message” because clicking the button causes a message to be displayed).

22 CSC 230 (Blum)22 Change the Text property to change what the button says.

23 CSC 230 (Blum)23 Change the BackColor property of the button by clicking on the drop down list, selecting the Web tab and then choosing a color from the list.

24 CSC 230 (Blum)24 Add a label to the form.

25 CSC 230 (Blum)25 Change the (Name) property.

26 CSC 230 (Blum)26 Change the BackColor property of the label.

27 CSC 230 (Blum)27 Click in the region next to Font and then on the ellipsis button that appears.

28 CSC 230 (Blum)28 Use the Font dialog box to change the font size.

29 CSC 230 (Blum)29 Change the Text property.

30 CSC 230 (Blum)30 Move the label and add a border.

31 CSC 230 (Blum)31 Change the Visible property to False. You can still see the label in “design” but the user will not see it at run time.

32 CSC 230 (Blum)32 Go to Debug/Start Debugging on the menu

33 CSC 230 (Blum)33 The form during run time does not display the “Hello World” message. Click the Close (X) button to stop running the program.

34 CSC 230 (Blum)34 Our goal Our goal is to have the message “Hello World” display when the user clicks the button. The user’s clicking of the button is said to raise an event – the click event. We have to write code that handles that event (instructs our program what to do when the event is raised – in this case, make the message visible).

35 CSC 230 (Blum)35 Double clicking on the button takes over to Code View and creates the boiler plate for our method that will handle the button’s click event.

36 CSC 230 (Blum)36 Note some of the key words: Public, Class, Private, Sub, ByVal The name of the “class” is the name we gave our form. The name of the subroutine is btnMessage_Click derived from the control and its event.

37 CSC 230 (Blum)37 Rest of it While the name of the subroutine was derived from the control and its event, that is only a name (and “A rose by any other name …”) but the code shown above is what really associates the action of clicking the button with the execution of the code in this subroutine.

38 CSC 230 (Blum)38 Between Private Sub … and End Sub lines type the code. After typing the code name of the label and a dot, IntelliSense provides a dropdown list of label properties and events.

39 CSC 230 (Blum)39 Type Visible or find it on the drop down list, then type “=,” after that IntelliSense provides another drop down list.

40 CSC 230 (Blum)40 Line of code and a comment (anything after an apostrophe). Comments do not affect execution of code. They help explain code.

41 CSC 230 (Blum)41 Comments are also used to take credit for code. Always have a comment with your name at the top of every program submitted for credit.

42 CSC 230 (Blum)42 The running program after the button has been clicked.


Download ppt "CSC 230 (Blum)1 Visual Basic 2005 Hello World Fall 2005 T. Blum."

Similar presentations


Ads by Google