programming 101 | Programming 101

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    1 Favorite

    programming 101 | Programming 101 - Presentation Transcript

    1. CLASS #1: FIRST STEPS IN VBE 2008 Covers topics 1.a, 1.b, and 1.c UNDERSTANDING THE VBE ENVIRONMENT Visual Basic .NET Express 2008 (VBE for short) is an Integrated Development Environment (IDE). This means that you can control each step of the application creation process from design to deployment without ever leaving VBE. When you open VBE, you will see something like this: Since I will be using Visual Studio (VS), the professional version of VBE, some text on my screen may differ from yours. For our purposes, this will not affect us. CREATING A NEW PROJECT The way that VBE keeps track of the programs you create is through projects. To create a new program, we therefore need to create a new project. Click on FileNew Project… The following dialog should come up: 1 © 2008 SilverSpark. All Rights Reserved.
    2. You will not have as many options as the screenshot above. Again, this is due to the difference between VBE and VS. The “Windows Forms Application” circled in red above is the option we will always use. The name textbox contains the name of the future project. I recommend changing it for something descriptive, for example “CookieStuffer” instead of “Application1”. Clicking on OK will create the new project. VISUAL GUIDE TO THE IDE Once you are working on a project, your screen will look something like this: Clicking on Toolbox (the black circle) will reveal the Toolbox panel, used to create controls: 2 © 2008 SilverSpark. All Rights Reserved.
    3. Tip: Click here to auto-hide the ToolBox Panel, a very useful feature when creating controls. In the red circle is the current form. Roughly speaking, a Form is what VB calls windows. You can add controls to a form, as we will see later. In the blue circle (top right-hand corner) is a list of the files contained in the current project. Each form has its own file. We can also put algorithms that don’t belong to any specific form in a Module. There are other types of files but they are beyond the scope of this course. In the purple circle (bottom right-hand corner) is a list of properties of the currently selected object. In this case, the currently selected object, and indeed the only object, is Form1. A Property of an object is simply an attribute or characteristic of that object. For example, the name property of Form1 refers to its name, that is, “Form1”. Note that the name of a control cannot include spaces or special characters (apart from the underscore). In the brown circle (top center) is a triangular button. This button allows you to run your program. CREATING CONTROLS A control is, generally speaking, something on the form that the user can interact with. Examples of controls are textboxes, buttons, labels (basically text that can’t be edited by the user), and scrollbars. To create a control, click on ToolBox if the ToolBox panel isn’t visible. Then, choose the control you want to add from the pane. You may have to click on Common Controls (+) to reveal the most commonly used controls (the only ones we will use) if they aren’t already visible. Click on the desired control. If the ToolBox panel overlaps the form you want to add the control to, click on Auto-Hide (see previous section). To create the control, simply drag the control across the Form to size it or double-click to create a default- sized control. 3 © 2008 SilverSpark. All Rights Reserved.
    4. Tip: You can copy and paste controls or groups of controls with the edit menu or using keyboard shortcuts CTRL+C, CTRL+V. Controls can be used to display information to the user (output), retrieve information from the user (input), or, generally speaking, to let the user control the behavior of the program. Common types of controls and their uses include: Control Use Button For the user to effect an action TextBox For the user to input text Label To display text to the user without him being able to edit it CheckBox To let the user choose between a fixed number of options that are not mutually exclusive RadioButton To let the user choose between a fixed number options that are mutually exclusive ListBox To display a variable number of elements to the user, or to let the user choose between a variable number of mutually exclusive or mutually- nonexclusive elements ProgressBar To display the progress of a long task to the user Exercise #1.1 Create one of each of the controls mentioned in the previous table. You will be surprised at how many of these you will recognize! PROPERTIES AND METHODS We have already seen what a property is in the previous section. A method of an object is an action that can be performed by that object. For example, a Form can close itself. This is intuitively called the Close() method. We will see what the parentheses mean later. We can cause an object to perform an action by using the following syntax: [Object].[Method]. The dot means that the method belongs to the object. This is useful, for example if we have several objects of the same type, we may not want all of them to perform the same action. Continuing with the form example, if we wanted Form1 to close, we would simply write Form1.Close(). 4 © 2008 SilverSpark. All Rights Reserved.
    5. Don’t worry about where to write this code, we will see that later. For now, the important thing is to understand how methods can be invoked using the above syntax. The value of a property can also be set or obtained using the similar syntax: [Object].[Property]. Using the above example, suppose that we wanted to set Form1’s window caption to “BlackHat” instead of “Form1”, like it is now. Then we would write Form1.Text = \"BlackHat\". Common properties that are shared by most objects and that may be of interest to us include : Property name Description of Property Name The name of the control Height The height of the control in pixels Width The width of the control in pixels Left Distance in pixels from left edge of the form to left edge of control Top Distance in pixels from top edge of the form to top edge of control Forecolor The foreground color of the control. Usually refers to font color. BackColor The background color of the control Text The text written on the control (not all controls have this) Size This property combines width and height. Its syntax is [Width];[Height] Exercise 1.2 – Creating an interface Create a login form that looks like this: Hint #1: You will have to set the Text property using the Property panel (see “Visual Guide to the IDE” section). Hint #2: You can copy-paste controls to save time. 5 © 2008 SilverSpark. All Rights Reserved.
    6. EVENTS An event, like the name suggests, is a VB word for “something happened”. This can be as simple as a user clicking on a button or as sophisticated as an RSS feed being updated. Handling events related to a particular control is literally a matter of double-clicking. To handle the event, double-click on the control in question. This will bring up the code file of the form in which the event is and will create an event handler for the default event of that object (the event that VB deems is most likely to be called). For example, in Exercise 1.2, suppose we double-click on the “Cancel” button (which has name property Button2). Then the following would come up: You don’t need to worry about understanding all that code for now. Basically, all it says is that any code we want to put in Button2_Click should go between the line beginning with “private” and the line that says “End Sub”. This code will only be executed when Button2 is clicked. IN THE NEXT CLASS… We will learn how to interpret the code in the previous screenshot, and we will learn how to write our own code and where to write it. You will create your first working application (a login program) and learn the basics of VB .NET programming. WHERE TO FIND MORE INFORMATION ON THIS SECTION Clicking on HelpHow Do I? in VBE will bring up a variety of topics. Also, consider the following websites: 1. VB: A “From the Ground up Tutorial”: http://visualbasic.about.com/od/learnvbnet/a/LVBE_L1.htm 2. MSDN (Microsoft’s official reference): http://msdn.microsoft.com/en-us/vbasic/default.aspx 6 © 2008 SilverSpark. All Rights Reserved.
    SlideShare Zeitgeist 2009

    + first lastfirst last Nominate

    custom

    235 views, 1 favs, 0 embeds more stats

    Programming 101 - Learn Programming vb.net
    Program more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 235
      • 235 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 1
    • Downloads 0
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories