Getting started Loading it up

Slides:



Advertisements
Similar presentations
Mike Scott University of Texas at Austin
Advertisements

Prof. Yitzchak Rosenthal
Working with Intrinsic Controls and ActiveX Controls
VISUAL BASIC Visual Basic is derived from the Basic language (Beginner’s All-Purpose Symbolic Instruction Code) Visual Basic uses an event-driven programming.
CMPT 100 : INTRODUCTION TO COMPUTING TUTORIAL #5 : JAVASCRIPT 2 GUESSING GAME By Wendy Sharpe 1.
How to Debug VB .NET Code.
To type the VB code behind the command button (named cmdPush), Double-Click on the Push Me (caption) command button As a result the Visual Basic Code Window.
Fundamentals of Programming in Visual Basic 3.1 Visual basic Objects Visual Basic programs display a Windows style screen (called a form) with boxes into.
Adding Controls to User Forms. Adding Controls A user form isn’t much use without some controls We’re going to add controls and write code for them Note.
Chapter 8: String Manipulation
Visual Basic Chapter 1 Mr. Wangler.
Variables and Constants
05/09/ Introducing Visual Basic Sequence Programming.
Hello World In C++ and Microsoft Visual C++. Directions to begin a project 1. Go to All Programs 2. Open Visual Studio C++ 3. Click on New Project 4.
Chapter 1 P. 1 Writing Windows applications with Visual Basic Figure 1.1 The first program works as follows: (These operations can be performed in any.
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
Introduction to Programming Using Visual Basic 6.0
Chapter 3 Introducing Visual Basic.NET. 3.1 Visual Basic.NET Windows Programming -Used to create Windows, Web, and Console applications -Uses predefined.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
06/10/ Working with Data. 206/10/2015 Learning Objectives Explain the circumstances when the following might be useful: Disabling buttons and.
Programming Examples to Accompany Structure Topic Please use speaker notes for additional information!
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
Copyright © 2001 by Wiley. All rights reserved. Chapter 2: Using Visual Basic to Create a First Project Getting Started with VB Development Environment.
Chapter 9 - VB.Net by Schneider1 Chapter 9 – Additional Controls and Objects 9.1 List Boxes, Combo Boxes, and the File-Opening Control The List Box Control.
 Application – another name for a program.  Interface – is what appears on the screen when the application is running.  Program Code – is instructions.
Microsoft Visual Basic 2005 CHAPTER 4 Variables and Arithmetic Operations.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
Working with the VB IDE. Running a Program u Clicking the”start” tool begins the program u The “break” tool pauses a program in mid-execution u The “end”
Chapter Two Creating a First Project in Visual Basic.
Chapter 2 P. 1 Introducing more controls (on the Toolbox) (Fig. 2.1) - Text box - Frame - Option button - Check box - Image Example P. 44 Figure 2.2 Message.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.
Data Types and Variables. Data Type! Computers are all about Data! Data can be in the form of Text Dates Sounds Pictures.
Variables & Function Calls. Overview u Variables  Programmer Defined & Intrinsic  Data Types  Calculation issues u Using Functions  The val() function.
1 Advanced Computer Programming Lab Calculator Project.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
1 Visual Basic Part I - A tool for customizing your program Principles of GIS
COMPUTER PROGRAMMING I 3.02 Apply Properties Associated with the Controls.
Lesson 1. Security At the menu bar at the top you will see the word Tools. Click your mouse on Tools scroll down to Macro. Move the Mouse over and down.
CECS 5020 Computers in Education Visual Basic Variables and Constants.
31/01/ Selection If selection construct.
BBT 10 Visual Basic 03 Enrichment. Tip Before creating any files for your project, first create a new folder Save all of your files in the folder Pieces.
110 E-1 Variables, Constants and Calculations(2) Chapter 3: Operations on variables, scope of a variable, formatting data Doing Arithmetic.
Slide 1 Controls v Control naming convention –Label: lblName –Command Button: cmdName –Text Box: txtName.
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
Controlling Program Flow with Decision Structures.
Microsoft Visual Basic 2012 CHAPTER FIVE Decision Structures.
Microsoft Visual Basic 2012 CHAPTER FOUR Variables and Arithmetic Operations.
Introduction to Programming Using Visual Basic 6.0 Cheryl Klimack
More Visual Basic Code: if-then-else, for loops Controls: Multiple forms, List Boxes, Radio buttons, frames,
National Diploma Unit 4 Introduction to Software Development Procedures and Functions.
Programming with Visual Basic.NET. Quick Links Program Code The Code Window The Event Procedure Assignment Statements Using AutoList Radio Buttons Buttons.
Making Interactive Programs with Visual Basic .NET
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 6 Looping and Multiple Forms.
Visual Basic/ Visual Studio Brandon Large. Connecting to prior knowledge In your notes write down what the two main parts of the computer are. The “software”
Part 1 Learning Objectives To understand that variables are a temporary named location to store data and that programmers work with different data types.
Multiple Forms and Menus
A variable is a name for a value stored in memory.
3.01 Apply Controls Associated With Visual Studio Form
CHAPTER FIVE Decision Structures.
3.01 Apply Controls Associated With Visual Studio Form
Variables and Arithmetic Operations
Visual Basic Programming Chapter Four Notes Working with Variables, Constants, Data Types, and Expressions GROUPBOX CONTROL The _____________________________________.
Introduction to TouchDevelop
VB.NET PROGRAMMING FINAL EXAM TEST REVIEW.
Presentation transcript:

Visual Basic.NET http://www.homeandlearn.co.uk/NET/vbNet.html Getting started Loading it up Where to save and how to organize your projects.

2. Forms From the menu bar, click Debug From the drop down menu, click Start Or press the F5 key on your keyboard Click the Red X on the form to stop it from running.

3. Controls Things like buttons, textboxes, and labels are all things that you can add to your Forms. They are know as Controls, and are kept in the Toolbox for ease of use. You can pin the toolbox to keep it in view.

4. Adding controls to a form Double click the textbox tool (make 3 textboxes - what are textboxes used for?) Double click the label tool (make 3 labels - when would you use a label and when would you use a textbox tool?) Resize and line up Start your program to view

5. VB.NET Properties What you are looking at is a list of the properties that a form has: Name , BackColor, Font, Image, Text, etc. Just to the right of these properties are the values for them. These values are the default values, and can be changed.

Properties continued Locate the word "Text" in the Property box "Text" is a Property of Form1. Change the Text property to read “My First Project”

Control Properties Click label1and then click inside the area next to "Text” property, and delete the word "Label1" by hitting the backspace key on your keyboard Type in the words "First Name” Change Label2 to read “Last name. Change Label 3 to read “Phone number”

6. Consistent Programming Change the Name properties into: frmName for Forms lblName for labels txtName for textboxes cmdName for command buttons picName for picture boxes

7. Variables a variable is a storage area of the computer's memory Think of it like this: a variable is an empty cardboard box. The use of variables allows values to be represented by meaningful names that make the program code easy to read. A variable can only store one value at a time. Dim dblX As Double dblX = 5.5 dblX = 10 The value stored would be 10 as it was assigned last.

8. Option Explicit In the General section of each form, ensure that you turn Option Explicit On. This will catch many of your spelling errors.

9. Data Types Type Prefix Used to Represent Short sho Integer with no decimals up to 32, 767 Long lng Integer with no decimals which go over 2,147,438,648 Decimal dec Decimal of 29 digits String str Represents a set of characters Integer int Integer with no decimals up to 2,147,438,648

10. Declaring Variables Dim number1 As Integer Dim number 2 As Integer What does each part mean? Dim? As Integer?

Question What would be the final value of the variable dblResult? dblNumber = 10 dblNumber = 2 * 3 dblResult = dblNumber * 2

11. Adding a Command Button New adding project Click on the button tool and change its text to read “Add Two Numbers” Change its property name to “cmdAdd” Make a label and clear its text. Change its property name to lblTotal

Double click on the command button. Private means that no other part of the program can see this code except for our button. The "Sub” (subroutine) word tells VB that some code follows. _Click ( ) The Click Event will runt the code. End Sub The subroutine ends right here.

Type the following in the command button click event. Dim intNumber1 As Integer Dim intNumber 2 As Integer Dim intAnswer as Integer intNumber1 = 3 intNumber2 = 5 intAnswer = intNumber1 + intNumber 2 lblTotal.Text = intAnswer

12. Constants In the previous project, both intNumber1 and inNumber 2 did not have values that changed…so they would be constants. If they are constants, they should be declared as such. Declaring a constant variable is as simple as Const intNumber1 As Integer = 3 Declare constants before Dim statements

The Done Command Button Most programs have a “Done” button that ends the program. The code is Unload Me

13. Mathematical Expressions Add = + Subtract = – Multiply = * Divide = / Integer Division = \ (how many times one number goes into another) Modular division = mod (returns the remainder resulting from division only) Power of 2 = ^2 Use brackets

Questions What is the value of intX? Dim intX As Integer intX = 20 Mod 7 What is the problem with the following code? Dim intX As Integer = 12

14. Dealing with Textboxes You have coded for 2 constants to be added together, when they are clicked. We want a person to be able to put in two numbers and then the computer to add then up and put the result in the label. Always have a variable assigned to a textbox Example dblNumber1 = txtNumber1.Text

Add 2 textboxes to the form. Label then txtNumber1 and txtNumber2 Ensure that the Text property is blank. Have 2 variables = to the corresponding textboxes. Add the 2 variables together and equal to the intAnswer variable Display intAnswer in the lblTotal

15. Change Event Procedures The change event occurs when the user begins to type in a textbox. Private Sub txtSide_Change() lblAnswer.Caption = “”

16. Adding Images From the toolbar click on the picture button Either draw or double click on this button Copy an image and paste into your folder. Using the picture properties, find the picture on your computer. The image is True for being shown and False for being invisible. Add a smiley picture to your Adding form. Call this picSmile in the properties of the picture

17. Form Load Event Procedure Double click on the white part of the form. Enter the code picSmile.value = False What do you think will happen?

To the command button, add the following code picSmile.value = True

Review 2 Area Calculation Create a new project that calculates the area of a rectangle with 1 side 5 cm and the other side is 8 cm. Display this in a label. Put a picture of an rectangle on the form and have this form only show until a command button for the answer being clicked.

18. Message Box Code for a pop up box Msgbox.Show(“Hello”) Or if you have a variable Msgbox.show(strName)

19. Option (Radio) Buttons Adding Radio Buttons to a Form is exactly the same process as adding a Checkbox. You must draw the option buttons in a group. Draw the group first. optName.Checked = True

Review 3 Create a new project. You will need a label (lblMessage), and a command button (cmdDone). Add 3 option buttons inside the group. Rename these buttons optEnglish, optSpanish and optfrench. The captions should say each language.

Double click on the optEnglish option button and add the following code lblMessage.Caption = “Hello World” Double click on the optSpanish option button and add the following code lblMessage.Caption = “Hola Mundo” Double click on the optFrench option button and add the following code lblMessage.Caption = “Bonjour le monde” Add a form load event procedure optEnglish.checked = True

Exercises 1-5

Part II Conditional Logic If…Then…End If If…Then…Else…End If If…Then…ElseIf…End If Select Case

20. If…Then statements These are conditional logic statements. If I eat the cake Then my diet will be ruined If I don't eat the cake Then I will be on course for a slimmer figure Or Else My diet is not ruined

Consider a number guessing game. I pick a number between 1-10. If you guess the number then you are right Else you are wrong. Something should happen in both conditions, either to let you know you are right or that you are wrong. For every If you need an End If to complete the condition.

Dim strFirstName as String strFirstName = "Bill" If firstname = Bill Then MsgBox.Show("firstname is Bill“) Else MsgBox.Show("firstname is not Bill“) End If Note that the line after the If statement is indented. This is good programming.

Guessing Game Review Make a new project. Make a label that says “Guess a number between 1 – 10”. Make a label that says “My Guess” Beside the “My Guess” label make an empty textbox for people to put there guesses. Make a label that will say if you are correct or incorrect. Make a command button that will check your number. Make a command button that is a done button.

Check Boxes Select “GroupBox” from the Containers in the toolbox. Draw a rectangle on the form and rename to grpTV and change the text to say TV Click on CheckBoxes and draw 2 inside the GroupBox Using a GroupBox allows you to move all the checkboxes as once.

If a checkbox has been selected, the value for the CheckState property will be 1; if it hasn't been selected, the value is zero

If CheckBox1.CheckState = 1 Then MsgBox("Checked") End If

Select Case Used when there is only a limited number of things that could be chosen. Dim strCreamCake As String Dim strDietState As String strCreamCake = txtTextBox1.Text (what is put in the textbox is stored) Select Case strCreamCake (check variable) Case "Eaten“ strDietState = "Diet Ruined" Case "Not Eaten" strDietState = "Diet Not Ruined" Case Else strDietState = "Didn't check" End Select MsgBox strDietState

Ampersand The symbol “&” connects 2 bits of information Dim strFirstName As String Dim strLastName As String Dim strFullName As String strFirstName = "Bill" strLastName = "Gates" strFullName = FirstName & LastName txtTextbox1.Text = FullName

Conditional Operators

Combo Boxes Double click the icon to add a Combo Box to your form. Or click once with the left hand mouse button, and then draw one on the form. A combo box is a way to limit the choices your user will have. When a black down-pointing arrow is clicked, a drop down list of items appears. The user can then select one of these options.

Whatever is in the Textbox will be transferred to the variable Dim strItems as String strItems = cboItems.Text Msgbox strItems

Loops You want to add up the numbers 1 to 4: 1 + 2 + 3 + 4. You could do it like this Dim intAnswer As Integer intAnswer = 1 + 2 + 3 + 4 MsgBox intAnswer Fairly simple, you think. And not much code, either. But what if you wanted to add up a thousand numbers? Are you really going to type them all out like that? It's an awful lot of typing. A loop would make life a lot simpler. But don't get hung up too much on the name of the Loop. Just remember what they do: go round and round until you tell them to stop.

For Loops Dim intAnswer As Integer Dim intStartNumber As Integer For intStartNumber = 1 To 4 intAnswer = intAnswer + intStartNumber Next intStartNumber MsgBox intAnswer Use the following code to halt the program if there is nothing in a textbox. Exit Sub

Do Loops Dim intNumber as Integer intNumber = 1 Do While intNumber < 5 MsgBox intNumber intNumber = intNumber + 1 Loop

Do Until Do Until intNumber < 5 MsgBox intNumber intNumber = intNumber + 1 Loop

Adding Menu’s

Coding for Menu’s Press F7 on your keyboard to go to the code window Click the black arrow at the top, where it says General

Run the program and see what happens when you click this in the menu Rename the menu items Use mnu as the prefix Rename the ExitToolStripMenuItem to mnuExit Bring up the code window by doubling clicking on the mnuExit on the form Add Me.Close( ) Run the program and see what happens when you click this in the menu

Open File Dialogue Box

Save File Dialogue Box

Show and Hide Controls

View Images Menu Button

Arrays

Text Files