473,395 Members | 1,502 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Here is some Sample Code for Classes and Methods

Here below I wrote a program to take a subtotal of your
purchased amount and calulate the tax based on Tennesse
sales tax rate of 9.25%. This is just a basic ASP.NET C#
program which could be wired up as a windows form app as
well. I thought I share this with some of you that are
learning C#, ASP.NET, and the .NET Framework!

using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace MikesASPNET

{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class MainPage : System.Web.UI.Page
{
protected
System.Web.UI.WebControls.TextBox PAmount;
protected System.Web.UI.WebControls.Label
Label1;
protected
System.Web.UI.WebControls.Button btnSbm;
protected System.Web.UI.WebControls.Label
lblTxtT;
protected System.Web.UI.WebControls.Label
lblTitle;
protected System.Web.UI.WebControls.Label
ResultOut;

private void Page_Load(object sender,
System.EventArgs e)
{

}

#region Web Form Designer generated code
override protected void OnInit(EventArgs
e)
{
//
// CODEGEN: This call is required
by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support -
do not modify
/// the contents of this method with the
code editor.
/// </summary>
private void InitializeComponent()
{
this.btnSbm.Click += new
System.EventHandler(this.btnSbm_Click);
this.Load += new
System.EventHandler(this.Page_Load);

}
#endregion
/// <summary>
/// This is were we wire up our code for the page to
actully do somthing!
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnSbm_Click(object sender,
System.EventArgs e)
{
// We need to Create a New
Instance of Our Class Computation
// This will load the Computation
Class into memory for use
// As I under stand this when the
Class emeber within a event
// is called it is automaticly
destroyed in memory when not in use

Computation MyComputation = new
Computation();
// This was difficult to
understand these next two lines of code
// We need to get the Value from
the PAmount Textbox Property Text
// and Parse it to a floating
number this is important as the default
// value for textbox.text
property is of a string value
// Then we need to assign a the
retuned!!! Value from out Class
// Computation Method computeTax
to a varible. This was done by my design
// this way if I need to do more with it in this
context I can! There
// are other ways to do this I am
sure

float Amount;
Amount = float.Parse
(PAmount.Text);

// Are you bored and confused by
now? Well this is something I
// did by complete accident,
Notice our type for Amount is a float
// which is needed to pass this
to the Computation Class Method computeTax
// or we wil get a build error!
Remember whatever the Methods entry
// variable is declared to be,
must be the same when used to
// call the method! What I did
here I think is cool! By assigning the
// the Call to our method in a
variable, I converted the returned vaule
// from our method to double
stored in AmountT.
double AmountT = Math.Round
(MyComputation.computeTax(Amount),2);

// Now we take our varibles that
we worked with and convert them
// back to a string then and
assign them to the ResultOut.Text Lable's
// Property (Remember we need to
convert it back to a string to be
// useful!

ResultOut.Text = AmountT.ToString
();
PAmount.Text = "";
}
}
public class Computation
{

// This is the computeTax Method Retuns
AmountT as a float when called
public float computeTax(float Amount)
{

float LTax = 0.0925F, TaxT = 0,
AmountT =0;
TaxT = Amount *LTax;
AmountT = Amount + TaxT;
return AmountT;
}

}
}

Nov 15 '05 #1
0 956

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

36
by: Antoon Pardon | last post by:
I'm rather new at this, so I don't know how I should introduce this, nor whether these ideas are worth much but here goes. What I would like to change is access to variables on an intermediate...
1
by: Torsten Mohr | last post by:
Hi, i have written a DLL that implements some C++ classes and their methods. Now i would like to make the classes and their methods known to python. Is there some example code available on...
11
by: Christopher Benson-Manica | last post by:
#include <vector> class Bar; class Foo { friend class Bar; /* 1 */ protected: int myint;
6
by: V. Jenks | last post by:
I apologize if this is the wrong forum for this, I could not locate one that was exactly appropriate for this topic. Over the last couple of years I've been doing a lot of reading on design...
1
by: Mitan | last post by:
Hello, I'm a beginner with what appears to be a simple question for which I haven't been able to get an answer. Can someone explain what "implementation code" is in relation to VB.NET? I want to be...
39
by: Digital Puer | last post by:
I'm not the world's greatest C++ programmer, so I had a hard time with these. Some help would be appreciated. 1. Comment on the declaration of function Bar() below: class Foo { static int...
69
by: raylopez99 | last post by:
They usually don't teach you in most textbooks I've seen that delegates can be used to call class methods from classes that are 'unaware' of the delegate, so long as the class has the same...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.