C ONTINUE... V ARIABLE -N AMING C ONVENTIONS When declaring variables, you should be aware of few naming conventions. A variable’s name: Must begin with.

Slides:



Advertisements
Similar presentations
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Advertisements

Week 2: Primitive Data Types 1.  Programming in Java  Everything goes inside a class  The main() method is the starting point for executing instructions.
IS 1181 IS 118 Introduction to Development Tools VB Chapter 04.
CSI 101 Elements of Computing Spring 2009 Lecture #6: Data Types and Variables in Visual Basic Wednesday, Februrary 11th, 2009.
Introduction to Computing Dr. Nadeem A Khan. Lecture 11.
IS437: Fall 2004 Instructor: Dr. Boris Jukic Data Types, Constants, Variables, Scope, Conversion.
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.
CSci 142 Data and Expressions. 2  Topics  Strings  Primitive data types  Using variables and constants  Expressions and operator precedence  Data.
Chapter Three Using Variables and Constants Programming with Microsoft Visual Basic th Edition.
Variables & Math Operators CE 311 K - Introduction to Computer Methods Daene C. McKinney.
Variables, Constants, Methods, and Calculations Chapter 3 - Review.
L EC. 02: D ATA T YPES AND O PERATORS (1/2) Fall Java Programming.
Variables and Constants
Chapter 3: Using Variables and Constants
Programming with Microsoft Visual Basic th Edition CHAPTER THREE USING VARIABLES AND CONSTANTS.
Variable, Expressions, Statements and Operators By: Engr. Faisal ur Rehman CE-105 Fall 2007.
Week 2 - Monday.  What did we talk about last time?  Software development  Lab 1.
National Diploma Unit 4 Introduction to Software Development Data types, variables and constants.
1 Chapter 3 – Variables, Input, and Output 3.1 Numbers 3.2 Strings 3.3 Input and Output.
CH2 – Using Data. Constant Something which cannot be changed Data Type Format and size of a data item Intrinsic Data Types Pg. 47 – Table 2-1 Basic ones.
3 - Variables Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
Property of Jack Wilson, Cerritos College1 CIS Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College.
MS Visual Basic Applications Walter Milner. Event-driven programming Standard approach for GUIs Contrast with old character interfaces – program determines.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Data Types and Variables. Data Type! Computers are all about Data! Data can be in the form of Text Dates Sounds Pictures.
PHY-102 SAPVariables and OperatorsSlide 1 Variables and Operators In this section we will learn how about variables in Java and basic operations one can.
Copyright Curt Hill Variables What are they? Why do we need them?
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Three Memory Locations and Calculations.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
Other Variable Types Dim lab as String makes a box that can store a label tag Dim ColHead As String ColHead = “function” ColHead function Dim lab as Boolean.
Lab 4 - Variables. Information Hiding General Principle: – Restrict the access to variables and methods as much as possible Can label instance variables.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
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.
Programming with Microsoft Visual Basic th Edition
Variables Hold information that may be manipulated, used to manipulate other information or remembered for later use A storage location in memory (RAM)
Variables in VB.NET. Variables  A storage location in memory (RAM)  Holds data/information while the program is running  These storage locations can.
Variables and Expressions Programming Right from the Start with Visual Basic.NET 1/e 7.
CIS 338: VB Variables Dr. Ralph D. Westfall April, 2011.
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.
Programming with Microsoft Visual Basic 2012 Chapter 3: Using Variables and Constants.
© 2006 Lawrenceville Press Slide 1 Chapter 4 Variables  A variable is a name for a value stored in memory.  Variables are created using a declaration.
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.
Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are created using a declaration statement. For example: Dim.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Creating Database Objects
A variable is a name for a value stored in memory.
VBScript Session 1 IT Professional Academy.
An Application Uses Variables to Hold Information So It May Be Manipulated, Used to Manipulate Other Information, or Remembered for Later Use.
Visual Basic 6 (VB6) Data Types, And Operators
Data Types, Arithmetic Operations
Chapter 3: Using Variables and Constants
2. Understanding VB Variables
Chapter 2.
Variables and Arithmetic Operations
IDENTIFIERS CSC 111.
Microsoft Visual Basic 2005 BASICS
Visual Basic Programming Chapter Four Notes Working with Variables, Constants, Data Types, and Expressions GROUPBOX CONTROL The _____________________________________.
CIS16 Application Development Programming with Visual Basic
Chapter 2: Java Fundamentals
Visual Basic Numbers Chapter 3.3 Prepared By: Deborah 1/15/2019.
Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language.
Creating Database Objects
Visual Basic Numbers Chapter 3.3 Prepared By: Deborah 7/9/2019.
Variables and Constants
Presentation transcript:

