March 2017 - Archive

Monday, March 27, 2017

Introduction To Programming Using Microsoft Visual Basic – Tutorial 2.

March 27, 2017
welcome to Introduction To Programming Using Microsoft Visual Basic – Tutorial 2. did you miss the first Tutorial don't worry you can click here to read it now below link:

Objectives, Below are what i m expecting you to know by the end of this tutorial:

  • Understand how to declare and initialize variables and constants
  • Understand the different primitive data types that exist in Visual Basic
  • Learn how to use Strings
  • Learn how to write a program that receives input from the user
Variables and Data Types in Visual Basic
In order to make use of data in your program, you needvariables. A variable is a storagecontainer for your data. Depending on the purpose and size of information you want to work with, data are classified into various categories called datatype.

Variables are created to hold values from a specific data type. Here is an example:

Dim studentAge As Integer

In the statement above, studentAge is a variable created as a container for Integercategory of data. That means it is capable of accommodating whole numbers only.
There are 15 data types defined in Visual Basic. These data types are called primitive data types.

For more information, Visit the MSDN Microsoft site here

Declaring Variables

To make use of variables, you first have to create them. This process is called declaration. To create variables use statement like this:

Dim varNameAsdatatype

Dim: Short for Dimension. It is a keyword for creating variable.

varName: Place holder for name of the variable. A variable name can be any valid identifier. An identifier is any series of characters consisting of letters, digits and underscores (_). Identifiers cannot begin with a digit, cannot contain spaces, cannot be a keyword, and cannot contain any special character. Some valid examples of variable names are studentName, candidate1, second_semester. But2Semester, student Name, MyClass are not valid variable names.
As datatype: Tells the computer what type of data will be stored in the variable.

Dim courseName As String
Dim grade As Char
Dim score As Double
Dim isPromoted As Boolean

  • Variables of different type can be declared in one statement with each variable declaration separated by comma. The last example can be written as:

Dim courseName As String, grade As Char, score As Double, isPromoted As Boolean

  • Variables of the same type can be declared in one statement with each variable in the declaration separated by comma. For example:
Dim score, cgpa As Double

Initializing Variables
Variables are not just declared (created). They are meant to contain some data (values). Data are stored in variables by assignment statements. Here is an example:

Dim regNo As String

In the statements above, the first statement declares a variable regNo that is capable of holding String data. The second statement (in bold) assigns the string “D13CS1003” to the variable declared previously. The statement is read as regNo gets the value “D13CS1003”.
Notice the “=” binary operator. This is called the assignment operator (more on this in the next Lab).

You can initialize a variable at the same time you declare it. It’s very handysometimes and always easy to do. For example the previous example can be written as:
Dim regNo As String=”D13CS1003”

Constants are different from variables in the sense that their values do not change during the running of the program.

The format to declare a constant is:

ConstConstantNameAsDataType = Value

Const Pi As Single=3.142
Const Temp As Single=37
Const Score As Single=100

Complete the following table:
Variable Declaration
Or Assignments
Correct or Incorrect?
If Incorrect, why?
Correction or Better Choice if any (whether correct or incorrect)
Dim Name as Integer

Dim m_FirstName as Integer

Dim m_Money Earned as Integer

Dim f_Currency as String

Dim f_ Person as String

Dim m_Name as String

Dim GoldbachNo as Integer

Dim m_PizzaOrder

Dim !Factorial as Double

Dim m_Chemicalppms as Double

Dim x, y, z as Integer

Dim m_Num1 as Integer, m_Num2 as Integer

txtCarPayment.txt = m_CarPayment

TextOrderNum.Text = m_OrderNum

txtCarPayment.txt = m_CarPayment

Distance = txtDistance

print "Show me the $ "; m_Money "!!!"

m_FibonacciNum = "45"


Strings are the most important data types in computer languages. String (or string literal) is one among the primitive data types in Visual Basic. A string is a sequence of characters (including space character) enclosed by double quotes (“ ”).

String Concatenation Operator
Two or more strings can be merged to form one string by using the string concatenation operator (& or +). The concatenation operator can also be used to join a string literals and variables that can be converted to string.
For example:
Welcome to ”& ”Visual Basic Programming” becomes
Welcome to Visual Basic Programming”

Welcome to Visual Basic ”+regNobecomes
Welcome to Visual Basic D13CS1003”

