Data and variables in Visual Basic. Annoucement Lecture on Thursday 7:30PM C106 Visual Basic download: 

Slides:



Advertisements
Similar presentations
Fundamentals of Programming in Visual Basic
Advertisements

Chapter 4 - Visual Basic Schneider
Introduction to Computing Dr. Nadeem A Khan. Lecture 4.
Chapter 31 Fundamentals of Programming in VB(Continue I) Numbers Arithmetic Operations Variables Incrementing the Value of a Variable.
VB Code Statements 3 types of VB statement The Remark statement, known as comments, are used for project documentation only Begin with an apostrophe Not.
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.
Introduction To Visual Basic 6. Announcements  Thursday, Oct 9th, 7:30PM, C106 Lloyd Douglas (NSF) Diversity in Science-Who needs it? 5 extra credits.
Basic Elements of C++ Chapter 2.
Copyright © 2001 by Wiley. All rights reserved. Chapter 3: Variables, Assignment Statements, and Arithmetic Variables Assignment Statements Arithmetic.
Variables & Math Operators CE 311 K - Introduction to Computer Methods Daene C. McKinney.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 6 Enhancing the Inventory Application Introducing Variables, Memory Concepts and.
CS0004: Introduction to Programming Variables – Numbers.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
CS0004: Introduction to Programming Variables – Strings.
1 Chapter 3 – Variables, Input, and Output 3.1 Numbers 3.2 Strings 3.3 Input and Output.
Programming Examples to Accompany Structure Topic Please use speaker notes for additional information!
Lecture 8 Visual Basic (2).
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 2 Input,
Input, Output, and Processing
 Application – another name for a program.  Interface – is what appears on the screen when the application is running.  Program Code – is instructions.
Chapter 2: Using Data.
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.
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
Fundamentals of GUI Programming. Objectives: At the end of the session, you should be able to: describe the guidelines that are used for creating user-friendly.
Introduction to Programming with RAPTOR
Chapter Two Creating a First Project in Visual Basic.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Applications Development
Data Types and Variables. Data Type! Computers are all about Data! Data can be in the form of Text Dates Sounds Pictures.
Lesson Two: Everything You Need to Know
Variables & Function Calls. Overview u Variables  Programmer Defined & Intrinsic  Data Types  Calculation issues u Using Functions  The val() function.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
String and General Procedures. Answer to the last question of Exam 1 Start Get a number Divide the Number By 2 Is the quotient Equal to 1? Print The Remain.
Arrays and others. Annoucement Today’s office hour move to Friday 1:00PM to 3:00PM Today’s office hour move to Friday 1:00PM to 3:00PM Today Today  Call.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
Hungarian Notation A must in this course Every object used MUST be renamed including the form(s) using the following rules Form  frmFormName E.g. frmTemperature.
Slide 1 Controls v Control naming convention –Label: lblName –Command Button: cmdName –Text Box: txtName.
Chapter 3 – Variables and Arithmetic Operations. First Program – volume of a box /************************************************************/ /* Program.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
Controlling Program Flow with Decision Structures.
Visual Basic Review LBS 126. VB programming Project Form 1Form 2Form 3 Text boxButton Picture box Objects Text box Button Objects.
Microsoft Visual Basic 2012 CHAPTER FOUR Variables and Arithmetic Operations.
Creation of Variables with Numeric, alphanumeric, date, picture, memo data types Constant - A quantity that does not change during the execution of a program.
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,
Addison Wesley is an imprint of © 2011 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 3 Variables and Calculations.
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.
Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are used in programs so that values can be represented with.
2.1 The Part of a C++ Program. The Parts of a C++ Program // sample C++ program #include using namespace std; int main() { cout
Introduction To Visual Basic 6
Egyptian Language School Computer Department
A variable is a name for a value stored in memory.
Chapter 2 Variables.
Topics Designing a Program Input, Processing, and Output
Chapter 2 Basic Computation
Variables and Arithmetic Operations
Variables, Expressions, and IO
Variables and Arithmetic Operations
Department Array in Visual Basic
CIS16 Application Development Programming with Visual Basic
Chapter 2 Variables.
Core Objects, Variables, Input, and Output
Chapter 2: Introduction to C++.
Topics Designing a Program Input, Processing, and Output
Engineering Problem Solving with C++ An Object Based Approach
Engineering Problem Solving with C++ An Object Based Approach
Topics Designing a Program Input, Processing, and Output
Chapter 2 Variables.
Presentation transcript:

Data and variables in Visual Basic

Annoucement Lecture on Thursday 7:30PM C106 Visual Basic download: 

VB Installation Download and run the program. Go to upzipped folder and run setup.exe Set unzip Path

Handling the event Message Dispatching Block User Text box Properties Methods Event Handler Button Properties Methods Event Handler Command1_Click Picture Box Properties Methods Event Handler Print Get Text1.text You have got clicked.

Define other event handler When you double click the command button, you only define the default event handler (command1_click). You can define other event as well. Demo

Variable Variables are storage unit of data. Distance = Speed * Time You need to declare a variable before using it. For example: Dim Distance as Integer … Distance = … = reads “is assigned with” Distance500 Speed100 Time5 In memory

Two meanings of “=“ sign Assignment operator: assign the value of the RIGHT side to the LEFT side. Dim A as Integer A=0 A=A+1 Relational operator If A = B Then Reads “A is assigned with A+1” Reads “If A equals to B then”

Doing Stuff with Variables Equations: Answer always on LEFT  Total = Weight * Coeff Math  +, -  * for multiplication  / for division  ^ for exponent: volume = width^3  ( ) for separating parts  Numerical functions: Sqr(), Int(), Round(), sin()

Order of Operations Parentheses Exponents Multiplication and Division Addition and Subtraction JUST LIKE ALGEBRA!

Naming a variable Start with a letter Followed by letter or number or underscore. Less than 255 letters Symbols that are forbidden in a variable name: Almost every special symbol on keyboard. Certain key word is reserved and can not be used as variable name, e.g. end print Right: A_2, Speed, Wrong: 2Heavy, private, Weight-factor

Review of Variables Different Types: Byte, Integer, Long, Single, String Naming- use descriptive names Input and output – do not put variable names inside quotes

Data types in VB Numeric data (and their range)  Byte: 0 ~ 255  Integer: -32,768 to 32,767  Long: -2,147,483,648 to 2,147,483,648  Single: +/ E-45 to E+38 String  A group of ASCII symbols. Each symbol takes one byte.

Strings String data is defined between two double quotations. “Hello world” String variable is a name used to refer to a string. String1=“Hello world” Difference between a number and a string of a number.  Number (Bin), just one byte  String “128” ASCII code “1” “2” “8”, 3 bytes.

String functions Val(string) converts “128” to Str(number) converts to “128”. Len(string) returns the length of the string (number of letters)

Building a Program

Outlining a Program Draw the form Define the objects in the form  Define key properties Define which objects have sub procedures

Sample Outline – GB to MB Picture Box (picOutput) Text Box (txtGB) Command Button (cmdCompute) Label Form Text Box (txtMB)

Objects Table ObjectTypePropertiesEvent handler txtGBTextBox txtMBText Box cmdComputeCommand Button Click() Label1, Label 2, … Labels picOutputPicture Box Form1Form

Getting Number Values into Variables Variable = Val(TextBox.Text) We have a textbox named txtGB, command button named cmdNum Private Sub cmdNum_Click() Dim GB As Single GB = Val(txtGB.Text) … End Sub Declares GB variable Sets GB equal to Text in txtGB When clicked

Sub Procedure Outline Variables  GB and Coeff are Single from textbox GB = Val(txtGB.Text)  result is Single to be calculated Equations  Result= GB * Coeff Output: Total to Answer (PictureBox)

Flow Charts Define different sub procedures Create separate paths in flowchart for different sub procedures

GB to MB Calculator Input Values Calculate Total Result= GB * coeff Begin cmdNum Declare Variables Dim GB As Single Dim Coeff As Single Output Total End cmdNum

Variables, Calculations, and Output Private Sub cmdCompute_Click() Dim GB As Single Dim coeff As Single Dim result As Single GB = Val(txtGB.Text) coeff = Val(txtMB.Text) result = GB * coeff picOutput.Print result; "MBs" End Sub

Comments in Program Private Sub cmdCompute_Click() ‘This program will convert GB to MB ‘declare GB, coeff, result Dim GB As Single Dim coeff As Single Dim result As Single ‘convert input from string to number GB = Val(txtGB.Text) coeff = Val(txtMB.Text) ‘computer result result = GB * coeff ‘output the result picOutput.Print result; "MBs" End Sub