Transcription of Visual Basic 2017 Made Easy - vbtutor.net
1 Visual Basic 2017 made easy By 1 Disclaimer Visual Basic 2017 made easy is an independent publication and is not affiliated with, nor has it been authorized, sponsored, or otherwise approved by Microsoft Corporation. Trademarks Microsoft, Visual Basic , Excel and Windows are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries. All other trademarks belong to their respective owners. Liability The purpose of this book is to provide Basic guides for people interested in Visual Basic 2017 programming. Although every effort and care has been taken to make The information as accurate as possible, the author shall not be liable for any error, Harm or damage arising from using the instructions given in this book.
2 Copyright 2017 Liew Voon Kiong All rights reserved. No Part of this e-book may be reproduced, in any form or by any means, without permission in writing from the author. 2 Acknowledgement Iwouldliketoexpressmysinceregratitudetom anypeoplewhohavemadetheir contributions in one way or another to the successful publication of this book. MyspecialthanksgotomychildrenXiang,Yiand Xunwhohavecontributedtheirideas millionsofreaderswhohavevisitedmy VisualBasicTutorial websiteat their support and encouragement. About the Author sdegreeinMathematics,amaster sdegreein Tutorialat , consistently been one of the highest ranked Visual Basic websites.
3 ToprovidemoresupportforVisualBasicstuden ts,teachers,andhobbyists, writtenthisbooktocomplementthefreeVisual Basic2017tutorialwithmuchmorecontent. HeisalsotheauthoroftheVisualBasicMadeEas yseries,whichincludes VisualBasic6 MadeEasy,VisualBasic2008 MadeEasy,VisualBasic2010 MadeEasy,VisualBasic 2013 MadeEasy and ExcelVBAMadeEasy. sbookshavebeenusedinhigh school and university computer science courses all over the world. 3 Contents chapter 1 Introduction to Visual Basic 201711 A Brief Description of Visual Basic 201711 The Visual Studio 2017 IDE13 Creating a New Project in Visual Studio 201714 chapter 2 Designing the Interface19 Customizing the Form19 Adding Controls to the Form24 chapter 3 Writing the Code27 The Concept of Event-Driven Programming27 Writing the Code29 chapter 4 Working with Controls31 TextBox31 Example Adding two numbers in two text boxes31 Label32 Example Displaying output on a Label33 List Box34 Adding Items to the List Box34 a)Adding items using the String Collection Editor34 b) Adding Items using the Add()
4 Method35 Example Adding an Item to a List Box35 Example Adding items to a List Box via an input box36 Example Creating Geometric Progression37 Removing Items from a List Box39 Example Removing an item from a list box39 Example Deleting an item from a list box via an input box40 Example Removing a selected item from a list box41 Example Removing multiple selected items in a list box41 Example Removing all items in a list box using the Clear method41 ComboBox42 Adding Items to a combo box42 Removing Items from a Combo box46 chapter 5 Handling Images47 Loading an Image in a Picture Box47 4 Loading an Image at Design Time47 Loading an Image at Runtime50 Loading an Image using Open File Dialog Control50 chapter 6 Working with Data54 Data Types54 Numeric Data Types54 Non-numeric Data Types55 Suffixes for Literals56 Variables and Constants56 Variable Names56 Declaring Variables57 Example Declaring Variables using Dim57 Example Displaying Message using MsgBox58 Assigning Values to Variables58 Example Incompatible Data Type59 Scope of Declaration60 Declaring Constants61 Example Calculating the Area of Triangle61 chapter 7 Array62 Introduction to Arrays62 Dimension of an Array62 Declaring Arrays63 Example Find the Length of an Array63 Example Using the Length Property64 Example Find the Length of a
5 Two-Dimensional Array64 Example Populating a List Box Involving an Array65 chapter 8 Performing Mathematical Operations67 Mathematical Operators67 Writing Code that Performs Mathematical Operations68 Example Standard Arithmetic Calculations68 Example Pythagorean Theorem68 Example : BMI Calculator69 chapter 9 String Manipulation71 String Manipulation Using + and & signs71 5 Example String Concatenation71 Example Data Mismatch72 String Manipulation Using Built-in Functions74 Len Function74 Example Finding the Length of a Phrase74 Right Function75 Example Extracting the Right Portion of a Phrase75 Left Function75 Mid Function76 Example Retrieve Part of a Text Using Mid Function76 Example Extracting Text from a Phrase76 Trim Function77 Example Trimming Both Side of a Phrase77 Ltrim Function77 The Rtrim Function78 The InStr function78 Ucase and the Lcase Functions78 Chr and the Asc functions78 chapter 10 Using Conditional
6 Operators80 Logical Operators81 Using Statement81 Example Lucky Draw82 Statement82 Example Lucky Draw Simulation82 Example Lucky Draw84 Statement85 Example Grade Generator86 chapter 11 Using Select Case88 Example : Examination Grades88 Example Using Case Is89 Example Select Case using a Range of Values90 Example Examination Grade91 6 chapter 12 Looping93 Loop93 Example Creating a Counter93 Example Sum of Numbers93 Example Step-down For Next Loop94 Example Demonstrate Exit For94 Do Loop94 Example Do Example Summation of Numbers95 While Loop96 Example Demonstrating While Loop96 chapter 13 Sub Procedures98 What is a Sub Procedure98 Example A Sub Procedure that Adds Two Numbers98 Example : Password Cracker99 chapter 14 Creating Functions102 Creating User-Defined Functions102 Example.
7 BMI Calculator102 Example Future Value Calculator104 Passing Arguments by Value and by Reference105 Example ByRef and ByVal106 chapter 15 Mathematical Functions108 The Abs Function108 Example Compute Absolute Number108 The Exp function109 Example Compute Exponential Value109 The Fix Function110 Example Truncate Decimals using Fix110 The Int Function111 The Log Function111 Example Calculate Logarithm of a Number111 The Rnd( ) Function112 The Round Function113 Example Rounding a Number113 7 chapter 16 The Format Function115 Format Function for Numbers115 Built-in Format function for Numbers115 Example Formatting Numbers116 User-Defined Format116 Example User-Defined Formats117 Formatting Date and Time118 Formatting Date and time using predefined formats118 Example Formating Date and Time119 Formatting Date and time using user-defined formats120 Example Formatting Date and Time120 chapter 17 Using Checkbox and Radio Button122 Check Box122 Example.
8 Shopping Cart122 Example Another Shopping Cart124 Example Formatting Text124 Radio Button126 Example Shopping Cart126 Example Using Groupbox128 chapter 18 Errors Handling130 Introduction130 Using On Error GoTo Syntax130 Example Division Errors131 Errors Handling using Try Structure132 Example Data Type Mismatch Error133 chapter 19 Object Oriented Programming135 Concepts of Object-Oriented Programming135 Encapsulation135 Inheritance135 Polymorphism135 Creating Class136 Example BMI Calculator137 chapter 20 Creating Graphics140 Introduction140 8 Creating the Graphics Object141 Creating the Pen Object141 Drawing a Line142 Example Drawing a Straight Line142 Drawing Lines that Connect Multiple Points143 Example Drawing Lines that Connect Multiple Points144 Drawing a curve that Connect Multiple Points145 Example Drawing a Curve that Connect Multiple Points145 Drawing Quadratic Curve146 Example Drawing a Quadratic Curve146 Drawing Sine Curve148 Example Drawing a Sine Curve149 Drawing a Rectangle150 Customizing Line Style of the Pen Object151 Example Drawing a Rectangle with DashStyle152 Drawing an Ellipse153 Example Drawing an Ellipse154 Example Drawing an Ellipse156 Drawing a Circle156 Example Draw a Circle156 Drawing Text157 Example Drawing Text158 Example Drawing Text Input by the
9 User160 Drawing Polygons161 Example Drawing a Triangle162 Example Drawing a Quadrilateral163 Drawing a Pie164 Example Drawing a pie that sweeps clockwise through 60 Filling Shapes with Color165 Example Drawing and Filling a Rectangle with Color165 Example Drawing and Filling an Ellipse with Color167 Example Drawing and Filling a Polygon with Color168 Example Drawing and Filling a Pie169 chapter 21 Using Timer171 9 Example Creating a Digital Clock171 Example Creating a Stopwatch172 Example Creating a Digital Dice174 chapter 22 Creating Animation176 Example Creating Moving Object176 Example Creating an Animated Dice177 Example Creating a Slot Machine180 chapter 23 Working with Databases184 Introduction to Database184 Creating a Database Application185 Creating Connection to a Database using Populating Data in Example Creating a Database196 Browsing Records197 Editing, Saving.
10 Adding and Deleting Records198 Example Browsing Records199 Accessing Database using DataGridView202 Example Browsing Data Using DataGridView203 Performing Arithmetic Calculations in a Database204 Example Performing Arithmetic Calculation204 Example Calculating Average206 Example Using SQL Count Function207 chapter 24 Reading and Writing Text Files210 Introduction210 Reading a Text File210 Writing to a Text File214 chapter 25 Building Console Applications217 Example : Displaying a Message219 Example Creating a Text File Writer in Console220 Example Creating a Text File Reader in Console221 Example Creating a Console App using chapter 26 Creating Menu Bar and Toolbar225 Creating Menu Items on the Menu Bar225 Creating the Toolbar233 10 chapter 27 Deploying your VB 2017 Applications239 Appendix244 Index245 11 chapter 1 Introduction to Visual Basic 2017 A brief description of Visual Basic 2017 Getting to know the Visual Basic 2017 Integrated Development Environment A Brief Description of Visual Basic 2017 VisualBasicisathird-generationev