Creating the Greetings project
Let’s put into practice what we have just learnt above by creating an application that welcomes you to visual basic programming.
  1. Open Microsoft Visual Studio IDE if you have not yet done so.
  2. Create a project called Greeting under a solution called Lab02. Remember how you created a project onlab01.
  3. Rename Module1.vb file in the Solution Explorer to GreetMe.vb
  4. In the Main Subroutine, declare a variable called stdName that can hold String data.
  5. Initialize stdName to hold your name.
  6. Output a greeting message with the variable declared previously included in the output. (Hint use & operator).
  7. Save and execute your application.

String Methods
There are several String methods. Consider this code snippet:
Dim stdName As String
stdName=”John Doe”
From the above statements, stdName is a variable of type String which is initialized to “John Doe”.
To convert all characters in stdName variable to lowercase, we write;
To convert all characters in stdName variable to uppercase, we write;
To check if the variable contains the character ‘e’ we write;
this will return true (Boolean) if stdName contains the string ‘e’ else it will return false.
To check the position of a character say, “o”, we write;
this will return 1. Why?
To check the last position of a character say, “o”, if it occurs more than once, we write;
what will be the output of above statement?

There are other string methods available. You can explore some (but not all) of them via these resource links:

Program that receives input from user
So far you have been writing programs that get its data from variables declared within it. It is possible to get data from various source including files, keyboard, network etc.
Let’s rewrite the previous program but in this case, it will get your name from user input via keyboard.

  1. Create a project called DynamicGreetings in Lab02 Solution.
  2. Rename the default module created by the IDE to GreetMe.vb
  3. In the Main Subroutine, enter the following code:

Dim stdName As String
Console.WriteLine(“Please enter your name: ”)
stdName= Console.ReadLine()
Console.WriteLine(“Welcome to Visual Basic Programming ” &stdName)

  1. Save the project using Save All command.
  2. Run the program.
Notice the use of ReadLine() method of Console class. The ReadLine() method causes the project to block until the user enters a value and press enter key. ReadLine() returns the value entered as string datatype.

  1. Write a program that prompt a user to enter the year of admission into Diploma program then outputs the expected year of graduation. For example if the user enters 2010, then the expected date of graduation will be 2012 (i.e. 2010 + 2).
Save the project as GraduationCalculator under Lab02 Solution

  1. Write a program that prompts a user for his/her name. it should the name in:
  1. Lower case
  2. Upper case and
  3. Length of the name (i.e. number of characters)
Hint: use name.length().toString() function
Save the project as NameAnalizer under Lab02 Solution.

I tried as much as possible to give solution to the exercise for you in The first tutorial here click, to read it now. And to check if you are correct please if you like this tutorial share with your friends and keep coming back.


What is Computer system?

Computer is defined as an electronic system that performs the following activities based on a set of instructions (program): 

  • accepts data through the input unit
  • process the accepted data in the processing unit
  • store the processed data (information) and
  • produce the processed data (information) through the output unit.

Data is defined as raw-fact. e.g numbers, characters, audio, video, images, etc.

Data can be processed through a computer based on program (software). The outcome (result) of processing is referred to as information.

The result of processing (information) can be stored in a storage media for later use or be produce through the output unit.

Characteristics of a Computer system

  1. Speed: Modern computers have incredible speed of processing. Jobs that a number of personals will do in many days, computer system can do it in some minutes.
  1. Accuracy: Computer can ensure consistently very high degree of accuracy in computations. It processes data according to the sequence of instructions . Hence, if input data and procedures are correct, the output will be consistently accurate. Unlike human beings that are liable to make mistakes.
  1. Huge storage and fast retrieval: Computer has huge storage capability. Secondary or auxiliary storage devices are used for permanent storage. Modern computers have enormous secondary storage capacity, e.g., a PC hard disk can store more than 80 GB of data.
  1. Versatility: computers are capable of performing almost any task that has a series of finite logical steps (instructions). Computers can be used for communications, process control, research, weather forecasting, healthcare, online trading, education, training, defense applications and so on.
  1. Free from fatigue: Computer is free from fatigue. It does not get tired of work and never loses concentration. It can perform operations with the same degree of speed and accuracy for any extent of time continuously, with the same amount of efficiency as the first transaction.
  1. Networking capability: Computers can be interconnected into a network. Network in turn can be connected to other networks. Networks extend the capability of computers.
  1. Programmable: Computer can be programmed and reprogrammed to function automatically . It executes jobs as programmed for any stretch of time until the condition to terminate is satisfied.

Sunday, March 26, 2017

Introduction To Programming Using Microsoft Visual Basic – Tutorial 01.

