Visual Basic Cheat Sheet



Similar documents
VB.NET Programming Fundamentals

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

Many applications consist of one or more classes, each containing one or more methods. If you become part of a development team in industry, you may

Moving from C++ to VBA

PL / SQL Basics. Chapter 3

Chapter 2 Introduction to Java programming

Moving from CS 61A Scheme to CS 61B Java

Visual Logic Instructions and Assignments

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

Hands-on Exercise 1: VBA Coding Basics

VHDL Test Bench Tutorial

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Chapter 2: Elements of Java

Changing the Display Frequency During Scanning Within an ImageControls 3 Application

Introduction. Why (GIS) Programming? Streamline routine/repetitive procedures Implement new algorithms Customize user applications

Government Girls Polytechnic, Bilaspur

Introducing VBA Message Boxes

Computer Programming I & II*

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system.

Sources: On the Web: Slides will be available on:

J a v a Quiz (Unit 3, Test 0 Practice)

Perl in a nutshell. First CGI Script and Perl. Creating a Link to a Script. print Function. Parsing Data 4/27/2009. First CGI Script and Perl

Object Oriented Software Design

C++ INTERVIEW QUESTIONS

JavaScript Introduction

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?

Visual Basic Programming. An Introduction

JavaScript: Introduction to Scripting Pearson Education, Inc. All rights reserved.

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Introduction to Java

PHP Tutorial From beginner to master

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand:

DATA 301 Introduction to Data Analytics Microsoft Excel VBA. Dr. Ramon Lawrence University of British Columbia Okanagan

One Dimension Array: Declaring a fixed-array, if array-name is the name of an array

Lecture 2 Notes: Flow of Control

What is a Loop? Pretest Loops in C++ Types of Loop Testing. Count-controlled loops. Loops can be...

Top 72 Perl Interview Questions and Answers

In this Chapter you ll learn:

6. Control Structures

Chapter 2: Algorithm Discovery and Design. Invitation to Computer Science, C++ Version, Third Edition

Connecting to an Excel Workbook with ADO

«W3Schools Home Next Chapter» JavaScript is THE scripting language of the Web.

Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void

Java Interview Questions and Answers

Debugging. Common Semantic Errors ESE112. Java Library. It is highly unlikely that you will write code that will work on the first go

13 Classes & Objects with Constructors/Destructors

High-Level Programming Languages. Nell Dale & John Lewis (adaptation by Michael Goldwasser)

Summit Public Schools Summit, New Jersey Grade Level / Content Area: Mathematics Length of Course: 1 Academic Year Curriculum: AP Computer Science A

The C++ Language. Loops. ! Recall that a loop is another of the four basic programming language structures

Computational Mathematics with Python

We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.

Example of a Java program

Java Application Developer Certificate Program Competencies

ESCI 386 IDL Programming for Advanced Earth Science Applications Lesson 6 Program Control

PRI-(BASIC2) Preliminary Reference Information Mod date 3. Jun. 2015

Exercise 1: Python Language Basics

Introduction to Python

QUIZ-II QUIZ-II. Chapter 5: Control Structures II (Repetition) Objectives. Objectives (cont d.) 20/11/2015. EEE 117 Computer Programming Fall

Operator Overloading. Lecture 8. Operator Overloading. Running Example: Complex Numbers. Syntax. What can be overloaded. Syntax -- First Example

Introduction to Java Applications Pearson Education, Inc. All rights reserved.

AP Computer Science Java Subset

Statements and Control Flow

Computational Mathematics with Python

Computational Mathematics with Python

Creating Applications using Excel Macros/Visual Basic for Applications (VBA)

Lab 9 Access PreLab Copy the prelab folder, Lab09 PreLab9_Access_intro

Java Basics: Data Types, Variables, and Loops

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq

National Database System (NDS-32) Macro Programming Standards For Microsoft Word Annex - 8

JavaScript: Control Statements I

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)

Specialized Programme on Web Application Development using Open Source Tools

Introduction to Matlab

