1 / 43

Visual Basic 2005 Hello World

Step-by-step guide to creating a Windows application, including renaming controls, setting properties, handling events, and writing code in Visual Basic 2005.

tsimon
Download Presentation

Visual Basic 2005 Hello World

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Visual Basic 2005Hello World Fall 2005 T. Blum

  2. Start/All Programs/Microsoft Visual Studio 2005 Beta 2/Microsoft Visual Studio 2005 Beta 2

  3. First time: select option you are most likely to use and click Start

  4. Click on Project next to Create in the Recent Project panel or go to File/New Project

  5. Choose Windows Application as the Template and give the project a name (e.g. MyHelloWorld). Click OK

  6. Result so far.

  7. 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

  8. Right click on the Form file shown in the Solution Explorer and select Rename from the Context sensitive menu

  9. Enter a name for the file (e.g. FrmHelloWorld.vb) containing the file containing your Visual Basic code

  10. Change the Text Property of the Form.

  11. Go to File/Save All

  12. Save Project Dialog box: Name project and solution and choose location for them (clicking Browse opens the Project Location dialog box)

  13. Click Browse, then use the Project Location dialog box to choose a place for the project. Then click Open.

  14. Click Save on the Save Project dialog box.

  15. A look at the files and folders created in My Compter .

  16. Place the mouse over the Toolbox tab, the toolbox emerges. To hold it in place click on the tack icon.

  17. 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.

  18. 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.

  19. 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.

  20. I prefer my properties to be alphabetized, so I clicked the Alphabetical button. You can go back to categorized by clicking that button.

  21. Change the (Name) property (e.g. to btnMessage).

  22. 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).

  23. Change the Text property to change what the button says.

  24. 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.

  25. Add a label to the form.

  26. Change the (Name) property.

  27. Change the BackColor property of the label.

  28. Click in the region next to Font and then on the ellipsis button that appears.

  29. Use the Font dialog box to change the font size.

  30. Change the Text property.

  31. Move the label and add a border.

  32. Change the Visible property to False. You can still see the label in “design” but the user will not see it at run time.

  33. Go to Debug/Start Debugging on the menu

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

  35. 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).

  36. 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.

  37. 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.

  38. 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.

  39. 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.

  40. Type Visible or find it on the drop down list, then type “=,” after that IntelliSense provides another drop down list.

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

  42. 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.

  43. The running program after the button has been clicked.

More Related