cittadelmonte.info Fiction Visual Basic 2008 Made Easy Ebook

VISUAL BASIC 2008 MADE EASY EBOOK

Saturday, December 15, 2018


Visual Basic Made Easy is written by Dr. Liew, the webmaster of the Visual Basic 6 Made Easy, Visual Basic Made Easy, Visual Basic Made. II. Disclaimer Visual Basic Made Easy- A complete tutorial for beginners is an independent publication and is not affiliated with, nor has it been authorized. Visual Basic Made Easy- A complete tutorial for beginners is an independent publication and is not affiliated with, nor has it been authorized, sponsored.


Author:VICKEY WASZMER
Language:English, Spanish, Portuguese
Country:Sudan
Genre:Lifestyle
Pages:186
Published (Last):25.01.2016
ISBN:628-1-78954-936-9
ePub File Size:30.54 MB
PDF File Size:10.68 MB
Distribution:Free* [*Regsitration Required]
Downloads:46158
Uploaded by: SUNSHINE

Buy Visual Basic Made Easy: Read 1 Kindle Store Reviews - cittadelmonte.info Visual Basic Made Easy is written by the webmaster of the poupular online Visual Basic Tutorial, cittadelmonte.info By reading this book,you can. VISUAL BASIC MADE EASY is an eBook written by our webmaster, cittadelmonte.info to complement our Online Visual Basic Tutorial.

Disclaimer Visual Basic 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 Corporation. Liability The purpose of this book is to provide a basic guide for people interested in Visual Basic 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. Copyright 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. Acknowledgement I would like to express my sincere gratitude to many people who have made their contributions in one way or another to the successful publication of this book. My special thanks go to my children Xiang, Yi and Xun.

Form, as shown in Figure The code must be entered between Private Sub End Sub. Example 5. Yellow Me. Blue End Sub. The first line of the code changes the title of the form to My First VB Program, the second line changes the foreground object to yellow in this case, it is a label that you insert into the form and change its name to Foreground and the last line changes the background to blue color.

Me is the name given to the Form1 class. We can also call those lines Statements. So, the actions of the program will depend on the statements entered by the porgrammer. Here is another example. The keyword Dim is to declare variables name1, name2 and name3 as string, which means they can only handle text. The output is shown in Figure below:.

Managing VB Data Assigning values to the variables. Getting to know various arithmetic operators in Visual Basic We come across many types of information and data in our daily life.

For example, we need to handle data such as names, addresses, money, date, stock quotes, statistics and more everyday. Similarly in Visual Basic , we have to deal with all sorts of data, some can be mathematically calculated while some are in the form of text or other forms. VB divides data into different types so that it is easier to manage when we need to write the code involving those data.

Examples of numeric data types are examination marks, body height, and body weight, the number of students in a class, share values, prices of goods, monthly bills, fees and more. Visual Basic divides numeric data into seven types, depending on the range of values they can store. Calculations that only involve round figures or data that do not need precision can use Integer or Long integer in the computation.

Programs that require high precision calculation need to use Single and Double decision data types, they are also called floating-point numbers. For currency calculation, you can use the currency data types. Lastly, if even more precision is required to perform calculations that involve a many decimal points, we can use the decimal data types. These data types summarized in Table Currency 8 bytes ,,,, Table Numeric Data Types.

The non-numeric data comprises text or string data types, the Date data types, the Boolean data types that store only two values true or false , Object data type and Variant data type. In some cases, we need to add a suffix behind a literal so that VB can handle the calculation more accurately. Some of the suffixes are displayed in Table In addition, we need to enclose string literals within two quotations and we enclose date and time literals within two sign.

Strings can contain any characters, including numbers. The following are few examples: The contents of the variables changes every now and then, just like the mail boxes.

In term of VB, 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. If you fail to do so, the program will show an error.

They are normally declared in the general section of the codes' windows using the Dim statement. The syntax is as follows: For the variable-length string, just use the same format as example 6. However, for the fixed-length string, you have to use the format as shown below: The expression could be a mathematical expression, a number, a string, a Boolean value true or false and etc. The following are some examples: Example 6.

