Visual Basic Review LBS 126. VB programming Project Form 1Form 2Form 3 Text boxButton Picture box Objects Text box Button Objects.

Slides:



Advertisements
Similar presentations
Working with Intrinsic Controls and ActiveX Controls
Advertisements

CSI 1306 PROGRAMMING IN VISUAL BASIC PART 2. Part 2  1. Strings  2. Translating Conditional Branch Instructions  3. Translation Set 2  4. Debugging.
Excel and Visual Basic. Outline Data exchange between Excel and Visual Basic. Programming VB in Excel.
1.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 4 Making Decisions in a Program.
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
1 PHP Statement Constructs Server Scripting. 5-2 Basic Statement All Statements end in a semicolon. Statements are delimited from the HTML code by enclosing.
Val Function A Function performs an action and returns a value The expression to operate upon, known as the argument, (or multiple arguments), must be.
Comparing Numeric Values If Val(Text1.Text) = MaxPrice Then (Is the current numeric value stored in the Text property of Text1 equal to the value stored.
PSU CS 106 Computing Fundamentals II VB Statements HM 5/19/2008.
Lec2 P 1 CP2030 Visual Basic For C++ Programmers Copyright © University of Wolverhampton CP2030 VBFC Lecture 2 Back to Index v Basic Data Types v Arithmetic.
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.
Promoting Code Reuse Often in programming, multiple procedures will perform the same operation IN OTHER WORDS – the same piece of code will do the same.
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.
A variable (X) is declared as an integer Data Type, meaning it can only accept numeric values The Text Box is named BoxContents The Variable X is assigned.
Introduction To Visual Basic 6. Announcements  Thursday, Oct 9th, 7:30PM, C106 Lloyd Douglas (NSF) Diversity in Science-Who needs it? 5 extra credits.
VBA & Excel Barry L. Nelson IEMS 465 Fall Quarter 2003.
CS0004: Introduction to Programming Relational Operators, Logical Operators, and If Statements.
Language Elements 1. Data Types 2 Floating Point (real) Single Precision Double Precision Decimal Fixed Point (integer) Byte Short Integer Long Numerical.
Chapter 3: Data Types and Operators JavaScript - Introductory.
Lecture 8 Visual Basic (2).
MAT Meyer Week 2 Programming VB: ‘basics’ Review & preview: Events, variables, statements, etc. Images, Control arrays, For/Next Assignment: read.
ENGR 112 Decision Structures.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 7 Using Menus, Common Dialogs, Procedures, Functions, and Arrays.
4 1 Array and Hash Variables CGI/Perl Programming By Diane Zak.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Visual Basic IITG to be expanded. What is Visual Basic? Object Oriented Programming Language (OOP) Graphical User Interface (GUI) Event Driven – Write.
CS285 Visual Basic 2 Department of Computing UniS 1 Statements in Visual Basic A statement is the fundamental syntactical element of a program smallest.
Visual Basic Programming
Applications Development
Data Types and Variables. Data Type! Computers are all about Data! Data can be in the form of Text Dates Sounds Pictures.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
Practical Programming COMP153-08S Week 5 Lecture 1: Screen Design Subroutines and Functions.
‘Tirgul’ # 2 Enterprise Development Using Visual Basic 6.0 Autumn 2002 Tirgul #2.
Copyright © 2001 by Wiley. All rights reserved. Chapter 6: Using Arrays Control Arrays List Arrays Finding Items in Arrays Multiple Forms 2-Dimensional.
1 Scripting Languages VBScript - Recognized mainly by Internet Explorer only - Netscape does have a plug-in JavaScript - Recognized by Internet Explorer.
Types of Visual Basic Data Numeric Data Non Numeric Data.
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.
Visual Basic Programming I 56:150 Information System Design.
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.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
CompMathBSc, English 5 October 2006 Programming basics — continued  Arrays  Cycle Statements: Loops  Control Structures vs Conditions  Subs: Procedures.
Pay Example (PFirst98) Please use speaker notes for additional information!
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.
CIVIL AND GEOMATIC ENGINEERING FT Okyere. CIV 257- COMPUTER PROGRAMMING Lecture 3.
COMPUTER PROGRAMMING I 5.04 Apply Decision Making Structures.
CECS 5020 Computers in Education Visual Basic Variables and Constants.
Slide 1 Controls v Control naming convention –Label: lblName –Command Button: cmdName –Text Box: txtName.
Controlling Program Flow with Decision Structures.
Loop and repetition. Today Passing values to and back from Sub procedures Option Buttons Do While Loops For Loops Population Growth.
Data and variables in Visual Basic. Annoucement Lecture on Thursday 7:30PM C106 Visual Basic download: 
Knowledge Base. Defining a Variable Dim statement Dim intXX As Integer Public in a Module Public dblNN As Double.
Creation of Variables with Numeric, alphanumeric, date, picture, memo data types Constant - A quantity that does not change during the execution of a program.
More Visual Basic Code: if-then-else, for loops Controls: Multiple forms, List Boxes, Radio buttons, frames,
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
TUTORIAL 4 Visual Basic 6.0 Mr. Crone. Pseudocode Pseudocode is written language that is part-code part- English and helps a programmer to plan the layout.
Introduction To Visual Basic 6
Programming Right from the Start with Visual Basic .NET 1/e
IE 8580 Module 4: DIY Monte Carlo Simulation
A variable is a name for a value stored in memory.
VB Script V B S.
Visual Basic 6 (VB6) Data Types, And Operators
Making Decisions in a Program
Chapter 3: Introduction to Problem Solving and Control Statements
Chapter (3) - Looping Questions.
T. Jumana Abu Shmais – AOU - Riyadh
CS285 Introduction - Visual Basic
Microsoft Visual Basic 2005: Reloaded Second Edition
Presentation transcript:

Visual Basic Review LBS 126

VB programming Project Form 1Form 2Form 3 Text boxButton Picture box Objects Text box Button Objects

Definitions Form contains the Main Program Controls are user interface elements (text boxes, commands) in the Form Forms and Controls are referred to as OBJECTS

Objects in VB Everything in VB is objects, forms, buttons, … Three elements of objects. Properties Methods Event handlers. Important properties of common objects. Properties (size, Caption…) Methods (Print…) Event Handler (Command1_Click()) VB object

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 event handler When you double click the command button, you only define the default event handler (command1_click). Other event can be defined as well. Then procedure name of the event handler. Private Sub ObjectName_EventName() End Sub

Variables Different Types: Byte, Integer, Long, Single, String Naming Starting with letter No special symbols, like ^ $ % Less than 255 characters. Key words are reserved. Declare Variable Dim VariableName As Variable Type

Declaring Arrays Use Dim key word to declare arrays, just as what we do for variables. Dim Data(1 to 50) As Single Dim Species(1 to 4) As String Accessing values in an array with subscript. Data(44) = 22.5; Species(1) = “ACTGACTCGTAACGT” Red Number is INDEX Use ReDim when declaring an array size based on a variable User tells you there are 50 values (count = 50) ReDim Values(1 to count) as Single

Scope of a variable Local scope. Variable declared in a sub procedure It only exists in this sub procedure. Form-level scope. Variable declared out of any sub procedure. Any sub procedure can read it.

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”

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” String is just a bunch of ASCII codes. You can not do mathematical operations on string.

String operations and functions Concatenation String relations =, <>,, = String functins Len(), Val(), Str(), Ucase()… Read text pp. 51

Sub procedures and Functions Procedures and functions are pre-defined code fragments. Why using procedures and functions Making code better structured. Reusing code. Three types of procedures. Event procedure (event handler) General procedure Function procedure Different between Sub procedure and Functions.

General Procedures Defined by key word Sub Private Sub ProcedureName() Block of code End Sub Not linked with any event Can be called by other part of code. Call ProcedureName(arguments list)

Functions procedure Function is a sub procedure with a returned value. Function procedure is used in the same way as a built-in numeric or string function. Variable = FunctionName(arguments…) Define a function Private Function FunctionName(arg1 As type1, arg2 As type2,…) As ReturnType Block of code FunctionName=expression End Function

Passing arguments to and from procedure Passing by reference Sum(num1, num2) Create a tunnel that a procedure can output the computing results. Passing by value Sum((num1),num2) Isolate the procedure from it external world.

Comparison Operators See table 5.1 = equal to <> unequal to < less than > greater than <= less than or equal to >= greater than or equal to Works both for numbers and strings.

Logical Operators And, Or, Not a >=b And b <> 2 a >=b Or b <> 2 And statements: Both must be true Or statements: one or both must be true Not statements: True if statement is false

Boolean value Comparison operator and logical operator will return a Boolean value. Dim VariableName as Boolean Boolean value has only two possibilities: True and False Boolean value can be directly used in decision structure, do while loop, etc. If boolean_variable Then… Do While boolean_variable

Decision structure Simple If statement IF Boolean_Condition Then End IF If-then-else blocks Nested decision blocks. If –ElseIf- Elseif… – Else blocks

Select Case Blocks Allows multiple options (not just true or false) Select Case Variable Case Condition1 Case Condition2 Case Condition3 Case Else End Select Read text pp. 114

Repetition struction Do while Loop When times of loop is unknow Do while condition Loop For Next loop Fixed number of loops For variable = start# to end# Next varialbe

Three steps of reading data from file Step 1:Open the plain text file Open “filename.txt” For Input As #1 Step 2: Read data Input #1, variable Step 3: Close file Close #1

VB and Excel How to exchange data between VB and Excel..csv file How to write a user defined function in Excel. Private Function FuncName(arg1 as type1) as type End Function