C ONTINUE..

V ARIABLE -N AMING C ONVENTIONS When declaring variables, you should be aware of few naming conventions. A variable’s name: Must begin with a letter Mustn’t exceed 255 characters. Must be unique within its scope Cannot include any special character except “_” (underscore) Cannot include a space

V ARIABLE -N AMING R ULES : A variable names in VB.NET are NOT case sensitive. Variables can be prefixed to indicate their data type (prefixes indicate a variable's data type)

S COPE AND LIFETIME OF VARIABLES Scope = visibility of a variable is the section of the application that can see and manipulate the variable. If a variable is declared within a procedure, only the code in the specific procedure has access to that variable. This variable doesn’t exist for the rest of the application. When the variable’s scope is limited to a procedure, it’s called local.

A CCESS S PECIFIERS Access specifiers let's us specify how a variable, method or a class can be used. The following are the most commonly used one's: Public: Gives variable public access which means that there is no restriction on their accessibility. Private: Gives variable private access which means that they are accessible only within their declaration content.

A CCESS S PECIFIERS.. CONT Protected: Protected access gives a variable accessibility within their own class or a class derived from that class. Static: Makes a variable static which means that the variable will hold the value even the procedure in which they are declared ends. Shared: Declares a variable that can be shared across many instances and which is not associated with a specific instance of a class or structure.

TYPES OF VARIABLES Visual Basic.NET recognizes different categories of variables as shown in the previews Table & the most commonly used include: Numeric Boolean String Character Date

N UMERIC V ARIABLES Note: Note: The data type of your variable can make a difference in the results of the calculations. In our previous discussion of data types, we lumped all numeric data together; however, Visual Basic has several numeric data types.

B OOLEAN V ARIABLES The Boolean data type stores True/False values. Boolean variables are, integers that take the value 1 (for True) and 0 (for False). Actually, any non-zero value is considered True. Boolean variables are declared as: Dim failure As Boolean Boolean variables are used in testing conditions, such as the following: If failure Then MessageBox.Show(“Couldn’t complete the operation”)

S TRING V ARIABLES The String data type stores only text, and string variables are declared with the String type: Dim someText As String Dim someText As String You can assign any text to the variable someTxt. You can store nearly 2 GB of text in a string variable (that’s 2 billion characters and is much more text than you care to read on a computer screen). The following assignments are all valid:

Dim aString As String aString = “MIS is a cool course” aString = “” aString = “111, 000” Assignment number 2 creates an empty string, and the last one creates a string that just happens to contain numeric digits, which are also characters.

T HE E MPTY S TRING The string "", which contains no characters, is called the empty string or the zero-length string. The statement lstBox.Items.Add("") skips a line in the list box. The contents of a text box can be cleared with either the statement: txtBox.Clear() or the statement txtBox.Text = ""

U SING T EXT B OXES FOR I NPUT AND O UTPUT The contents of a text box is always a string Input example strVar = txtBox.Text Output example txtBox.Text = strVar

D ATA C ONVERSION string Because the content of a text box or a label is always a string, sometimes you must convert the input or output value into another type. Table 2 shows the VB functions that perform data-type conversions.

FunctionConverts Its Argument To: CBoolBoolean CByteByte CCharUnicode character CDateDate CDblDouble CDecDecimal CIntInteger (4-byte integer, int32) CLngLong (8-byte integer, int64) CObjObject CShortShort (2-byte integer, int16) CSngSingle CStrString

E XAMPLE : numVar = CDbl(txtBox.Text) -Converts a String to a Double txtBox.Text = CStr(numVar) -Converts a number to a string

C HARACTER V ARIABLES Character variables store a single Unicode character in two bytes (16 bit). you can use the CChart() function to convert integers to characters and the CInt() function to convert to their equivalent integer values.

D ATE V ARIABLES Date and time values are stored internally in a special format, but you don’t need to know the exact format. They are double-precision numbers: the integer part represents the date and the fractional part represents the time. A variable declared as Date can store both date and time values with a statement like the following:

D ATE V ARIABLES … CONT Dim expiration As Date The following are all valid assignments: expiration = #01/01/2004? expiration = # 1/2/ ;26:11 pm# expiration = “July 2, 2004” expiration = Now()