1 Advanced Computer Programming Lab Calculator Project.

Slides:



Advertisements
Similar presentations
Compunet Corporation Programming with Visual Studio.NET GUI Week 13 Tariq Aziz and Kevin Jones.
Advertisements

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.
5.05 Apply Looping Structures
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.
Instructor: Adil Ibrahim Office: 212 Ullrich Phone: ibrahima 1.
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
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.
Ch 11: Userforms CP212 Winter Topics Designing User Forms o Controls Setting Properties o Tab Order o Testing Writing Event Handlers o Userform_Initialize.
1 Visual Basic for Applications (VBA) for Excel Prof. Yitzchak Rosenthal.
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
06/10/ Working with Data. 206/10/2015 Learning Objectives Explain the circumstances when the following might be useful: Disabling buttons and.
1/36 Database Programming with Visual Basic.Net and MS Access IKE Lab. Yunho Song Database Management and Analysis.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide.
Chapter 3 – Fundamentals of Programming in VB.NET VB.NET Controls VB.NET Events Numbers Strings Input and Output.
Review for Mid-term! October 26, Review Homework Worksheet True or False Operators are symbols that perform specific operations in Visual Basic.
Introduction to Visual Basic.NET Chapter 2 Introduction to Controls, Events.
Introduction to Visual Basic.NET Your First Visual Basic.NET Application.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
Visual Basic.NET Windows Forms Hello World Homework Assignment.
1. S:\Courses\CSSE\ibrahima\CS2340\Notes Folder Section1 Folder Section2 2.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
CSCI 3327 Visual Basic Chapter 4: Control Statements in Visual Basic (Part 1B) UTPA – Fall 2011.
New Project in Visual Basic Please use speaker notes for additional information!
1 Week 6 The Repetition Structure. 2 The Repetition Structure (Looping) Lesson A Objectives After completing this lesson, you will be able to:  Code.
Tutorial 6 The Repetition Structure
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
CS0004: Introduction to Programming Project 1 – Lessons Learned.
University of Sunderland CIF 104 Fundamentals of DatabasesUnit 16 SESSION 16 VBA example.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Class Average Application Introducing the Do...Loop While and Do...Loop Until.
Controls. Adding Controls to Form -You can pick controls from the toolbox. -To add the controls from Toolbox to the Form You have be in design view. -To.
Applications Development
Data Types and Variables. Data Type! Computers are all about Data! Data can be in the form of Text Dates Sounds Pictures.
1 Creating Windows GUIs with Visual Studio. 2 Creating the Project New Project Visual C++ Projects Windows Forms Application Give the Project a Name and.
What is Visual Basic.NET? 110 B-1 e.g. a word processor doesn’t do anything until the user clicks on a button, types text... A programming language that.
Class 2 Remote Instruction Review of Working with Buttons EDU 556 Programming for Instruction Dr. Steve Broskoske This is an audio PowerCast. Make sure.
COPYRIGHT 2010: Dr. David Scanlan, CSUS OBJECTIVES: How to write classes How to create an object from a class using the "New" keyword. How to communicate.
VAT Calculator program Controls Properties Code Results.
Created by Alia Al-Abdulkarim 2008 Visual Basic Vs. Java.
1 CS 106 Computing Fundamentals II Chapter 210 “Adding Controls to User Forms” Herbert G. Mayer, PSU CS Status 7/4/2013 Initial content copied verbatim.
Creating Menus Menu Bar – behaves like standard Windows menus Can be used in place of or in addition to buttons to execute a procedure Menu items are controls.
Python Lesson 1 1. Starter Create the following Excel spreadsheet and complete the calculations using formulae: 2 Add A1 and B1 A2 minus B2 A3 times B3.
Slide 1 Controls v Control naming convention –Label: lblName –Command Button: cmdName –Text Box: txtName.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
Calculator Program Explained by Arafa Hamed. First Designing The Interface Ask yourself how many places are there that will be used to input numbers?
Sorry, the pen lost control. Anyway, you need to download both the.vbp and the.frm for each project. I looked at PrCalc, I did not look at inventory.
Introduction to VB programming Dr. John P. Abraham UTPA Chapters 2 & 3.
Adding Code to the Option Button. Open VB 1.Double click the Calculate button and select General from the Object list box. 2.Add the following code to.
Visual Basic 6 Programming Decide how many variables you need by looking at this form. There is one textbox for input and there are 3 labels for output,
I am using Visual Basic 6 for this class. If you want to use a different version, please contact me. Thanks!
Addison Wesley is an imprint of © 2011 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 3 Variables and Calculations.
21/03/ Working with Controls Text and List Boxes.
Visual Basic Declaring Variables Dim x as Integer = 0 In the statement above, x is being declared as an Integer (whole number) and is initialised.
Computer Science Up Down Controls, Decisions and Random Numbers.
Computing and Information Technology Building a Web Browser
Visual Basic Fundamental Concepts
Apply Procedures to Develop Menus, List Box and Combo Box Objects
Apply Procedures to Develop Message, Input, and Dialog Boxes
Apply Procedures to Develop Menus, List Box and Combo Box Objects
Introduction to VB programming
Please use speaker notes for additional information!
Visual Basic..
Please use speaker notes for additional information!
Introduction to TouchDevelop
Hints on Chapter 5.
Introduction to Programming
GUI Programming in Visual Studio .NET
Presentation transcript:

1 Advanced Computer Programming Lab Calculator Project