Introduction to Programming or Introduction to Visual Basic is a program run in IYA ABUBAKAR COMPUTER CENTER in AHMADU BELLO UNIVERSITY and I am giving to you now the very first tutorial on this subject but first I conclude that by now you should have been familiar with what Programming or Visual Basic Programming Software is but if you are not familiar with it I got you covered I explained every thing in details below. But first I will be starting with:


  • Know how to locate and open Microsoft Visual Studio IDE from within your computer
  • Familiarizing yourself with the Visual Studio IDE interface
  • Learn how to create and run simple console application in Visual Basic directly from Visual Studio IDE and Command line

How To Locate and Open/Run Microsoft Visual Studio IDE

Microsoft Visual Studio is an Integrated Development Environment (IDE) for creating, running and debugging programs (applications) written in a variety of supported programming languages (in this case, Visual Basic). An IDE is a way of bringing together a suite of tools that makes developing software a lot easier.
There are various ways to start Microsoft Visual Studio depending on your system configuration. Locate and fire up your Visual Studio IDE and see what you have got:
  1. From Start Menu: Select Start > All Programs > Microsoft Visual Studio 2010 >Microsoft Visual Studio 2010
Locate and Open/Run Microsoft Visual Studio

  1. From Desktop: If a shortcut labelled Microsoft Visual Studio 2010 exist on the desktop, double click on it to start the application.

Once the Visual Studio IDE begins execution, the Start Page displays. You’ll probably see a screen similar to the one below:

Locate and Open/Run Microsoft Visual Studio IDE 
The Start Page has a place for recent projects you’ve had open. From here, you could click on a recent project to open it or select a new project and start from scratch. The Start Page also has online help and some tutorials available just by clicking on the appropriate option. Feel free to look at them when you have time. By default the Start Page opens every time you start Visual Studio.

Menus and Toolbars Of Microsoft Visual Basic.

As explained earlier, an IDE (e.g. Visual Studio) is a collection of tools that makes programming easier. Developers (like you) make use of these tools during software development by executing some commands. These commands are grouped into menus. 
In Microsoft Visual Studio, menus are located in the menu bar. Each menu in the menu bar contains a collection of related commands. The Visual Studio menu bar is also dynamic, which means the set of menus displayed depends on what you are currently doing in the IDE.

Menus and Toolbars Of Microsoft Visual Basic.

Instead of navigating through series of menus to locate a command, Visual Studio provides quick access to frequently used commands via the toolbar which contains icons that represent commands. You may be familiar with some of these icons in other windows application like Microsoft Word. The toolbar is also dynamic in the sense that icons become active based on what you are currently doing. 

Creating Your First Console Application In Microsoft Visual Basic.

To finish your exploration of the Visual Studio IDE, you need to create an application so that the windows shown earlier have some interesting content for you to look at.

In Visual Basic, you create an application by developing a project. The project is stored in a folder and contains files and other folders. The finished executable program is stored in the bin folder which is located in the project folder and has an .exe extension.
  1. Select File > New Project… to display the New Project dialog. Alternatively you can click on the New Project icon on the toolbar or use the keyboard shortcut Ctrl+Shift+N

     Creating Your First Console Application In Microsoft Visual Basic. 
    How To Create Your First Console Application In Microsoft Visual Basic. 
  1. From the Installed Templates: section, select Windows if it is not selected.
  2. From the Templates: section, select Console Application if it is not selected.
  3. In the Name: field type “Welcome” as shown in the figure above.
  4. Click on the Ok button.
Having done with that, you get a window similar to this:

Creating Your First Console Application In Microsoft Visual Basic.

At this point, you can see that various windows in the IDE are beginning to show their purposes. An example is the Solution Explorer. The Solution Explorer displays the folder structure of your projects located within a Solution. A solution can have one or more projects and projects are made up of entities like Classes, Modules, Forms, images, etc.

By default, Visual Studio IDE creates a module called Module1 whenever you create a new project.

A module is just a logical collection of methods – methods perform a task and may return a value when the task is completed.

Every Visual basic code is stored in a file that ends with .vb extension. From Solution Explorer you can see that Module1 Module is stored in a file called Module1.vb. This name is not descriptive. So let’s rename the file to WelcomeModule.vb.
  1. On the Solution Explorer window, Click on Module1.vb.
Notice the changes in the Properties Window. The Properties window displays information about currently selected item in the Solution Explorer or Design Window.
  1. On the Properties Window Change the File Name property to WelcomeModule.vb.
  2. Press Enter key from your keyboard. Notice that the Module name in the code also changed to reflect the file name.

Few notes on Visual Basic syntax