Computers can perform mathematical calculations much faster than human beings do. However, computer itself is not able to perform any mathematical calculations without receiving instructions from the programmer or user. In VB, we can write code to instruct the computer to perform mathematical calculations like addition, subtraction, multiplication, division and other kinds of arithmetic operations. In order for VB to carry out arithmetic calculations, we need to write code that involves the use of various arithmetic operators.

VB arithmetic operators are very similar to the normal arithmetic operators, only with slight variations. The list of VB arithmetic operators are shown in table below:. In this example, you need to insert two Text boxes, four labels and one button. Click the button and enter the code as shown below. Note how the various arithmetic operators are being used. When you run the program, it will perform the four basic arithmetic operations and display the results on the four labels.

In this example, the program calculates the length of hypotenuse given the length of the adjacent side and the opposite side. The syntax for Pythagoras Theorem in Vb is. Obesity has proven by the medical experts to be one of the main factors that bring many adverse medical problems, including the heart diseases. If your BMI is more than 30, you are considered obese. You can refer to the following range of BMI values for your weight status: The BMI calculator is a Visual Basic program that can calculate the body mass index, or BMI of a person based on the body weight in kilogram and the body height in meter.

If you only know your weight and height in lb and feet, then you need to convert them to the metric system you could indeed write a VB program for the conversion. The output is shown in the Figure below.

In this example, your height is 1. The reading suggests that you are healthy.

Visual Basic 2008 Made Easy

From the above examples, you can see that perform arithmetic operations is relatively easy. Here are more arithmetic projects you can try to programs, they are area of a triangle, area of a rectangle, area of a circle, volume of a cylinder, volume of a cone, volume of a sphere, compound interest, future value, mean and more. Chapter 8 String Manipulation Learn how to manipulate Strings String manipulation is an important part of programming because it helps to process data that come in the form of non-numeric types such as name, address, city, book title and etc.

An error occurs if you do not following rule, as shown in the following example. Example 8. There are many string manipulation functions that are built into VB but I will only discuss a few here and will explain the rest of them in later Chapters. Click Label1. Text End Sub. The format is Microsoft. Right "Phrase",n Where n is the starting position from the right of the phase where the portion of the phrase is going to be extracted.

For example, Microsoft. Text Label1. Right text1, 4 End Sub The above program will return four right most characters of the phrase entered into the textbox, as shown in Figure Left "Phrase",n Where n is the starting position from the left of the phase where the portion of the phrase is going to be extracted.

In previous Chapters, we have learned how to write code that accepts input from the user and displays the output without controlling the program flow.

In this chapter, you will learn how to write VB code that can make decision when it process input from the users, and control the program flow in the process. Decision making process is an important part of programming because it helps solve practical problems intelligently so that it can provide useful output or feedback to the user.

For example, we can write a VB program that can ask the computer to perform certain task until a certain condition is met, or a program that will reject non-numeric data.

In order to control the program flow and to make decisions, we need to use the conditional operators and the logical operators together with the If control structure.

They are also known as numerical comparison operators. Normally they are used to compare two values to see whether they are equal or one value is greater or less than the other value. The comparison will return true or false result.

These operators are shown in Table In this case, using numerical comparison operators alone is not sufficient, we need to use additional operators, and they are the logical operators. These logical operators are shown in Table However, you can also compare strings with the above operators.

In making strings comparison, there are certain rules to follows: There are three types of If control structure, namely If Then statement, If Else statement and If ElseIf statement.

Then Statement The If Then statement instructs the computer to perform a certain action specified by the VB expression if the condition is true.

However, when the condition is false, no action will be performed. The general format for the if On the other hand, if the number entered is less than or equal to , you don't see any display. Else Statement Using just If Then statement may not be very useful in programming and it does not provide choices for the users. In order to provide a choice, we have to use the If Else Statement. This control structure will ask the computer to perform a certain action specified by the VB expression if the condition is true.

And when the condition is false, an alternative action will be executed. You win a lucky prize! On the other hand, if the number entered is less than or equal to , you will see the "Sorry, You did not win any prize" statement Example 9. You win a lucky prize" Else Label2. This means that both the conditions must be fulfilled in order for the conditions to be true, otherwise the second block of code will be executed.