2 How to use Variables in VB.NET Learn how to transfer the contents from one textbox to another Learn how to transfer the text from a label to a textbox

3 Lets Start!! Start a new Visual basic project. You should have a plain grey Form on your screen. By default it will be called Form1. Click the Name property in the Properties window. Change the Name of the form to frmVariables. Set the Text property of the Form to "Transferring information". You can choose any background colour you like for the form, or leave it on the default.

4 Change Control Properties Put the following controls on the Form, and change their properties to the one's specified below (NOTE: lbl is short for label) Textbox Name: txtVariables Font: MS Sans Serif, Bold, 10 Text Delete the default text "Text1" and leave it blank Label Name: lblTransfer BackColor: A colour of your choice Text: Label Caption Font: MS Sans Serif, Bold, 10 Button Name: btnTransfer Text: Transfer to Textbox

5 Coding…. (Transfer text from a label to an empty textbox) Double Click on the button to bring up the code window. You will write your code in this window Declaring Variables Dim LabelContents As String Assigning a value to the variables LabelContents = lblTransfer.txt The next line of code simply puts what ever text is written in the label into the textbox txtVariables.txt = LabelContents

6 Output

7 Coding…(Transfer text from the textbox to a label) Now we want to transfer the text in the textbox to a label Add a new button to your form and change its text property to “Transfer to Label” The code for this is similar to what we have done above Declaring the variables Dim TextboxContents As String Assigning a value to the variable TextboxContents = txtVariables.txt The next line of code simply puts what ever text is written in the label into the textbox lblTransfer.txt = TexboxContents

8 Exercise  A button also has a Text Property. Write code to transfer the Text property of a button to the Textbox. It's probably better for this exercise to create a new Button. Set its Name property to whatever you like. And give its Text Property a new value (The Text property will be Button1 by default).

9 Calculator Project Create a new project called Calculator The following controls need to be added to the form Buttons Name: btn Plus a Number (btnOne, btnTwo, btnThree, etc) Text: A number from 0 to 9. A different one for each button, obviously Font: MS Sans Serif, Bold, 14 Textbox Name: txtDisplay Font: MS Sans Serif, Bold, 14 Text: Erase the default, Textbox1, and leave it blank

10 Command Buttons Plus Button Name: cmdPlus Font: MS Sans Serif, Bold, 14 Text: + Equals Button Name: cmdEquals Font: MS Sans Serif, Bold, 14 Text: = Clear Button Name: cmdClear Font: MS Sans Serif, Bold, 14 Text: Clear

11 Calculator

12 What Shall Happen? So if you wanted to add 5 + 9, you would click first on the 5. A 5 would appear in the textbox. Then you would click the + symbol. The 5 would disappear from the textbox. Next, click on the 9. The number 9 would appear in the textbox. Finally, click on the = symbol. The 9 would disappear from the textbox, and the answer to our sum would replace it. We would then click the Clear button to clear the display.

13 Calculator Code in VB.NET Declare two variables named total1 and total2 These variables shall store the numbers which have to be added together We shall declare the two variables at the top of the code below the line that begins “Public Class Form1” So after declaring the code will look like; The Single in the above code means “Single-Precision” For scientific calculations use “Double”

14 Code for 0-9 Buttons The Buttons with the Text 0 to 9 only need to do one thing when the button is clicked - have their Text Properties transferred to the Textbox. You've already wrote code to do that. So double click the 0 Button and enter the following code: Private Sub btnZero_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) _ Handles btnZero.Click txtDisplay.Text = btnZero.Text End Sub This code will transfer the Text Property of a Button called btnZero to the Text Property of a Textbox called txtDisplay. There is a problem with this code????? 

15 Code for 0-9 Buttons Problem in the code: What happens when you transfer the number 2 to the Textbox, and then click the number 3? The number 2 will disappear, to be replaced by the number 3. if you actually wanted the number 23 in the Textbox. With this code, you could have either the number 2 in the Textbox or the number 3, but not both! Solution: What we need is a way to get whatever is in the Textbox to stay where it is, and not disappear on us when we click a different number. For this the code will transform into something like: txtDisplay.Text = txtDisplay.Text & btnZero.Text Note: This code has to be written for all of the 10 buttons

16 Coding for the Plus Button When we click the Plus Button, we want two things to happen –Store the number that is currently in the textbox –Clear the textbox To store the number that is currently in the textbox we have already defined a variable which does just that i.e. Dim total1 As integer So in order to store the number in the textbox our code will look like this; total1 = txtDisplay.Text

17 Coding for the Plus Button The above code will only put the value in the textbox in the variable named total1. But if we want to add three or four numbers together like … If we don't keep a running total, there's no way for our program to remember what has gone before, it will just erase whatever is in total1 and then start again. We can do something similar if we want to retain a value that is already in a variable variable1 = variable1 + 1 The "= variable1 + 1" part just says "Remember what is in the variable variable1, and then add 1 to it.

18 Coding for the Plus Button Using the code above we can write our code for the plus button as; total1 = total1 + Val (txtDisplay.Text) The Val( ) part just makes sure that a number in a textbox is kept as a number, and not as text So now we are saying that “The variable total1 contains whatever is in total1 added to the number in the textbox. Clear the Textbox To clear the textbox just write the code as; txtDisplay.clear()

19 Whole Code for Plus Button Private Sub btnPlus_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) _ Handles btnPlus.Click total1 = total1 + Val(txtDisplay.Text) txtDisplay.Clear() End Sub

20 Exercise Write the code for the equals button