Visual Basic Code For Simple Interest



Home > Articles > Programming > Windows Programming

Output: Write First Program in Visual basic. How to Concat two string in Visual basic. + or the & operator is used to Concat two or more string in Visual basic. Below is the code to Concat two string in visual basic. Which contains 3 strings str1, str2,str3. This code does not rely on using Adobe Acrobat or any other object library to determine the page count. It uses straight Visual Basic.NET code to open a PDF. More Special Folders.

Visual
  • Background Information. The calculator application does simple arithmetic operations.
  • The following Visual Basic project contains the source code and Visual Basic examples used for Compound Interest Calculator. This is my 10th Code for the beginners with easy code.
  1. Sample Application: Calculating a Future Value
< BackPage 5 of 7Next >
This chapter is from the book For

Visual Basic Code For Simple Interest Calculator

Sams Teach Yourself Visual Basic .NET in 21 Days

This chapter is from the book

This chapter is from the book

Sample Application: Calculating a Future Value

Now that you have explored creating and using variables and procedures, you can create an application that performs an investment calculation. This application will enable you to explore the lovely benefits of regular investing and compound interest. This sample Console application will avoid the complexity that a graphical user interface would add. Listing 3.4 shows the output from one run of the program.

Listing 3.4 The Investment Calculator

CodesVisual basic codes list

Here we see the result of starting with a $10,000 balance and adding $200 per month for 30 years, at a constant 5 percent interest.

The program requires the user to enter the four values (Initial Balance, Annual Interest, Monthly Deposit, and Years of Investment). In turn, the program calculates the final balance. This calculation is known as the Future Value (FV) calculation, and Visual Basic .NET includes it as one of its built-in functions. The formula for Future Value is

The following steps outline this procedure so that you can better understand how it works:

  1. Begin by creating a new project in Visual Basic .NET. Select a new Visual Basic Console Application. Visual Basic .NET creates a new project with one module.

  2. Close the file window and rename the file using the Solution Explorer. Right-click on the filename Module1.vb in the Solution Explorer and select Rename. Change the filename to modInvest.vb.

  3. Change the name of the Startup Object, also. Right-click on the project in the Solution Explorer and select Properties. On the General page, change the Startup Object to Invest. This should be in the drop-down list.

  4. You're ready to begin coding. As a minimum, you need four variables to hold the user's input. Declare the variables as shown in Listing 3.5. Most of these values are floating point numbers, with the exception of Years. These declarations should occur between the Module line and the Sub Main() line because these will be Module-level variables.

  5. Listing 3.5 Declarations for the Future Value Calculation

  6. Use the Main routine to call each of the routines that will get the user input, do the calculations, and display the output, as in Listing 3.6.

  7. Listing 3.6 Main Routine

    In Listing 3.7, each of the major functions of the application is a separate subroutine or function. This enables you to more easily change the techniques for getting input or display output later.

  8. Add the code in Listing 3.7 to allow the user to enter information. The procedure does not take any parameters, nor does it return a value. Because this is a Console application, you'll use the Console.Read routine to get values.

  9. Listing 3.7 The Input Console.Read Routine

    Notice that the GetInputValues subroutine calls the GetValue function. This is an example of creating support routines. Rather than rewrite the code to prompt the user many times, pull the code out and create a procedure to perform the task. The resulting code in GetInputValues is therefore simplified.

  10. Write the routine that will display the output when it is calculated. Eventually, this might be displayed in a window, but for now, use the Console.WriteLine procedure, shown in Listing 3.8, to display the information. This procedure should take the value to display, and return nothing.

  11. Listing 3.8 The Output Console.WriteLine Routine

    This is a simple routine, consisting of a series of Console.WriteLine calls to display the entered values and the result of the calculation.

  12. Perform the FV calculation. This routine should take the four values as parameters, and return the result of the calculation. As it has a return value, this procedure is a function. Listing 3.9 shows the CalculateFV function.

  13. Listing 3.9 The CalculateFV Function

    Just as with the GetInputValues, you could have pulled out the code that calculated the decTemp value. However, because you only need this calculation in this routine, and likely won't need it again, you don't.

    Listing 3.10 shows the full code for the sample application.

    Listing 3.10 The Complete Investment Calculator

  14. Run the application. The output should be similar to that shown at the beginning of this section. You can run the application from the IDE by clicking the Play button on the toolbar. However, it is likely that the window that pops up with the application will go away too quickly for you to see the answer. Instead, run the program from the command prompt by running the executable created.

You can try a frightening experiment with this calculator. Enter deposit values representing the money you would normally spend on a vice (lunch at work, cigarettes, electronic gadgets) each month. The resulting Future Value can often be disturbing.

Visual Basic Codes List

Related Resources

Visual Basic 2012 Code

Simple
  • Book $31.99

Visual Basic Codes For Excel

  • eBook (Watermarked) $22.39

Visual Basic Codes Pdf

  • Book $96.32