In this example, the number entered must be more than and the age must be more than 60 in order to win a lucky prize, any one of the above conditions not fulfilled will disqualify the user from winning a prize. ElseIf Statement If there are more than two alternatives, using just If Else statement may not be enough.

In order to provide more choices, we can use the If ElseIf Statement. Example 9. End Select Structure. In the previous Chapter, we have learned how to control the program flow using the If ElseIf control structure. In this chapter, you will learn another way to control the program flow, that is, the Select Case control structure.

However, the Select Case control structure is slightly different from the If The difference is that the Select Case control structure basically only make decision on one expression or dimension for example the examination grade while the If ElseIf statement control structure may evaluate only one expression, each If ElseIf statement may also compute entirely different dimensions.

Select Case is preferred when there exist many different conditions because using If ElseIf statements might become too messy. Text Select Case mark Case 0 to 49 Label1. Looping Understanding and using the DoLoop Understanding and using the WhileEnd while Loop Visual Basic allows a procedure to be repeated as many times as long as the processor could support.

This is generally called looping. Looping is required when we need to process something repetitively until a certain condition is met. For example, we can design a program that adds a series of numbers until it exceed a certain value, or a program that asks the user to enter data repeatedly until he or she keys in the word 'Finish'. In Visual Basic , we have three types of Loops, they are the For Next loop, the Do loop.

End while loop Next Loop The format is: The command to use is Exit For. To exit a For Next Loop, you can place the Exit For statement within the loop; and it is normally used together with the If.. Then statement. For its application, you can refer to Example Example The program will compute the subtraction as follows: The syntax to use is known as Exit Do. Lets examine the following example. The above example can be rewritten as Do TextBox1. In the design stage, you need to insert a ListBox into the form for displaying the output, named List1.

The program uses the Add method to populate the ListBox. The statement ListBox1. End While Loop The structure of a While. End While is very similar to the Do Loop. It takes the following format: While condition Statements End While The above loop means that the loop will end when the condition is met. A function is similar to a normal procedure but the main purpose of the function is to accept a certain input and return a value that is passed on to the main program to finish the execution.

There are two types of functions, the built-in functions or internal functions and the functions created by the programmers. The general format of a function is FunctionName arguments The arguments are values that are passed on to the function. In this Chapter, we are going to learn two very basic but useful internal functions of Visual Basic, i. This format is as follows: The Style Value determines the type of command buttons appear on the message box, as shown in Table The Title argument will display the title of the message board.

In fact, VB6 will automatically shows up a list of names constant where you can select one of them. The types of buttons clicked by the user determine the values. It has to be declared as Integer data type in the procedure or in the general declaration section.

Table shows the values, the corresponding named constant and buttons. A function is similar to a normal procedure but the main purpose of the function is to accept a certain input and return a value which is passed on to the main program to finish the execution.

To make the message box looks more sophisticated, you can add an icon besides the message. There are four types of icons available in VB as shown in Table Figure In VB, you can use the following format: The arguments are explained as follows: However, the format won't work in VB because InputBox is considered a namespace.

Visual Basic Tutorial

So, you need to key in the full reference to the Inputbox namespace, which is Microsoft. InputBox "What is your message? Show userMsg Else MessageBox. We have learned about the basic concept of function as well as the MsgBox and InputBox functions in Chapter In fact, I have already shown you a few string manipulation functions in Chapter 8, they are the Len function, the Left function and the Right Function.

In this Chapter, we will learn other string manipulation functions. The format of the Mid Function is Mid phrase, position,n Where phrase is the string from which a part of text is to be retrieved.

InputBox "Enter your phrase" Label1. After a phrase is entered and the OK button is pressed, the label will show the extracted text starting from position 2 of the phrase and the number of characters extracted is 6. The output are shown in Figure and Figure Right Phrase, n Where n is the starting position from the right of the phase where the portion of the phrase is going to be extracted.

For example: Right myword, 4 End Sub The output. Left Phrase, n Where n is the starting position from the right of the phase where the portion of the phrase is going to be extracted.

For example, you can write the following code to extract the left portion any phrase entered by the user.

Left myword, 4 End Sub. The format is Trim Phrase.