A keyword is a reserved word in the Visual Basic language. Keywords are used to perform a specific task in the computer program. E.g. Dim, Rem, If, Else, End, Sub

Comments are used by programmers to clarify the source code. All comments in Visual Basic follow either the ' character or the Rem keyword. Comments are ignored by the Visual Basic compiler.

White space in Visual Basic is used to separate tokens in the source file. It is used to improve readability of the source code. The amount of space put between tokens is irrelevant for the Visual Basic compiler. 
A statement in Visual Basic is a complete instruction. A statement can be used for declaration or to initiate actions.

A line continuation character ( _ ), is used if a statement spans more than one line otherwise compilation will fail.

Modifying WelcomeModule.vb code

  1. Click on WelcomeModule.vb tab to view the editor window
  2. In between Sub Main() and End Sub , type
Console.WriteLine(“Welcome to Visual Basic Programming!”)
console.write(“Welcome to Visual Basic Programming!”)

Saving your project
  1. Save your project by selecting File > Save All on the toolbar or by using the keyboard shortcut Ctrl+Shift+S. For the first time, the Save Project Window appears.
Saving your project
  1. On the Location: field, type in the address. The format should be:
C:\VBPracticalProjects\<<your name>>
where <<your name>> will be replaced by your name. For example,
All subsequent practical exercises should be located in that folder.
  1. In the Solution Name, type in Tutorial01 since this is Tutorial01 of the tutorial practical. If you were on Tutorial02 the Solution Name will be Tutorial02 and so on.
  2. Make sure the Create directory for solution is checked.
  3. Click on Save button.
Running your first console application in Microsoft Visual Basic
You are now ready to compile and execute your application.
To compile the application:
  1. On the menu bar, select Build > Build Welcome. This creates a file called Welcome.exe in C:\VBPracticalProjects\Binoosmart\Part01\Welcome\bin\Release or C:\VBPracticalProjects\Binoosmart\Part01\Welcome\bin\Debug depending on your IDE configuration.
To execute the application:
  1. From the IDE select Debug > Start Without Debugging or use the keyboard shortcut Ctrl+F5.
  2. From windows command prompt, use cd command to navigate to the folder where Welcome.exe file is located in your project.
  3. Type the name of the .exe file. In this case, Welcome.exe.
  4. Press Enter key from the keyboard.
Exercises For You, To Test What You Just Learn The Solution Is Below It.
  1. What is the difference between Console.WriteLine() and Console.Write() methods?
  2. Modify the Welcome project so that it displays the following text in one line.
Welcome to Visual Basic programming using Microsoft Visual Studio Integrated Development Environment!”

  1. Write an application (MyProfile) that displays your profile. An example output is displayed below. The output of the application should correspond to you.

Phone No.: +2348168374589

Name: Yakubu Binuyaminu

Sex: Male

Country: Nigeria

State: Kogi State

Religion: Islam

Save and run the Project as MyProfile under Tutorial01 Solution.
  1. Write an application that will output something similar to the output in the figure below:
Save the application as VShape under Tutorial01 Solution. (Hint: use spaces to separate the asterisks).

When you are done, Tutorial01 Solution should contain three projects namely:
  • Welcome,
  • MyProfile, and
  • Vshape

  1. The Basic difference between Console.WriteLine() and Console.Write() methods is that Console.WriteLine() will make each sentence or the item you want to display in be on a separate lines, each will have their lines. While the Console.Write() method is otherwise every statements been display by this method will bring out or display all output in one line. I think that English is Simple enough.
  2. Sub Main ()
      console.write(“Welcome to Visual Basic programming using Microsoft Visual Studio Integrated Development Environment!”)
      End Sub
      End Module
  3. Sub Main ()
      console.writeline(“Phone No.:    +2348168374589”)

      console.writeline(“Name:         Yakubu Binuyaminu”)

      console.writeline(“Sex:          Male”)

      console.writeline(“Country:      Nigeria”)

      console.writeline(“State:        Kogi State”)

      console.writeline(“Religion:     Islam”)
      End Sub
      End Module
  4. Sub Main ()
      console.writeline(“*              *”)
      console.writeline(“  *          *”)
      console.writeline(“    *      *”)
      console.writeline(“      *  *”)
      console.writeline(“        *”)
      End Sub
      End Module
    Watch out for the Tutorial 2 so that you wouldn't miss future tutorials like this one please subscribe with your Email. And keep coming back.

    Alright thanks for reading please if you like this tutorial share with your friends and don't hesitate to ask me any question in the comment section.
List Of the Tutorials: