Type Storage Range of Values
|
|
- Caitlin Jackson
- 5 years ago
- Views:
Transcription
1 University of Misan College of Engineering Department of Civil Engineering Course Title: Visual Basic Second Stage Fourth Lecture Visual Basic Data There are many types of data that we come across in our daily life. For example, weneed to handle data such as names, addresses, money, date, stock quotes, statisticsetc. everyday. Similarly in Visual Basic, we are also going to deal with these kinds ofdata. However, to be more systematic, Visual Basic divides data into differenttypes. 4-1 Types of Visual Basic Data a) Numeric Data Numeric data are data that consist of numbers, which can be computed mathematically with various standard operators such as add, minus, multiply, divide and so on. In Visual Basic, the numeric data are divided into 7 types, which are summarized in Table 4-1: N o. Table 4-1: Numeric Data Types Type Storage Range of Values 1 Byte 1 byte 0 to Integer 2 bytes -32,768 to 32,767 3 Long 4 bytes -2,147,483,648 to 2,147,483,648 4 Single 4 bytes E+38 to E-45 for negative values E-45 to E+38 for positive values 5 Double 8 bytes e+308 to E-324 for negative values E-324 to e+308 for positive values 6 Currency 8 bytes -922,337,203,685, to 922,337,203,685, Decimal 12 bytes +/- 79,228,162,514,264,337,593,543,950,335 if no decimal is used+/ (28 decimal places). Page1 24
2 b) Non-numeric Data Types The non-numeric data types are summarized in Table 4-2: Table 4-2: Nonnumeric Data Types No. Data Type Storage Range 1 String (fixed length) Length of string 1 to 65,400 characters 2 String (variable length) Length + 10 bytes 0 to 2 billion characters 3 Date 8 bytes January 1, 100 to December 31, Boolean 2 bytes True or False 5 Object 4 bytes Any embedded object 6 Variant (numeric) 16 bytes Any value as large as double 7 Variant (text) Length+22 bytes Same as variable-length string c) Suffixes for Literals Literals are values that you assign to a data. In some cases, we need to add a suffixbehind a literal so that VISUAL BASIC can handle the calculation more accurately.for example, we can use num=1.3089# for a Double data type. Some of the suffixes are displayed in Table 4-3: Table 4-3: Suffix No. Suffix Data Type 1 % Integer 2 & Long 3! Single 4 # Double Currency 6 $ String In addition, we need to enclose string literals within two quotations and date and time literals within two # signs. Strings can contain any type of characters, including numbers. The following are a few examples: membername$="ahmed, Dhuha" TelNumber$=" " LastDay=#31-Dec-00# ExpTime=#12:00 am# Mark%=90 profit@= It should be noted that in most cases, it is not necessary to use suffixes as long aswe declare the variables using the Dim statement. Page2 24
3 4-2 Managing Variables Variables are like mail boxes in the post office. The contents of the variables change every now and then, just like mail boxes. In terms of Visual Basic, variables are areas allocated by the computer memory to hold data. Like the mail boxes, each variable must be given a name. To name a variable in Visual Basic, you have to follow a set of rules. a) Variable Names The following are the rules when naming the variables in Visual Basic: 1- It must be less than or equal to 255 characters. 2- No spacing is allowed. 3- It must not begin with a number. 4- Periods are not permitted. Examples of valid and invalid variable names are displayed in Table 4-4: Table 4-4: valid and invalid variable names Valid Name Invalid Name My_Car My.Car This year 1NewBoy Long_Name_Can_beUSE He&HisFather *& is not acceptable Page3 24
4 b) Declaring Variables In Visual Basic, one needs to declare the variables before using them by assigning names and data types. You can declare the variables implicitly or explicitly. For example, sum=text1.text means that the variable sum is declared implicitly and ready to receive the input in the Text1 textbox. Other examples of implicit declaration are volume=8 and label="welcome". On the other hand, for explicit declaration, variables are normally declared in the general section of the code s window using the Dim statement. The format is as follows: Dim Variable Name as Data Type Dim (Private) password As StringDim: Dimension Dim yourname As String Dim firstnum As Integer Dim secondnum As Integer Dim total As Integer Dim dodate As Date Page4 24
5 You may also combine them in one line, separating each variable with a comma, asfollows: Dim password As String, yourname As String, firstnum As Integer. If the data type is not specified, Visual Basic will automatically declare the variableas a Variant. For string declaration, there are two possible formats, one for the variable-length string and another for the fixed-length string. For the variable-length string, just use the same format as Example above. However, for the fixed-length string, youhave to use the format as shown below: Dim VariableName as String * n, where n defines the number of characters the string can hold. For example, Dim yourname as String * 10 mean yourname can hold nomore than 10 Characters. Declaration of Variables There are three methods to declaration of variables: 1- Dynamic Local Variables. Syntax 2- Static Local Variables. Syntax Dim Variable Name as Variable Type Static Variable Name as Variable Type 3- Global (Public) Variables. Syntax Public Variable Name as Variable Type Using "Option Explicit" statement in the general declaration section of a program forces Visual Basic to generate an error message if a variable is not declared. This way you make sure that you are using only explicit form of variable declaration. Local (Private) and Global (Public) Variables If a variable is declared in a specific event procedure, i.e. Command1_Click (), then it is a local variable and can only be used in that event procedure with the declared format. If you want to use this variable in another event procedure, then you must declare it again. In order to make a variable available to all the controls and procedures in your program, you need to declare it as a global variable. Page5 24
6 This is done by declaring the variable in the General (declaration) event procedure. This event procedure is available through the Code Window as the first item in the "Object" drop-down list and first item in the "Procedure" drop-down list as seen in the following figure. General Declaration 1 st Variable 2 nd Variable Third Variable Page6 24
7 4-3 Constants If a variable in your program contains a value that never changes (such as π, a fixed mathematical entity), you might consider storing the value as a constant instead of as a variable. A constant is meaningful name that takes the place of a number or a text string that doesn t change. Constant are useful because the increase the readability of program code, they can reduce programming mistake, and they make global changes easier to accomplish later. Constant operate a lot like variables, but you can t modify their values at run time. In Visual Basic you can declare a constant by using the keyword "Const", as show in the following example: Const pi As Double= Constant are useful in the program code, especially in involved mathematicalformulas, such as area of circle = π r 2. Syntax In Editor CodeConst Constant Name = Value InModule Public Const Constant Name = Value Immediate Window There is a window down the Form called immediate window, which using direct to compute the mathematical operators in Visual Basic. Syntax Debug. Print or print then mathematical operators then press Enter Page7 24
8 Remember One of the outstanding features of Visual Basic is that you can accomplish a lot by writing only a few lines of code. In Visual Basic, code is also referred to as program Statement. A program statement can be as simple as a single word; Note: Beep This statement causes the computer speaker to make a beep sound. A program statement can also be quite sophisticated. One of the most usual forms of the program statements is as follows: Object Name. Property Name = Setting Exercises 1. List out all numeric and non-numeric data types. 2. State the rules in naming the variables. 3. Write five examples of valid variable names. 4. Use the Dim statements to declare three numeric variables and three nonnumeric variables. Fifth Lecture 5-1 Arithmetic Operators in Visual Basic In order to compute input from users and to generate results, we need to use various mathematical operators. In Visual Basic, except for + and -, the symbols for the operators are different from normal mathematical operators, as shown in Table 5-1. Table 5-1: Arithmetic Operators Page8 24
9 No. Operator Order of Precedence Mathematical function Example 1 ^ First Exponential 2^4=16 2 * Second Multiplication 4*3=12 3 / Third Division 12/4=3 4 \ Fourth Integer Division (discards the decimal places) 5 Mod Fifth Modulus (returns the remainder from aninteger division) 19\4=4 15 MOD 4=3 6 + Or & and - Sixth String concatenation "Visual"&"Basic"="Visual Basic" EX.8 Private Sub Form_Load() Form1.Height = 6000 Form1.Width = 5000 Form1.Caption = "Operators" Form1.BackColor =vbyellow Form1.FontName = "Times New Roman" Form1.Font.Italic = True Form1.Font.Size = 20 Command1.Caption = "Operators" Command1.Top = 4000 Command1.Left = 2000 Command1.Height = 1000 Command1.Width = 2000 Command1.FontName = "Times New Roman" Command1.FontItalic = True Command1.FontSize = 20 Page9 24
10 Private Sub Command1_Click() Print 7 \ 3 Print 7 Mod 3 Print "My" & "Name" Print 10 / 3 * 15 / 3 * 3 / 2-9 / 3 / 2 * 4 * 3 Print 4000# - 300# / 5 / 30# Print 4E-8 / 2 * 5E+8 / 6E+16 * 4E+14 * 3 Print 4 / 3 ^ 3 / 4 ^ 2 * 3 ^ 4 * 2 ^ 4 Print 27 ^ 1 / 3-200# ^ 3 * / 4 ^ 3 Print (3-3 ^ 3) / ((3 ^ ^ 3) / 3 ^ 5) / 3 ^ 4 EX.9:Example to explain utilizing the Operators. Now let s try writing a Visual Basic program to examine each of the operations mentioned above. 1- Open a new Visual Basic Project by clicking on the "New Project" on the "File"menu, and selecting Standard.EXE from the list of icons. 2- Select "Save As..." from the File menu. A dialog box appears with Form1.frm in the File Name window. Type "Operators" in place of Form1 and click "O.K." (Make sure you are in the directory that you want). Another dialog box appears with Project1.vbp in the File Name window. Type "Operators" in place of Project1 and click "O.K." 3- Develop the interface using the following information. 4- Attach code to the Interface Declarations of variables. Click on the "View Code" in the Project Window. In the "Object" drop-down list select "General" and in the "Procedure" drop-down list select" (declarations)". Type the following codes in this window. Dim x As Single Dim y As Single Dim z As Single Or you may type: Dim x, y, z As Single 5- Generate the executable file for this Program by clicking on "File" in the menu bar and choosing "Make EXE File... ". The Make EXE File dialog box appears and you will be asked if you would like to save the executable file in "Operators.exe". Accept by clicking "O.K". Page10 24
11 ToolBox and Properties Object Property Value Form TextBox TextBox TextBox Name Caption Name MultiLine Alignment Name MultiLine Alignment Name MultiLine Alignment Forecolor frmoperators The Operator Program txtnumber1 True Center txtnumber2 True Center txtresult True Center Red Label Caption First Number Label Caption Second Number Label Caption Result CommandButton1 Caption &Add CommandButton2 Caption &Subtract CommandButton3 Caption &Divide CommandButton4 Caption &Multiply CommandButton5 Caption &Integer Divide CommandButton6 Caption &Exponential CommandButton7 Caption & CommandButton8 Caption &Mod CommandButton9 Caption Reset CommandButton10 Caption &Exit Page11 24
12 Visual Programming Your program s interface or main window should look like this: Code Programming 1- Addition Double click on the Add Command Button. Visual Basic responds by opening the Code Window Type the following lines in the Code Window x = Val (txtnumber1.text) y = Val (txtnumber2.text) z = x + y txtresult.text = z 2- Subtract Double click on the Subtract Command Button. Visual Basic responds by opening the Code Window Type the following lines in the Code Window x = Val (txtnumber1.text) y = Val (txtnumber2.text) z = x - y txtresult.text = z 3- Divide Double click on the Divide Command Button. Visual Basic responds by opening the Code Window Type the following lines in the Code Window x = Val (txtnumber1.text) y = Val (txtnumber2.text) z = x - y txtresult.text = z Page12 24
13 4- Multiply Double click on the Multiply Command Button. Visual Basic responds by opening the Code Window Type the following lines in the Code Window x = Val (txtnumber1.text) y = Val (txtnumber2.text) z = x * y txtresult.text = z 5- Integer Divide Double click on the Integer Divide Command Button. Visual Basic responds by opening the Code Window Type the following lines in the Code Window x = Val (txtnumber1.text) y = Val (txtnumber2.text) z = x \ y txtresult.text = z 6- Exponential Double click on the ExponentialCommand Button. Visual Basic responds by opening the Code Window Type the following lines in the Code Window x = Val (txtnumber1.text) y = Val (txtnumber2.text) z = x ^ y txtresult.text = z 7- & Double click on &Command Button. Visual Basic responds by opening the Code Window Type the following lines in the Code Window x = Val (txtnumber1.text) y = Val (txtnumber2.text) z = x & y txtresult.text = z Page13 24
14 8- Mod Double click on the Mod Command Button. Visual Basic responds by opening the Code Window Type the following lines in the Code Window x = Val (txtnumber1.text) y = Val (txtnumber2.text) z = x Mod y txtresult.text = z Private Sub Command9_Click() txtnumber1.text = "" txtnumber2.text = "" txtresult = "" Private Sub Command10_Click() End Code Interpretation for EX.9 In the first line you are assigning the user input or the value of the Text property of the txtnumber1 Text Box to the variable x. While the program is running, user will type the first number for the operation in this Text Box. Your code will instruct Visual Basic to retrieve this value and assign it to the Text property of the txtnumber1 object. The same is true for txtnumber2 object in the second line of the code. Then the two variables xand y are added together and the result is assigned to the variable z. The variable z is then assigned to the Text property of the txtresult object that will consequently be displayedin the interface. 5-2 Operator Precedence A mathematical formula processes a combination of variables and operators. Following is a valid Visual Basic program statement: X = / 4-1 * 3^2 Above calculation may have several different results depending on which operator is executed first. For example is 12 added to 8 and the result is then divided by 4 or -9 is first divided by 4 and the result is added to 20? Visual Basic executes mathematical operators in a specific order. Table 5-1: Shown the order of precedencethat operators are executed in Visual Basic. Page14 24
15 In the above expression 3^2 is executed first. Then 9 (the result of 3^2) is multiplied by -1 and 8 is divided by 4. The above expression reduces to: Which will add up to 5. X = / 4-1 * 3^2 When writing formulas in Visual Basic, it is recommended to use parentheses to separate calculations. In Visual Basic, parentheses take precedence over everything else. Innermost parentheses are always executed first regardless of the operators they contain. Therefore use of parentheses forces precedence in calculations. Consider the following expression: y = 3 + 5^2 / 9 * 2^3 10 If we present this expression in this format to Visual Basic the result will be , but this expression should resemble the following formula: yy = Above expression has a value of To make sure that the formula is presented to the Visual Basic correctly, we must use parentheses. So the expression should be written as: Y = (3 + 5^2) / (9 * 2^3-10) Which will result in the correct answer. EX.10: Convert the following sentence from the algebraic formula to Visual Basic formula. 33 ee55 + ssssss 3333 llllll(22) + tttttt 3333 Solution: ((EXP(5)+SIN(30* /180))/(LOG(2)/LOG(10)+TAN(35* /180)))^(1/3) Page15 24
16 H.W:Convert the following sentences from the algebraic formula to Visual Basic Language. 1- ππ 4 UU aaaa UU bb± bb2 4aaaa aaaa 2aa Page16 24
17 6-1Conditional Operators Sixth Lecture To control the Visual Basic program flow, we can use various conditional operators. Basically, they resemble mathematical operators. Conditional operators are very powerful tools which let the Visual Basic program compare data values and then decide what action to take, whether to execute or terminate the program etc. These operators are shown in Table (5-2). Table 5-2: Comparison Operators (Conditional Operators) Operator Meaning = Equal to > More (Greater) than < Less than >= More (Greater)than or equal to <= Less than or equal to <> Not equal to The following table shows some conditional expressions and their results.you ll work with conditional expressions several time in this Course. Conditional Expression Result 10 <> 20 True (10 is not equal 20) Score <20 True if Score is less than 20; otherwise, false Score = Label 1.Text True if the Text property of the Label 1 object contains the same value as the Score variable; otherwise, false TextBox1 ="Bill" True if the word "Bill" in the TextBox1 object; otherwise, false 6-2 Logical Operators In addition to conditional operators, there are a few logical operators that offer added power to the Visual Basic programs. They are shown in Table (5-3). Table (5-3) Operators Meaning And Both sides must be true Or One side or other must be true Xor One side or other must be true but not both Not Negates truth The following table lists some examples of the logical operators at work. In the expressions, it is assumed that the Vehicle string variable contains the value "Bill", and the integer variable Price contains the value 200. Logical expression Vehicle="Bill" And Price <300 Vehicle="Car" Or Price <500 Vehicle="Bill" Xor Price <300 Not Price <100 Result True (both conditions are True) True (one condition is True) False (both conditions are True) True (condition is False) Page17 24
18 6-3Conditions Statement Conditional structures allow applications written in Visual Basic to respond to different situations depending upon the result of a test condition. The condition can be a comparison or any expression that evaluates to a numeric value If Then Statement In general, you use an If...Thenstatement when your program must make an "either/or" decision. When your program must select from more than one alternative, use an If...Then...Elsestatement, an If...Then...Elseifstatement, or a Select Casestatement. You choose the structure that is most efficient for your needs. These other statements are covered in subsequent topics If...Thenstatements evaluate whether a condition is true or false and direct the program s flow accordingly. If...Thenstatements can use either single-line or block form syntax. Syntax 1 If Condition Then Statements EX.11: What will appear when the following program is executing? Private Sub Command1_Click() X = 5 Y = 7 If X <> Y Then X = 2 * X Print "X="; X, "Y="; Y If...Then...Else statements are an elaboration on the If...Thenconcept. AnIf...Then...Else block allows you to define two blocks of code and have your programexecute one based upon the result of a condition. If more than one of the conditionsin a conditional structure is true, only the code statements enclosed by the first truecondition are executed. Syntax 2 If Condition Then Statements1 Else Statements2 Note:Can using the function IIF instead of IF Then. IIF (Condition, Statements1, Statements2) Switch (Condition1, Statements1,Condition2, Statements2) Page18 24
19 An If...Then...Else statement includes a condition that evaluates to True orfalse, one or more statements that execute depending on the result of the testcondition, and an End If statement in the case of a block If...Then...Else statement. EX.12: What will appear when the following program is executing? Private Sub Command1_Click() x = 5: y = 10: z = 30 If x <> 2 Then y = y + x z = z + x x = 0 Else y = y - x z = z - x x = 1 Print "X="; x Print "Y="; y Print "Z="; z End If Syntax 3 Syntax 4 IfConditionThenStatements End If If Condition ThenStatements ElseIf Condition n ThenStatements ElseStatements End If EX.13: Using Operators with IIf. Private Sub Command1_Click() Dim X As Integer X = Val(Text1.Text) Label1 = IIf(X >= 50, "Good", "Bad") Label1 = Switch(X >= 50, "Good", X<50, "Bad") EX.14: Using Operators with If Then Else. Private Sub Command1_Click() sage = Val(Text1.Text) If sage > 24 And sage <= 45 Then Label1 = "Acceptable" Else Label1 = "Unacceptable" End If Page19 24
20 EX.15: Using Operators with If Then Else. Private Sub Command1_Click() FirstNum = Val(Text1.Text) SecondNum = Val(Text2.Text) Total = Firstnum + SecondNum If Total = Val(Text3.Text) And Val(Text3.Text) <> 0 Then Label1.Caption = "Yes, you are Correct" Else Label1.Caption = "Sorry, you are wrong" End If EX.16 Using If Then Else. Private Sub Command1_Click() x = 8: y = 8 If x > 10 Then x = x + 7 Else If x < 5 Then x = x + 13 Else If y < 10 Then y = y + x Else y = y * 2 End If End If End If Print x, y EX.17: Using If Then ElseIf Else. Private Sub Command1_Click() x = 3: y = 10 If x > 5 Then x = x + 7 ElseIf x < 5 Then x = x + 13 ElseIf y < 10 Then y = y + x Else y = y * 2 End If Print x, y Page20 24
21 6-3-2 Select Case Statement Allow your program to choose from more than two alternatives. However, the Select Case structure can be more efficient because it evaluates the test expression onlyonce. The result of the expression is then compared against multiple values todetermine which code block is invoked.the following example shows the code syntax for the Select Case structure.one of several groups of statements is run, depending on the value of an expression. Syntax Select Case variable Case value 1 Statements executed if value 1 matches variable Case value 2 Statements executed if value 2 matches variable Case value n Statements executed if value n matches variable Case Else Statements executed if value no matches is found End Select Ex.18: Using Operatorswith Select Case. Private Sub Command1_Click() Dim age As Integer age = Val(Text1.Text) Select Case age Case is >=16 Label1 <= "you can drive now" Case 18 Label1 = "you can vote now" Case 21 Label1 = "you can travel" Case 65 Label1 = "time to retire and have fun" Case Else Label1 = "you re a great age!, Enjoy it" End Select Page21 24
22 EX.19:Using ListBox and Select Case. Private Sub Form_Load() List1.AddItem "Green" List1.AddItem "Yallow" List1.AddItem "Blue" List1.AddItem "Red" List1.AddItem "White" List1.AddItem "Black" Private Sub List1_Click() Dim icolor As Integer Dim sbackground As String icolor = List1.ListIndex Select Case icolor Case 0 sbackground = vbgreen Case 1 sbackground = vbyellow Case 2 sbackground = vbblue Case 3 sbackground = vbred Case 4 sbackground = vbwhite Case 5 sbackground = vbblack End Select Form1.BackColor = sbackground EX.20: Private Sub Command1_Click()Label3 = "Very Good" Dim degree As Single Case 90 To 100 If IsNumeric(Text1.Text) ThenCase 90 To 100 degree = Val(Text1.Text) Label3 = "Excellent" Select Case degreecase Is > 100 Case 0 To 49MsgBox "Higher degree must be <=100" Label3 = "Fail"Case Else Case 50 To 59End Select Label3 = "Pass"Else Case 60 To 69MsgBox "Your degree is wrong" Label3 = "Pass-High"End If Case 70 To 79 Label3 = "Good" Case 80 To 89 Page22 24
23 6-3-3 GoTo Statement Another branching statement, and perhaps the most hated statement inprogramming, is the GoTo statement. However, we will need this to do Run-Timeerror trapping. The format is GoTo Label, where Label is a labeled line.labeled lines are formed by typing the Label followed by a colon. Syntax GoTo Example: Line10:. Sub A: Statement GoTo Beta Statement GoTo A Statement Beta: GoTo Line10. When the code reaches the GoTo statement, program control transfers to the linelabeled Line10. Ex.21: Using GoTo Statement and Numeric Data Type as Integer Private Sub Command1_Click() Dim x, y, Max As Integer x = Val(Text1.Text) y = Val(Text2.Text) Max = x If x > y Then GoTo 10 Max = y 10 Text3.Text = Max Page23 24
24 6-3-4With End With Statement Syntax EX.22: Using With Statement Label1.Caption = Your Label1.BackColor = vbgreen Label1.ForeColor = vbblue With Label1.Caption = Bibo.BackColor = vbgreen.forecolor = vbblue End With With Object. Property = Setting End With Choose Statement Syntax Value = Choose (Number, Value1, Value2, Value n) EX.23: Using With and Choose Statement Private Sub Command1_Click() With Label1.ForeColor = vbred.backcolor = vbwhite End With T = Text1.Text Label1 = Choose(T, 20, 40, 60, 80) H.W: Write a program using the Select Case statement to inform a person about his/her eight status based on the body mass index (BMI) where BMI=bodyweight in kilograms dividedby the square of the height in meters. The weight status is usually shown in the table below: BMI BMI Weight Status Below 18.5 Underweight Normal Overweight 30.0 And Above Obese Page24 24
Excel VBA Variables, Data Types & Constant
Excel VBA Variables, Data Types & Constant Variables are used in almost all computer program and VBA is no different. It's a good practice to declare a variable at the beginning of the procedure. It is
More informationUnit 4. Lesson 4.1. Managing Data. Data types. Introduction. Data type. Visual Basic 2008 Data types
Managing Data Unit 4 Managing Data Introduction Lesson 4.1 Data types We come across many types of information and data in our daily life. For example, we need to handle data such as name, address, money,
More informationVba Variables Constant and Data types in Excel
Vba Variables Constant and Data types in Excel VARIABLES In Excel VBA, variables are areas allocated by the computer memory to hold data. Data stored inside the computer memory has 4 properties: names,
More informationVISUAL BASIC For Engineers & Scientists. Shahab D. Mohaghegh, Ph.D. Professor Petroleum & Natural Gas Engineering West Virginia University
VISUAL BASIC For Engineers & Scientists Shahab D. Mohaghegh, Ph.D. Professor Petroleum & Natural Gas Engineering West Virginia University March 1997 TABLE OF CONTENTS Chapter 1: Problem Solving with Visual
More informationStart Visual Basic. Session 1. The User Interface Form (I/II) The Visual Basic Programming Environment. The Tool Box (I/II)
Session 1 Start Visual Basic Use the Visual Basic programming environment Understand Essential Visual Basic menu commands and programming procedure Change Property setting Use Online Help and Exit Visual
More informationLe L c e t c ur u e e 2 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Variables Operators
Course Name: Advanced Java Lecture 2 Topics to be covered Variables Operators Variables -Introduction A variables can be considered as a name given to the location in memory where values are stored. One
More informationThe Control Properties
The Control Properties Figure Before writing an event procedure for the control to response to a user's input, you have to set certain properties for the control to determine its appearance and how it
More informationChapter 17. Fundamental Concepts Expressed in JavaScript
Chapter 17 Fundamental Concepts Expressed in JavaScript Learning Objectives Tell the difference between name, value, and variable List three basic data types and the rules for specifying them in a program
More informationOverview About KBasic
Overview About KBasic The following chapter has been used from Wikipedia entry about BASIC and is licensed under the GNU Free Documentation License. Table of Contents Object-Oriented...2 Event-Driven...2
More informationVisual Basic 6 Lecture 7. The List Box:
The List Box: The function of the List Box is to present a list of items where the user can click and select the items from the list or we can use the List Box control as a simple memory to save data.
More informationFundamentals. Fundamentals. Fundamentals. We build up instructions from three types of materials
Fundamentals We build up instructions from three types of materials Constants Expressions Fundamentals Constants are just that, they are values that don t change as our macros are executing Fundamentals
More informationMicrosoft Visual Basic 2015: Reloaded
Microsoft Visual Basic 2015: Reloaded Sixth Edition Chapter Three Memory Locations and Calculations Objectives After studying this chapter, you should be able to: Declare variables and named constants
More informationMicrosoft Visual Basic 2005: Reloaded
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations Objectives After studying this chapter, you should be able to: Declare variables and named
More informationFunction: function procedures and sub procedures share the same characteristics, with
Function: function procedures and sub procedures share the same characteristics, with one important difference- function procedures return a value (e.g., give a value back) to the caller, whereas sub procedures
More informationControl Properties. Example: Program to change background color
Control Properties Before writing an event procedure for the control to response to an event, you have to set certain properties for the control to determine its appearance and how will it work with the
More informationdownload instant at Introduction to C++
Introduction to C++ 2 Programming: Solutions What s in a name? that which we call a rose By any other name would smell as sweet. William Shakespeare When faced with a decision, I always ask, What would
More informationLanguage Fundamentals
Language Fundamentals VBA Concepts Sept. 2013 CEE 3804 Faculty Language Fundamentals 1. Statements 2. Data Types 3. Variables and Constants 4. Functions 5. Subroutines Data Types 1. Numeric Integer Long
More informationProgramming with visual Basic:
Programming with visual Basic: 1-Introdution to Visual Basics 2-Forms and Control tools. 3-Project explorer, properties and events. 4-make project, save it and its applications. 5- Files projects and exercises.
More information2Practicals Visual Basic 6.0
2Practicals Visual Basic 6.0 Practical 1: 1. Navigation of Visual Basic Integrated Development Environment The Visual Basic IDE is made up of a number of components Menu Bar Tool Bar Project Explorer Properties
More informationDecisions, Decisions. Testing, testing C H A P T E R 7
C H A P T E R 7 In the first few chapters, we saw some of the basic building blocks of a program. We can now make a program with input, processing, and output. We can even make our input and output a little
More informationVBScript: Math Functions
C h a p t e r 3 VBScript: Math Functions In this chapter, you will learn how to use the following VBScript functions to World Class standards: 1. Writing Math Equations in VBScripts 2. Beginning a New
More informationStatements and Operators
Statements and Operators Old Content - visit altium.com/documentation Mod ifi ed by Rob Eva ns on Feb 15, 201 7 Parent page: EnableBasic Enable Basic Statements Do...Loop Conditional statement that repeats
More informationProgramming Language 2 (PL2)
Programming Language 2 (PL2) 337.1.1 - Explain rules for constructing various variable types of language 337.1.2 Identify the use of arithmetical and logical operators 337.1.3 Explain the rules of language
More informationCSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York
CSc 10200! Introduction to Computing Lecture 2-3 Edgardo Molina Fall 2013 City College of New York 1 C++ for Engineers and Scientists Third Edition Chapter 2 Problem Solving Using C++ 2 Objectives In this
More informationOverview: Programming Concepts. Programming Concepts. Names, Values, And Variables
Chapter 18: Get With the Program: Fundamental Concepts Expressed in JavaScript Fluency with Information Technology Third Edition by Lawrence Snyder Overview: Programming Concepts Programming: Act of formulating
More informationOverview: Programming Concepts. Programming Concepts. Chapter 18: Get With the Program: Fundamental Concepts Expressed in JavaScript
Chapter 18: Get With the Program: Fundamental Concepts Expressed in JavaScript Fluency with Information Technology Third Edition by Lawrence Snyder Overview: Programming Concepts Programming: Act of formulating
More informationAn overview about DroidBasic For Android
An overview about DroidBasic For Android from February 25, 2013 Contents An overview about DroidBasic For Android...1 Object-Oriented...2 Event-Driven...2 DroidBasic Framework...2 The Integrated Development
More informationFundamental of Programming (C)
Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 3 Constants, Variables, Data Types, And Operations Department of Computer Engineering
More informationLearning the Language - V
Learning the Language - V Fundamentals We now have locations to store things so we need a way to get things into those storage locations To do that, we use assignment statements Deja Moo: The feeling that
More informationGENERAL INFORMATICS Chapter 3. The Representation of Processing Algorithms Algorithm definition Steps in computer problem solving process
GENERAL INFORMATICS Chapter 3. The Representation of Processing Algorithms 3.1. Algorithm definition 3.2. Steps in computer problem solving process 3.3. Steps for preparing a program for execution 3.4.
More informationFull file at
2 Introduction to C Programming Solutions What s in a name? That which we call a rose By any other name would smell as sweet. William Shakespeare When faced with a decision, I always ask, What would be
More informationProfessor: Sana Odeh Lecture 3 Python 3.1 Variables, Primitive Data Types & arithmetic operators
1 Professor: Sana Odeh odeh@courant.nyu.edu Lecture 3 Python 3.1 Variables, Primitive Data Types & arithmetic operators Review What s wrong with this line of code? print( He said Hello ) What s wrong with
More informationBASIC ELEMENTS OF A COMPUTER PROGRAM
BASIC ELEMENTS OF A COMPUTER PROGRAM CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING LOGO Contents 1 Identifier 2 3 Rules for naming and declaring data variables Basic data types 4 Arithmetic operators
More informationExpressions and Data Types CSC 121 Spring 2015 Howard Rosenthal
Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types
More informationIntroductory Notes: Condition Statements
Brigham Young University - Idaho College of Physical Sciences and Engineering Department of Mechanical Engineering Introductory Notes: Condition Statements The simplest of all computer programs perform
More informationChapter 2. Designing a Program. Input, Processing, and Output Fall 2016, CSUS. Chapter 2.1
Chapter 2 Input, Processing, and Output Fall 2016, CSUS Designing a Program Chapter 2.1 1 Algorithms They are the logic on how to do something how to compute the value of Pi how to delete a file how to
More informationIntroduction to Data Entry and Data Types
212 Chapter 4 Variables and Arithmetic Operations STEP 1 With the Toolbox visible (see Figure 4-21), click the Toolbox Close button. The Toolbox closes and the work area expands in size.to reshow the Toolbox
More informationCS112 Lecture: Variables, Expressions, Computation, Constants, Numeric Input-Output
CS112 Lecture: Variables, Expressions, Computation, Constants, Numeric Input-Output Last revised January 12, 2006 Objectives: 1. To introduce arithmetic operators and expressions 2. To introduce variables
More informationOutline. Data and Operations. Data Types. Integral Types
Outline Data and Operations Data Types Arithmetic Operations Strings Variables Declaration Statements Named Constant Assignment Statements Intrinsic (Built-in) Functions Data and Operations Data and Operations
More informationCS1150 Principles of Computer Science Boolean, Selection Statements
CS1150 Principles of Computer Science Boolean, Selection Statements Yanyan Zhuang Department of Computer Science http://www.cs.uccs.edu/~yzhuang CS1150 Math Center https://www.uccs.edu/mathcenter/schedules
More informationSimple Java Programming Constructs 4
Simple Java Programming Constructs 4 Course Map In this module you will learn the basic Java programming constructs, the if and while statements. Introduction Computer Principles and Components Software
More informationVISUAL BASIC 6.0 OVERVIEW
VISUAL BASIC 6.0 OVERVIEW GENERAL CONCEPTS Visual Basic is a visual programming language. You create forms and controls by drawing on the screen rather than by coding as in traditional languages. Visual
More informationVisual Basic for Applications
Visual Basic for Applications Programming Damiano SOMENZI School of Economics and Management Advanced Computer Skills damiano.somenzi@unibz.it Week 1 Outline 1 Visual Basic for Applications Programming
More informationMotivations. Chapter 3: Selections and Conditionals. Relational Operators 8/31/18. Objectives. Problem: A Simple Math Learning Tool
Chapter 3: Selections and Conditionals CS1: Java Programming Colorado State University Motivations If you assigned a negative value for radius in Listing 2.2, ComputeAreaWithConsoleInput.java, the program
More informationVisual C# Instructor s Manual Table of Contents
Visual C# 2005 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion Topics Additional Projects Additional Resources Key Terms
More informationDisclaimer. Trademarks. Liability
Disclaimer II Visual Basic 2010 Made Easy- A complete tutorial for beginners is an independent publication and is not affiliated with, nor has it been authorized, sponsored, or otherwise approved by Microsoft
More informationd2vbaref.doc Page 1 of 22 05/11/02 14:21
Database Design 2 1. VBA or Macros?... 2 1.1 Advantages of VBA:... 2 1.2 When to use macros... 3 1.3 From here...... 3 2. A simple event procedure... 4 2.1 The code explained... 4 2.2 How does the error
More informationCMPT 125: Lecture 3 Data and Expressions
CMPT 125: Lecture 3 Data and Expressions Tamara Smyth, tamaras@cs.sfu.ca School of Computing Science, Simon Fraser University January 3, 2009 1 Character Strings A character string is an object in Java,
More informationLas Vegas, Nevada, December 3 6, Kevin Vandecar. Speaker Name:
Las Vegas, Nevada, December 3 6, 2002 Speaker Name: Kevin Vandecar Course Title: Introduction to Visual Basic Course ID: CP11-3 Session Overview: Introduction to Visual Basic programming is a beginning
More informationInformation Science 1
Information Science 1 Simple Calcula,ons Week 09 College of Information Science and Engineering Ritsumeikan University Topics covered l Terms and concepts from Week 8 l Simple calculations Documenting
More informationC++ Programming: From Problem Analysis to Program Design, Third Edition
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 2: Basic Elements of C++ Objectives (continued) Become familiar with the use of increment and decrement operators Examine
More informationOverview (4) CPE 101 mod/reusing slides from a UW course. Assignment Statement: Review. Why Study Expressions? D-1
CPE 101 mod/reusing slides from a UW course Overview (4) Lecture 4: Arithmetic Expressions Arithmetic expressions Integer and floating-point (double) types Unary and binary operators Precedence Associativity
More informationUsing Basic Formulas 4
Using Basic Formulas 4 LESSON SKILL MATRIX Skills Exam Objective Objective Number Understanding and Displaying Formulas Display formulas. 1.4.8 Using Cell References in Formulas Insert references. 4.1.1
More informationOutline. Midterm Review. Using Excel. Midterm Review: Excel Basics. Using VBA. Sample Exam Question. Midterm Review April 4, 2014
Midterm Review Larry Caretto Mechanical Engineering 209 Computer Programming for Mechanical Engineers April 4, 2017 Outline Excel spreadsheet basics Use of VBA functions and subs Declaring/using variables
More informationOur Strategy for Learning Fortran 90
Our Strategy for Learning Fortran 90 We want to consider some computational problems which build in complexity. evaluating an integral solving nonlinear equations vector/matrix operations fitting data
More informationIntroduction to programming with Python
Introduction to programming with Python Ing. Lelio Campanile 1/61 Main Goal - Introduce you to programming - introduce you to the most essential feature of python programming 2/61 Before to start The name
More informationTOPIC 2 INTRODUCTION TO JAVA AND DR JAVA
1 TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson, and instructor materials prepared
More informationSKILL AREA 306: DEVELOP AND IMPLEMENT COMPUTER PROGRAMS
Add your company slogan SKILL AREA 306: DEVELOP AND IMPLEMENT COMPUTER PROGRAMS Computer Programming (YPG) LOGO 306.1 Review Selected Programming Environment 306.1.1 Explain the concept of reserve words,
More informationVB FUNCTIONS AND OPERATORS
VB FUNCTIONS AND OPERATORS In der to compute inputs from users and generate results, we need to use various mathematical operats. In Visual Basic, other than the addition (+) and subtraction (-), the symbols
More informationModule 2 - Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1
Module 2 - Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1 Topics 1. Expressions 2. Operator precedence 3. Shorthand operators 4. Data/Type Conversion 1/15/19 CSE 1321 MODULE 2 2 Expressions
More informationDEPARTMENT OF MATHS, MJ COLLEGE
T. Y. B.Sc. Mathematics MTH- 356 (A) : Programming in C Unit 1 : Basic Concepts Syllabus : Introduction, Character set, C token, Keywords, Constants, Variables, Data types, Symbolic constants, Over flow,
More informationIntroduction to Computer Use II
Winter 2005 (Section M) Topic B: Variables, Data Types and Expressions Wednesday, January 18 2006 COSC 1530, Winter 2006, Overview (1): Before We Begin Some administrative details Some questions to consider
More informationYou will have mastered the material in this chapter when you can:
CHAPTER 6 Loop Structures OBJECTIVES You will have mastered the material in this chapter when you can: Add a MenuStrip object Use the InputBox function Display data using the ListBox object Understand
More informationCS313D: ADVANCED PROGRAMMING LANGUAGE
CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 2 : C# Language Basics Lecture Contents 2 The C# language First program Variables and constants Input/output Expressions and casting
More informationOperators. Java operators are classified into three categories:
Operators Operators are symbols that perform arithmetic and logical operations on operands and provide a meaningful result. Operands are data values (variables or constants) which are involved in operations.
More informationObjectives. In this chapter, you will:
Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates arithmetic expressions Learn about
More informationVARIABLES. Aim Understanding how computer programs store values, and how they are accessed and used in computer programs.
Lesson 2 VARIABLES Aim Understanding how computer programs store values, and how they are accessed and used in computer programs. WHAT ARE VARIABLES? When you input data (i.e. information) into a computer
More informationvariables programming statements
1 VB PROGRAMMERS GUIDE LESSON 1 File: VbGuideL1.doc Date Started: May 24, 2002 Last Update: Dec 27, 2002 ISBN: 0-9730824-9-6 Version: 0.0 INTRODUCTION TO VB PROGRAMMING VB stands for Visual Basic. Visual
More informationFull file at
Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class
More informationFundamentals of Programming
Fundamentals of Programming Lecture 3 - Constants, Variables, Data Types, And Operations Lecturer : Ebrahim Jahandar Borrowed from lecturer notes by Omid Jafarinezhad Outline C Program Data types Variables
More informationSelection Statements. Pseudocode
Selection Statements Pseudocode Natural language mixed with programming code Ex: if the radius is negative the program display a message indicating wrong input; the program compute the area and display
More information20. VB Programming Fundamentals Variables and Procedures
20. VB Programming Fundamentals Variables and Procedures 20.1 Variables and Constants VB, like other programming languages, uses variables for storing values. Variables have a name and a data type. Array
More informationLESSON 2 VARIABLES, OPERATORS, EXPRESSIONS, AND USER INPUT
LESSON VARIABLES, OPERATORS, EXPRESSIONS, AND USER INPUT PROF. JOHN P. BAUGH PROFJPBAUGH@GMAIL.COM PROFJPBAUGH.COM CONTENTS INTRODUCTION... Assumptions.... Variables and Data Types..... Numeric Data Types:
More informationQuick Reference Guide
SOFTWARE AND HARDWARE SOLUTIONS FOR THE EMBEDDED WORLD mikroelektronika Development tools - Books - Compilers Quick Reference Quick Reference Guide with EXAMPLES for Basic language This reference guide
More informationProgram Fundamentals
Program Fundamentals /* HelloWorld.java * The classic Hello, world! program */ class HelloWorld { public static void main (String[ ] args) { System.out.println( Hello, world! ); } } /* HelloWorld.java
More informationFull file at
Java Programming, Fifth Edition 2-1 Chapter 2 Using Data within a Program At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics Additional
More informationAccelerating Information Technology Innovation
Accelerating Information Technology Innovation http://aiti.mit.edu Cali, Colombia Summer 2012 Lesson 02 Variables and Operators Agenda Variables Types Naming Assignment Data Types Type casting Operators
More informationUNIT- 3 Introduction to C++
UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage
More informationLecture 3 Tao Wang 1
Lecture 3 Tao Wang 1 Objectives In this chapter, you will learn about: Arithmetic operations Variables and declaration statements Program input using the cin object Common programming errors C++ for Engineers
More informationComputer Programming, I. Laboratory Manual. Experiment #2. Elementary Programming
Think Twice Code Once The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2005 Khaleel I. Shaheen Computer Programming, I Laboratory Manual Experiment #2
More information9. Elementary Algebraic and Transcendental Scalar Functions
Scalar Functions Summary. Introduction 2. Constants 2a. Numeric Constants 2b. Character Constants 2c. Symbol Constants 2d. Nested Constants 3. Scalar Functions 4. Arithmetic Scalar Functions 5. Operators
More informationInformation Science 1
Topics covered Information Science 1 Terms and concepts from Week 8 Simple calculations Documenting programs Simple Calcula,ons Expressions Arithmetic operators and arithmetic operator precedence Mixed-type
More informationChapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics
Java Programming, Sixth Edition 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics Additional Projects Additional
More informationIFA/QFN VBA Tutorial Notes prepared by Keith Wong
Chapter 2: Basic Visual Basic programming 2-1: What is Visual Basic IFA/QFN VBA Tutorial Notes prepared by Keith Wong BASIC is an acronym for Beginner's All-purpose Symbolic Instruction Code. It is a type
More informationExpressions and Data Types CSC 121 Fall 2015 Howard Rosenthal
Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types and
More informationCivil Engineering Computation
Civil Engineering Computation First Steps in VBA Homework Evaluation 2 1 Homework Evaluation 3 Based on this rubric, you may resubmit Homework 1 and Homework 2 (along with today s homework) by next Monday
More informationLecture 2: Variables and Operators. AITI Nigeria Summer 2012 University of Lagos.
Lecture 2: Variables and Operators AITI Nigeria Summer 2012 University of Lagos. Agenda Variables Types Naming Assignment Data Types Type casting Operators Declaring Variables in Java type name; Variables
More informationGeoCode Language Reference Manual
GeoCode Language Reference Manual Contents 1 Introduction... 3 2 Lexical Elements... 3 2.1 Identifiers... 3 2.2 Keywords... 3 2.3 Literals... 3 2.4 Line Structure... 4 2.5 Indentation... 4 2.6 Whitespace...
More informationIntroduction to Visual Basic and Visual C++ Arithmetic Expression. Arithmetic Expression. Using Arithmetic Expression. Lesson 4.
Introduction to Visual Basic and Visual C++ Arithmetic Expression Lesson 4 Calculation I154-1-A A @ Peter Lo 2010 1 I154-1-A A @ Peter Lo 2010 2 Arithmetic Expression Using Arithmetic Expression Calculations
More informationProgramming Lecture 3
Programming Lecture 3 Expressions (Chapter 3) Primitive types Aside: Context Free Grammars Constants, variables Identifiers Variable declarations Arithmetic expressions Operator precedence Assignment statements
More informationText Input and Conditionals
Text Input and Conditionals Text Input Many programs allow the user to enter information, like a username and password. Python makes taking input from the user seamless with a single line of code: input()
More informationUNIT 2 USING VB TO EXPAND OUR KNOWLEDGE OF PROGRAMMING
UNIT 2 USING VB TO EXPAND OUR KNOWLEDGE OF PROGRAMMING UNIT 2 USING VB TO EXPAND OUR KNOWLEDGE OF PROGRAMMING... 1 IMPORTANT PROGRAMMING TERMINOLOGY AND CONCEPTS... 2 Program... 2 Programming Language...
More informationECE 122 Engineering Problem Solving with Java
ECE 122 Engineering Problem Solving with Java Lecture 3 Expression Evaluation and Program Interaction Outline Problem: How do I input data and use it in complicated expressions Creating complicated expressions
More informationEx: If you use a program to record sales, you will want to remember data:
Data Variables Programs need to remember values. Ex: If you use a program to record sales, you will want to remember data: A loaf of bread was sold to Sione Latu on 14/02/19 for T$1.00. Customer Name:
More informationControl Structures. Lecture 4 COP 3014 Fall September 18, 2017
Control Structures Lecture 4 COP 3014 Fall 2017 September 18, 2017 Control Flow Control flow refers to the specification of the order in which the individual statements, instructions or function calls
More information2 nd Week Lecture Notes
2 nd Week Lecture Notes Scope of variables All the variables that we intend to use in a program must have been declared with its type specifier in an earlier point in the code, like we did in the previous
More informationOpenOffice.org 3.2 BASIC Guide
OpenOffice.org 3.2 BASIC Guide Copyright The contents of this document are subject to the Public Documentation License. You may only use this document if you comply with the terms of the license. See:
More informationBy the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program
1 By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program variables. Apply C++ syntax rules to declare variables, initialize
More informationExpressions and Variables
Expressions and Variables Expressions print(expression) An expression is evaluated to give a value. For example: 2 + 9-6 Evaluates to: 5 Data Types Integers 1, 2, 3, 42, 100, -5 Floating points 2.5, 7.0,
More informationJava+- Language Reference Manual
Fall 2016 COMS4115 Programming Languages & Translators Java+- Language Reference Manual Authors Ashley Daguanno (ad3079) - Manager Anna Wen (aw2802) - Tester Tin Nilar Hlaing (th2520) - Systems Architect
More information