Visual Basic Tutorial

The format is Ltrim Phrase. The format is Rtrim Phrase. The format is Instr n, original phase, embedded phrase Where n is the position where the Instr function will begin to look for the embedded phrase. On the other hand, the Lcase function converts all the characters of a string to small letters.

UCase Phrase Microsoft. LCase Phrase. Some of the characters may not be displayed as they may represent some actions such as the pressing of a key or produce a beep sound. The format of the Chr function is Chr charcode and the format of the Asc function is Asc Character The following are some examples: Chapter 14 Mathematical Functions Learning How to use the Mathematical functions We have learned how to Vb can perform arithmetic functions using standard mathematical operators.

However, for more complex mathematical calculations, we need to use the built-in math functions in VB There are numerous built-in mathematical functions in Visual Basic which we will introduce them one by one. The syntax is Math. Abs number The Math keyword here indicates that the Abs function belongs to the Math class. However, not all mathematical functions belong to the Math class.

Exp number. Exp num1 Label1. However, when the number is negative, it will return smallest integer larger than the number. For example, Fix 9. For example Int 2. Log num1 Label1. The Rnd function returns a random value between 0 and 1. Random numbers in their original form are not very useful in programming until we convert them to integers.

After adding 1, you will get a random number between 1 and 6 every time you click the command button. For example, let say the random number generated is 0. The Format is Round n, m which means to round a number n to m decimal places. For example, Math.

Round 7. Round num1, 2 Label1. The Format function is a very powerful formatting function that can display the numeric values in various forms. There are two types of Format function, one of them is the built-in or predefined format function while another one can be defined by the users.

Displays the number without having separators between thousands and rounds it up to two decimal places. Standard Displays the number with separators or separators between thousands and rounds it up to two decimal places. Currency Displays the number with the dollar sign in front, has separators between thousands as well as rounding it up to two decimal places.

The Format Function. Click, Button5. Click, Button4. Click, Button3. Examples of user-defined formatting style are listed in Table Format Format 0. Users Defined Functions. Date and time can be formatted using predefined formats and user-defined formats. The predefined formats of date and time are shown in Table Displays the current date in long format. Displays current date in short format Display the current time in long format. Display the current time in short format.

Format Now, "G". And for "Long Time", you can use the abbreviated format "T". As for "Short Time", you may use the abbreviated format "t" Example Displays abbreviated name of the current month Displays full name of the current month. Click, Button2. For example, in the Font dialog box of any Microsoft Text editor like FrontPage, there are many checkboxes under the Effects section such as that shown in the diagram below. The user can choose underline, subscript, small caps, superscript, blink etc.

In Visual Basic, you may create a shopping cart where the user can click on checkboxes that correspond to the items they intend to buy, and the total payment can be computed at the same time as shown in Example EventArgs Handles BtnCalculate. If CheckBox3. If CheckBox6. ToString "c". Here is another example Example EventArgs Handles CheckBox1.

CheckedChanged If CheckBox1. Checked Then TextBox1. Font, TextBox1. Style Or FontStyle. Bold Else TextBox1. Style And Not FontStyle. EventArgs Handles CheckBox2. CheckedChanged If CheckBox2. Italic Else TextBox1. EventArgs Handles CheckBox3. CheckedChanged If CheckBox3.

Style Or. Underline Else TextBox1. The statement TextBox1. Italic will retain the original font type but change it to italic font style. Italic will also retain the original font type but change it to regular font style.

The other statements employ the same logic. However, it operates differently from the check boxes. While the checkboxes work independently and allows the user to select one or more items, radio buttons are mutually exclusive, which means the user can only choose one item only out of a number of choices. Here is an example that allows the users to select one color only.

EventArgs Handles RadioButton8. EventArgs Handles RadioButton7. EventArgs Handles RadioYellow. Click Label2. Although the user may only select one item at a time, he may make more than one selection if those items belong to different categories. For example, the user wish to choose T-shirt size and color, he needs to select one color and one size, which means one selection in each category.