Wage Calculator Application

Basic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C

The C Programming Language course syllabus associate level

Fundamentals of Java Programming

Systems Programming & Scripting

Thomas Jefferson High School for Science and Technology Program of Studies Foundations of Computer Science. Unit of Study / Textbook Correlation

Scoping (Readings 7.1,7.4,7.6) Parameter passing methods (7.5) Building symbol tables (7.6)

Simple File Input & Output

VISUAL GUIDE to. RX Scripting. for Roulette Xtreme - System Designer 2.0

SQL - QUICK GUIDE. Allows users to access data in relational database management systems.

Symbol Tables. Introduction

Creating Basic Excel Formulas

Certified PHP Developer VS-1054

This loop prints out the numbers from 1 through 10 on separate lines. How does it work? Output:

PULSE Automation programming in Visual Basic. From BK training lectures arranged by Jiří Tůma & Radovan Zadražil

Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007

Variables, Constants, and Data Types

2. Capitalize initial keyword In the example above, READ and WRITE are in caps. There are just a few keywords we will use:

GCE. Computing. Mark Scheme for January Advanced Subsidiary GCE Unit F452: Programming Techniques and Logical Methods

Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following:

OpenOffice.org 3.1 BASIC Guide

Pemrograman Dasar. Basic Elements Of Java

Transcription:

thecodingguys 2013 Visual Basic Cheat Sheet 12/24/2013 A cheat sheet to the Visual Basic language, ideal for newcomers to the language for more visit http://www.thecodingguys.net KEEP IN TOUCH

TABLE OF CONTENTS LICENSE LANGUAGE BASICS Introduction Variables Arrays Strings Concatenation String.Format New Line CONDITIONAL STATEMENTS If Statement If Else Statement Operators Select Case LOOPS While Loop For Loops For Each

ADVANCED EXCEPTIONS, METHODS, CLASSES Exceptions Methods Functions Classes ENJOYED IT? Why not give us a like?

LICENSE This work is licensed under the creative commons Attribution-NonCommercial-NoDerivs 3.0 Unported You may not alter, transform, or build upon this work. You may not use this work for commercial purposes. You are free to copy, distribute and transmit the work

LANGUAGE BASICS INTRODUCTION Visual Basic has a simple syntax much of the language is easily understandable (that s why it s called Basic, doh). A few points: The language is not case-sensitive (So A and a are the same) Lines do not terminate with semi-colons Code is in code blocks, but not your standard Java or C# code block { } (You will see in the examples) VARIABLES Variables are declared using the Dim keyword, Dim is short for (Dimension). Dim MyVariable As DataType The above code creates a variable called MyVariable with no value. The example below creates two variables with data type of string and one of type integer I will use these variables throughout. ARRAYS Dim Name As String = "thecodingguys" Dim Year As Integer = 2013 Arrays are similar to variables, however arrays can hold more than one value. Dim MyArray() As DataType = {Values Comma Separated} Dim MyGamesOf2013() As String = {"GTAV", "Battlefield 3"} Dim MyMoviesOf2013() As String = New String(3) {"The Amazing Spiderman", "The Expendables", "X-Men", "Rise of the planet of the apes"} STRINGS CONCATENATION Concatenation is done through the & symbol, like the following: Console.WriteLine("Hello " & "World")

STRING.FORMAT Formats a string, the following example prints out 5,00 Console.WriteLine(String.Format("{0:C}", 5)) In the example above, we want to format the number 5 and show the currency symbol. The {0:C} is the formatting we want to do, in this case it means format the first argument (0) and apply the currency symbol. Many more formatting types are available see this MSDN reference. The formatting depends on you computers regional settings, users of the UK will see the symbol, users of USA will see the $ symbol and so on. NEW LINE New lines are made using the vbcrlf word. Console.WriteLine("Hello " & vbcrlf & "World")

