BrainDump
  Home arrow BrainDump arrow Using Conditionals with User-defined Funct...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
BRAINDUMP

Using Conditionals with User-defined Functions in Visual Basic Applications in Excel
By: Codex-M
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 3
    2009-08-18

    Table of Contents:
  • Using Conditionals with User-defined Functions in Visual Basic Applications in Excel
  • Building the Function
  • Implementing the Function
  • Getting a URL's Filename Path

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Using Conditionals with User-defined Functions in Visual Basic Applications in Excel


    (Page 1 of 4 )

    In the first part of this three-part series I introduced you to building user-defined functions for Excel with a very simple example. You can build a much more powerful and versatile application with Visual Basic, however, when you use conditional statements. I will be demonstrating such an application in this second part of the series.

    Let’s continue our tutorial on making user-defined functions in MS Excel. In the first part, we discussed the programming steps required to make user-defined functions. We covered the programming syntax, and even provided some basic sample code illustrating a very simple user-defined functions application.

    In this article, we will go in-depth by examining other important aspects of how to make user-defined functions in Excel. This comprises a little more advanced techniques, such as implementing conditional statements within the Visual Basic code. 

    Okay, I'm going to assume you have already read the first part. Let’s get started. 

    Developing conditional statements 

    Conditional statements are very useful for creating meaningful programs, just as they would be in any other programming language. They add intelligence to  applications and make it easier to get the work done.  

    Since MS Excel user-defined functions rely on the Visual Basic language, developing conditional statements is easy. 

    Let’s make a payroll application that will compute the total salary of a certain employee based on a performance bonus. An additional $3000 bonus (to be added to the monthly salary) will be given if the performance rating is above 90 percent; otherwise, if the rating is below 90 percent, he will just received a $500 bonus.

    To make this work, we need to to express it mathematically. the following is the formula for the employee's total monthly income (salary + bonus):

    Total monthly income = Monthly basic salary + Bonus, where Bonus is equal to $3000 if performance rating is above or equal to 90%, otherwise it is only $500 if it is below 90%.

    As we did in the first part, we will declare the variables to be used in our Visual basic program.

    Let:

    totsalary = total monthly income that the employee will received based on his performance rating.

    basic = monthly basic salary of the employee.

    rating = % performance rating of the employee.

    So the Visual Basic program implementing the above variables and formulas will be:

    Function totsalary(basic, rating)

    If rating >= 0.9 Then totsalary = 3000 + basic Else totsalary = 500 + basic

    End Function

    More BrainDump Articles
    More By Codex-M


       · On the second page of this tutorial, the wrong graphic is displayed. Instead of the...
       · Yeah ok.Thanks for the feedback.Anyway the image showing the excel sheet on the...
     

    BRAINDUMP ARTICLES

    - Microsoft, NSF Open Cloud Computing to Scien...
    - Windows 7 Grabs One-Tenth of Market
    - Windows Mobile 7
    - Commands in WPF
    - Routing Events in WPF
    - Property Value Inheritance and More WPF Conc...
    - Important New Concepts in WPF
    - Introduction to Office Live Workspace
    - Using MS Excel for One-way Analysis of Varia...
    - Comparing Data Sets Using Statistical Analys...
    - Import Blogger Posts into WordPress Using Wi...
    - Download WordPress from an FTP Server and Ru...
    - Install and Run WordPress in XAMPP Local Host
    - What Windows 7 Brings to the Table
    - Virtualization and Sandbox Detection





    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek