|
I am coding a interest calculator in C# using Visual Studio 2005 Express edition and I keep on getting the following error: "CalcBalance does not exist in the current context". I am not sure what's cuasing it or how to fix it. Any advice which would help in get this code working would be greatly appreciated. Below is the full code:
<%@ Control Language="C#" ClassName="WebUserControl" %>
protected void Button1_Click(object sender, EventArgs e)
{
Label6.Text = "Final Balance: $" +
CalcBalance(Convert.ToInt32(TextBox1.Text),
(Convert.ToInt32(TextBox2.Text) / 100),
Convert.ToInt32(TextBox3.Text),
Convert.ToInt16(DropDownList1.SelectedItem.Value)).ToString();
}
private string CalculateBalance(int Principal, double Rate, int Years, int Period)
{
double result;
double NumToBeRaised = (1 + Rate / Period);
result = Principal * System.Math.Pow(NumToBeRaised, (Years * Period));
return (result.ToString("C"));
}
<asp:label id="Label1" runat="server" style="position: relative" text="Compound interest Calculator" width="318px" font-bold="True" font-size="Large">
<asp:label id="Label2" runat="server" style="position: relative" text="Principal ($)" width="165px">
<asp:textbox id="TextBox1" runat="server" style="position: relative">
<asp:label id="Label3" runat="server" style="position: relative" text="Rate (%)" width="165px">
<asp:textbox id="TextBox2" runat="server" style="position: relative">
<asp:label id="Label4" runat="server" style="position: relative" text="Years:" width="165px">
<asp:textbox id="TextBox3" runat="server" style="position: relative">
<asp:label id="Label5" runat="server" style="position: relative" text="Compound Frequency:" width="165px">
<asp:dropdownlist id="DropDownList1" runat="server" style="position: relative">
<asp:listitem value="1">Annually
<asp:listitem value="4">Quarterly
<asp:listitem value="12">Monthly
<asp:listitem value="365">Daily
<asp:listitem>
<asp:button id="Button1" runat="server" style="left: 9px; position: relative; top: 10px"
="" text="Calculate" width="207px" onclick="Button1_Click">
<asp:label id="Label6" runat="server" style="position: relative" width="165px">
Greg
The Belizean Dan Dada!!!
|
|
|
|
|
Are you kidding?
You are calling a function named CalcBalance but you have defined one with the name CalculateBalance . Do you see the difference?
|
|
|
|
|
protected void Button1_Click(object sender, EventArgs e)
{
Label6.Text = "Final Balance: $" +
CalcBalance(Convert.ToInt32(TextBox1.Text),
^^^^^^^^^^^ -- LOOK AT WHAT YOU TYPED HERE :~
(Convert.ToInt32(TextBox2.Text) / 100),
Convert.ToInt32(TextBox3.Text),
Convert.ToInt16(DropDownList1.SelectedItem.Value)).ToString();
}
private string CalculateBalance(int Principal, double Rate, int Years, int Period)
^^^^^ - NOW LOOK AT WHAT YOU TYPED HERE :omg:
{
double result;
double NumToBeRaised = (1 + Rate / Period);
result = Principal * System.Math.Pow(NumToBeRaised, (Years * Period));
return (result.ToString("C"));
}
|
|
|
|
|
By looking at your code, it seems as CalculateBalance(...) is the function that actually calculates the interest but you are using CalcBalance instead of CalculateBalance(...) as the name of the function.
If the name of the interest calculating function is actually CalcBalance, then this error might be because CalcBalance is not in the current class.
Regards,
Wasif Ehsan
|
|
|
|
|
wasife wrote: If the name of the interest calculating function is actually CalcBalance, then this error might be because CalcBalance is not in the current class.
"this error might be..." You are too kind, Wasif
:josh:
My WPF Blog[^]
|
|
|
|
|
Thanks, Guys I really apprecaite the tip. I changed the name and it worked. This code was written directly from a microsoft book, as is, so i took it for granted that i was doin something wrong................what a dork. Thanks again. I knew I can rely on you guys for assistance.
Greg
The Belizean Dan Dada!!!
|
|
|
|
|
Which just goes to proove:
1) Technical writers/editors make mistakes too
2) Dont believe everything you read without verifying it
Current blacklist
svmilky - Extremely rude | FeRtoll - Rude personal emails | ironstrike1 - Rude & Obnoxious behaviour
|
|
|
|
|
Hi, i'm trying to show the "video capture filter" or "video source" form to configure the webcam parameters.
How can i do that??
Very thanks. Sorry, I'm Spanish.
www.studios-tortuga.com
|
|
|
|
|
You probably should begin by reading Chris' article on how to get answers to your questions. It is really unclear as to what you are asking here! If you believe there is some kind of dialog in .NET to display this video source form, you are very wrong. You will have to write this yourself. If it is a feature within a webcam piece of hardware, then you need to look into the webcam SDK and determine how to interact with this in your program. Contacting the webcam manufacturer will help along these lines.
|
|
|
|
|
It's ok to be Spanish. Don't apologise. Now, if you were Welsh....that's a different question.
Regards
Angel
*********************************************
The sooner you fall behind, the longer you have to catch up.
|
|
|
|
|
I’m having troubles with the following code:
txtSelect.Text = “Select System_id From [DFIParmsHTS].[docsadm].[ExtGroup] where CustNumber = _CustomerNumber”
OdbcCommand cmdSelect= new OdbcCommand(txtSelect.Text, conn);
cmdSelect.CommandType=CommandType.Text;
cmdSelect.Parameters.Add("_CustomerNumber", vfx.TNM);
dr = cmdSelect.ExecuteReader();
Throws SQLSRV32.DLL - ERROR [42S22] [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid column name '_CustomerNumber'
No kidding _CustomerNumber is an Invalid Column name. I’m trying to replace it with vfx.TNM. If I look at the Command object in the watch window Parameters.items[0].parametername = “_CustomerNumber” and Parameters.items[0].Value = “000122”
So why isn’t it getting to the db that way.
I’ve also tried
txtSelect.Text = “Select System_id From [DFIParmsHTS].[docsadm].[ExtGroup] where CustNumber = @CustomerNumber”
OdbcCommand cmdSelect= new OdbcCommand(txtSelect.Text, conn);
cmdSelect.CommandType=CommandType.Text;
cmdSelect.Parameters.Add("@CustomerNumber", vfx.TNM);
dr = cmdSelect.ExecuteReader();
Throws SQLSRV32.DLL - ERROR [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Must declare the variable '@CustomerNumber'
So to me it looks like the Command isn’t committing the changes of the parameters to the query. That made me try:
txtSelect.Text = “Select System_id From [DFIParmsHTS].[docsadm].[ExtGroup] where CustNumber = @CustomerNumber”
OdbcCommand cmdSelect= new OdbcCommand(txtSelect.Text, conn);
cmdSelect.CommandType=CommandType.Text;
cmdSelect.Parameters.Add("@CustomerNumber", vfx.TNM);
cmdSelect.Prepare();
dr = cmdSelect.ExecuteReader();
And that didn’t work either.
Any help is appreciated, Thanks.
Ronald Hahn, CNT - Computer Engineering Technologist
New Technologies Analyst
HahnTech Affiliated With Code Constructors
Edmonton, Alberta, Canada
Email: rhahn82@telus.net
|
|
|
|
|
First question would be why are you using OdbcCommand rather than SqlCommand? It appears you are connecting to a Sql Server database.
|
|
|
|
|
Well some sites use MS SQL others use Postgrsql. When you write code that is flexible and not just MS you can't always take the easy way.
Ronald Hahn, CNT - Computer Engineering Technologist
New Technologies Analyst
HahnTech Affiliated With Code Constructors
Edmonton, Alberta, Canada
Email: rhahn82@telus.net
|
|
|
|
|
True enough. You didn't mention anything about the databases you were using. From the evidence you provided it seemed only SQL Server.
You might want to look at the Microsoft Enterprise Library and the Data Application block to assist in writing a more generic data access layer.
|
|
|
|
|
Thanks for the link. I need all the help i can get with this two DBS thing.
Ronald Hahn, CNT - Computer Engineering Technologist
New Technologies Analyst
HahnTech Affiliated With Code Constructors
Edmonton, Alberta, Canada
Email: rhahn82@telus.net
|
|
|
|
|
|
Parameters in ODBC don't have names. Use "?" in the query to identify the parameters, and add the parameters to the parameter collection in the same order as they appear in the query.
---
b { font-weight: normal; }
|
|
|
|
|
Cool Thanks for the help. I Guess I'm going to just to Replace() on the input string then. The attraction of using parameters was that it allowed a bit of latitude in how the sql strings where made.
Ronald Hahn, CNT - Computer Engineering Technologist
New Technologies Analyst
HahnTech Affiliated With Code Constructors
Edmonton, Alberta, Canada
Email: rhahn82@telus.net
|
|
|
|
|
HahnTech wrote: I Guess I'm going to just to Replace() on the input string then.
Why? Just use '?'
Select System_id From [DFIParmsHTS].[docsadm].[ExtGroup] where CustNumber = ?
then
cmdSelect.Parameters.Add("", vfx.TNM);
"Just about every question you've asked over the last 3-4 days has been "urgent". Perhaps a little planning would be helpful?" Colin Angus Mackay in the C# forum
led mike
|
|
|
|
|
Yeah that would work Great if I was always only going to use one where clause or if this was the only sql statement in the program. But tomorrow or a week from now, myself or some one else will have to edit the sql to return a smaller range and forget that its ordinal specific then spend 2h trying to figure out why its not working. Replace() is ordinal unspecific and works all the time. I envy all you programmers that get to use a static DB schema.
Ronald Hahn, CNT - Computer Engineering Technologist
New Technologies Analyst
HahnTech Affiliated With Code Constructors
Edmonton, Alberta, Canada
Email: rhahn82@telus.net
|
|
|
|
|
Stored Procedures
"Just about every question you've asked over the last 3-4 days has been "urgent". Perhaps a little planning would be helpful?" Colin Angus Mackay in the C# forum
led mike
|
|
|
|
|
Too many sites to manage and a moving Db schema make them too hard to manage.
Ronald Hahn, CNT - Computer Engineering Technologist
New Technologies Analyst
HahnTech Affiliated With Code Constructors
Edmonton, Alberta, Canada
Email: rhahn82@telus.net
|
|
|
|
|
If you are not going to use parameters, be sure to encode the values properly when you put the query together, or your application will be wide open for SQL injections.
---
b { font-weight: normal; }
|
|
|
|
|
I am using SendMessage from the Win32 API to send keystrokes to the foreground window. The keystrokes do not arrive, though, somehow. I have checked, and the handle to the window that I get is correct. When I use SendMessage to send a character to the application itself it works, but not to another window.
I use the following API functions:
<br />
[DllImport("user32.dll")]<br />
public static extern int SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);<br />
<br />
[DllImport("user32.dll")]<br />
public static extern IntPtr GetForegroundWindow();<br />
And the following to send the message:
<br />
char a = new char();<br />
a = 'A';<br />
this.WindowState = FormWindowState.Minimized;<br />
IntPtr handle = GetForegroundWindow();<br />
SendMessage(handle, (int)Win32API.Messages.Char, (IntPtr)a, (IntPtr)0);<br />
The char enum is set to 0x0102, which is equivalent to WM_CHAR.
Does anyone know what I'm doing wrong? I would appreciate some help!
Thanks!
|
|
|
|
|
Is the window within your application space? Security will prevent you from sending keystrokes to a window that is not within your application space unless you have a remoting solution that specifically marshals the request between each boundary.
|
|
|
|