Slide 9.10: User-defined functions
Slide 9.12: Arrays
Home

User-Defined Functions (Cont.)

 using System;
 using System.Windows.Forms;

 namespace WindowsFormsApp3 {
   public partial class Form1 : Form {
     public Form1( ) { InitializeComponent( ); }

     private void Compute_Click( object sender, EventArgs e ) {
       string presentval = PV.Text;
       string interest   = rate.Text;
       string period     = years.Text;
       double futureVal  = FV( presentval, interest, period );
       Microsoft.VisualBasic.Interaction.MsgBox(
           "The future value is" + futureVal );
     }

     public double FV( string PV, string i, string n ) {
       double result;
       result = 1 + double.Parse( i ) / 100;
       result = Math.Pow( result, int.Parse( n ) );
       result = double.Parse( PV ) * result;
       return ( result );
     }
   }
 }

In order to make the VB MsgBox Microsoft.VisualBasic.Interaction.MsgBox work for C#, add the Microsoft.VisualBasic by using the Reference Manager:
  1. Right click the project WindowsFormsApp2 in the Visual Studio,
  2. Select the option Add, and
  3. Select the option Reference....