This is easily achieved in VB by using the Groupbox control under the containers categories. After inserting the Groupbox into the form, you can proceed to insert the radio buttons into the Groupbox. Only the radio buttons inside the Groupbox are mutually exclusive, they are not mutually exclusive with the radio buttons outside the Groupbox.

In Example EventArgs Handles RadioL. EventArgs Handles RadioM. EventArgs Handles RadioS. Since the advent of the Internet and the World Wide Web, almost everyone is surfing the Internet for information. In addition, when we are talking Internet surfing, it refers to using a program to browse the World Wide Web; this type of program is called a browser. At the beginning of the Internet age, we have the primitive Internet browsing program called Gopher where you can only see text contents.

However, the famous Netscape Navigator soon replaced it. Moreover, much later Microsoft created the Internet explorer, a default browser that shipped with newer versions of Windows. Today, basically everyone navigates the Internet using commercially produced web browsers such the Internet Explorer produced by Microsoft or those open source browsers designed by the experts such Mozilla FireFox , Opera and the latest Chrome created by Google. However, is it cool if we can create our very own web browser that we can customize to our own taste and design?

Yes, you can do that in VB, and rather easy too. In this chapter, I will show you how to create a simple web browser and get it running in a few minutes.

First of all, start a new project in VB and name it with any name that you like. Here I am just using the name webbrowser. Change the name of Form1 to webbrowser and the text property to My First Web Browser and set its size property to , Next, you need to add a control so that your web browser can connect to the Internet, and this very engine is called the WebBrowser control, located in the Toolbox on the left side, set its size property to , Next, drag a text box and place it at the bottom of the WebBrowser control, this will be the address bar where the user can enter the URL.

Lastly, place a command button beside the text box and label it as Go. The design interface is shown in Figure below:. The Code The code for the web browser is surprisingly simple; it is only a single line code! Double click on the Go button and key in the following code: Click myWebBrowser.

Navigate TextBox1. Now run the program, type in any URL and click the Go button. You will be able to browse any web page you want. An error-free program can run smoothly and efficiently, and the user does not have to face all sorts of problems such as program crash or system hang.

Errors often occur due to incorrect input from the user. For example, the user might make the mistake of attempting to enter a text string to a box that is designed to handle only numeric values such as the weight of a person, the computer will not be able to perform arithmetic calculation for text therefore will create an error. These errors are known as synchronous errors. Therefore, a good programmer should be more alert to the parts of program that could trigger errors and should write errors handling code to help the user in managing the errors.

Writing errors handling code should be considered a good practice for Visual Basic programmers, so do try to finish a program fast by omitting the errors handling code. However, there should not be too many errors handling code in the program as it create problems for the programmer to maintain and troubleshoot the program later. VB has improved a lot in built-in errors handling compared to Visual Basic 6. For example, when the user attempts to divide a number by zero, Vb will not return an error message but gives the 'infinity' as the answer although this is mathematically incorrect, because it should be undefined Although it has a more advanced error handling.

We shall now learn how to write errors handling code in VB Division by Zero In this example, we will deal with the error of entering non-numeric data into the textboxes that suppose to hold numeric values.

Try again! If no error occur, it will display the correct answer. Try it out yourself. EventArgs Handles CmdCalculate.

End Try Structure VB has adopted a new approach in handling errors, or rather exceptions handling. It is supposed to be more efficient than the old On Error Goto method, where it can handles various types of errors within the Try End Try structure. End Try method. In this example, the Catch statement will catch the exception when the user enters a non-numeric data and return the error message.

Chapter 21 Reading and Writing Files Learning how to write program to read and write files In fact, the ability to store, retrieve and modify data makes a computer a powerful tool in database management. In this Chapter, we will learn how to manage data that is stored as a text file. Using text file is an easy way to manage data, although it is not as sophisticated as full fledged database management software such as SQL Server, Microsoft Access and Oracle.

Visual Basic allows the user to create a text file, save the text file as well as read the text file. It is relatively easy to write code for the above purposes in VB compared to VB6.

Reading and writing to a text file in VB required the use of the StreamReader class and the StreamWriter class respectively. StreamReader is a tool that enables the streaming of data by moving it from one location to another so that the user can read it.

For example, it allows the user to read a text file that is stored in a hard drive. On the other hand, the StreamWriter class is a tool that can write data input by the use to a storage device such as the hard drive.

To achieve that, first we need to include the following statement in the program code: Imports System. IO This line has to precede the whole program code as it is higher in hierarchy than the StreamReader Class. In Fact, this is the concept of object oriented programming where StreamReader is part of the namespace System. It has to be put on top of. The word import means we import the namesapce System. IO into the program.

Once we have done that , we can declare a variable of the streamReader data type with the following statement: StreamReader each time we want to use the StreamReader class. Now, start a new project and name it in whatever name you wish. Now, insert the OpenFileDialog control into the form because we will use it to read the file from the storage device. The default name of the OpenFileDialog control is OpenFileDialog1, you can use this name or you can rename it with a more meaningful name.

We will also insert a command button and change its displayed text to 'Open'. It is used by the user to open and read a certain text file. The following statement will accomplish the task above. It is used for displaying the text from a text file. In order to read the text file, we need to create a new instant of the streamReader and connect it to a text file with the following statement: The syntax is: ReadToEnd Lastly, we need to close the file by using the Close method.

The entire code is shown in the box below: The Code Imports System. EventArgs Handles BtnOpen. FileName TextBox1. ReadToEnd FileReader. Close End If End Sub. It also means saving the file. To accomplish this task, we need to deploy the StreamWriter Class. You also need to insert the SaveFileDialog control into the form as it is used to save the data into the storage unit like a hard drive.

The code is shown below: The code Imports System. FileName, False FileWriter. Write TextBox1. Text FileWriter. When you click the save button, the program will prompt you to key in a file name and the text will be save as a text file. Finally, you can combine the two programs together and create a text editor that can read and write text file, as shown in Figure Chapter 22 Creating and Managing Graphics Learning how to create and manage graphics Whether you want to build original programs from the ground up or take advantage of existing wizards, this book will help you design and debug your work - and accomplish all your goals!

This tutorial covers all essential Visual Basic knowledge. You can learn complete primary skills of Visual Basic fast and easily. It presents the basics of Visual Basic programming using direct and simple language. This book is a quick introduction to Visual Basic. NET programming language. It explains the very basics of the language with screenshots showing what is expected to see during development process. NET and. NET remoting. This practical introduction to VB will bring you up to speed on all the new features of this language by allowing you to work with them directly.

Get a focused, first look at the features and capabilities in Microsoft Visual Basic , Visual Studio , and the.

NET Framework 2.

This book engages through media sound, color, shapes, etc. Small Basic is a programming language that is designed to make programming extremely easy, approachable and fun for beginners.

This book is a very good overview of the basics of Machine Language. The book starts with an introduction to how computers work, what Binary and Hex are, and how they relate to programing. Microsoft QuickBasic and QBasic are very popular programming languages for beginners. This book will cover the usage of QBasic and most of it's functions.

This is a book on naming conventions, best coding practices and patterns written by the industry expert Steven Sartain. It take full advantage of the Microsoft. NET Framework - and write reusable, robust, and security-enhanced code. This book is the definitive tutorial and reference for the. It shows you how to transfer your skills and your code to the Pocket PC and other mobile and embedded smart devices. This book describes a simple method for generating an endless succession of beautiful fractal patterns by iterating simple maps and ordinary differential equations with coefficients chosen automatically by the computer.

In this lively, eye-opening, hands-on book, all you need is a computer and the desire to learn how to program with Visual Basic Express Edition. It will explain the basics of Visual Basic through task-oriented examples and a hands on approach. Please check this page daily!!! Book Site. Learn to Program with Visual Basic and.

Visual Basic Essentials Neil Smyth This book is intended to be of use to both novices looking to learn Visual Basic, and to those proficient in other languages to learn Visual Basic. Visual Basic Wikibooks This book takes a step-by-step approach, helping students understand the logic behind developing quality programs while introducing the Visual Basic language. A Programmer's Guide Jonathan E. Learn Visual Basic 6. Visual Basic 6 Tutorial DR. Upgrading Visual Basic 6.

WALTRAUD from Indiana
I do enjoy reading novels yesterday. Feel free to read my other articles. I am highly influenced by chicago.