CONDITIONAL STATEMENTS IF STATEMENT Executes code based on a condition, the condition must evaluate true for the code to execute. If True Then End If If Year > 2010 Then Console.WriteLine("Hello World!") End If IF ELSE STATEMENT The If Else Statement works similar to the if statement, however if the first condition is false the else condition will execute. If Year < 2010 Then Else End If Console.WriteLine("Hello World!") Console.WriteLine("Hello!") OPERATORS Operator Description < Less than operator if 19 < 20 Then > Greater than operator if 20 > 19 Then = Equal to operator if a = b Then <> Not equal to operator if a <> b Then <= Less than or equal to operator if 19 <= b Then >= Greater than or equal to operator if 19 >= b Then

SELECT CASE The Select Case statement is similar to a switch statement found in many other programming languages. A few points: Select Case evaluate one variable You can use some operators Select Case Statements are must easier to maintain then using nested if else Select Case variablename Case 1 Case 2 Case Else End Select Select Case Year Case 2012 Console.WriteLine("It's 2012!") Case 2013 Console.WriteLine("The current year!") Case Year > DateTime.Now.Year Console.WriteLine("Year is greater than 2013") Case Else End Select Console.WriteLine("...")

LOOPS WHILE LOOP Continuously loops around code until the condition becomes false. While True End While While Year >= 2013 Year += 1 If Not Year = 2100 Then Else End If End While Console.WriteLine(Year) Exit While Visual Basic does not have an increment operator, however Year += 1 will increment by 1 until it reaches 2100. Always make sure your loop comes to a stop at some point otherwise it becomes endless and can result in errors. FOR LOOPS Similar to the while statement, but you specify when the loop should end. For index = 1 To 10 Next For i = 1 To 100 Console.WriteLine(i) Next This will output 1 100. Once it reaches 100 it will stop.

FOR EACH Loops through elements in a collection. For Each element As DataType In Group Next For Each item As String In MyGamesOf2013 Console.WriteLine(item) Next The above example prints out all the elements in the MyGamesOf2013 array created earlier.

ADVANCED EXCEPTIONS, METHODS, CLASSES EXCEPTIONS To catch possible exceptions which may occur we use a Try Catch Block. Try Catch ex As Exception End Try Try Console.WriteLine(Year + 2147483641) Catch oex As OverflowException Console.WriteLine("Result: Overflow: " + oex.message) Catch fex As ArithmeticException Console.WriteLine("Result: Arithmetic Exception: " + fex.message) Catch ex As Exception End Try Console.WriteLine(ex.Message) The example above catches Overflow Exception, Arithmetic Exception or if all fails it will catch any exception. The above however only results in an Overflow Exception. METHODS Public Sub MyMethodName() No Arguments End Sub Public Sub MyMethodName(ByVal Parameter As DataType) Arguments End Sub A Sub (Subroutine) does not return value back. A Public method can be accessed outside the current class, if you declare it private it can only be accessed within the current class.

Public Sub WelcomeUser() End Sub Console.WriteLine("Welcome Guest") Public Sub WelcomeUser(ByVal Name As String) End Sub Console.WriteLine("Welcome " + Name) The above example is also an overloaded method this is where two methods have the same name but you pass different arguments of different data type. The first method has no arguments and the second one requires an argument. (Just be careful not to make it ambiguous, for example having a method where one you require a double and other and Integer, double can be an integer so this results in an error) FUNCTIONS A function similar to a Subroutine, requires that you return some data back, you can pass arguments just like above. Public Function MyFunc() As DataType End Function Return Data Public Function Tomorrow() As Date Dim CurrentDate As Date = DateTime.Now Return CurrentDate.AddDays(1) End Function

CLASSES A class contains methods and events. Public Class MyClassName End Class Your Methods Public Class MyCar Public Sub CarManufacturer(ByVal Manufacturer As String) End Sub Console.WriteLine(Manufacturer) End Class We can then call this method from another class or module, first you must initialize the class. Dim Car As New MyCar() Car.CarManufacturer("Audi") This will output Audi to the console.

ENJOYED IT? WHY NOT GIVE US A LIKE?