|
-
Dec 3rd, 2012, 03:37 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] The name does not exist in the current context
When I hover over the YTD1Month part of the line of code after it executes I do not see what the value is. I added a watch to the variable and it is telling me:
The name 'YTD1Month' does not exist in the current context
Can anyone explain this to me?
Code:
String YTD1Month = MonthDate(DateRangeEnd, -1);
Here is MonthDate:
Code:
public string MonthDate(String EndingDate, int MonthsToSubtract)
{
DateTime dt = new DateTime();
if (DateTime.TryParse(EndingDate, out dt))
{
dt = dt.AddMonths(MonthsToSubtract);
return dt.ToShortDateString();
}
else
{
return "";
}
}
-
Dec 3rd, 2012, 03:51 PM
#2
Re: The name does not exist in the current context
You haven't posted anything relevant to help you solve the issue. You say the error is that YTD1Month does not exist in the current context, but you're not showing where it is being referenced or where the error is occuring.
-
Dec 3rd, 2012, 04:12 PM
#3
Thread Starter
Fanatic Member
Re: The name does not exist in the current context
Code:
public bool ProcessPMTDRecords(BackgroundWorker bw)
{
//process pmtdhdr/det records into an array
bw.ReportProgress(0, "Processing");
//get the companies to process from the app.config file
DataAccess da = new DataAccess();
List<string> lstComp = da.GetCompileCompanies();
List<YPUR> ypur = new List<YPUR>();
//loop thru lstComp and process the pmtd into the YPUR
if (lstComp != null)
{
foreach (String strComp in lstComp)
{
//get the GL Date Start- retrieve all data from GL Date Start and process month by month by RecDate
String MonthGLStarts = da.GLMonthStart();
//end date is the last day of the month from CTLF130
String DateRangeEnd = FindEndDate(strComp);
//start date is the year prior starting in the month found
String DateRangeStart = FindStartDate(MonthGLStarts, DateRangeEnd, strComp);
//Use these dates to compile data for the buckets.
String PTDMonth = DateRangeEnd;
String YTD1Month = MonthDate(DateRangeEnd, -1);//after these execute it tells me does not exist in current context
String YTD2Month = MonthDate(DateRangeEnd, -2);
String YTD3Month = MonthDate(DateRangeEnd, -3);
String YTD4Month = MonthDate(DateRangeEnd, -4);
String YTD5Month = MonthDate(DateRangeEnd, -5);
String YTD6Month = MonthDate(DateRangeEnd, -6);
String YTD7Month = MonthDate(DateRangeEnd, -7);
String YTD8Month = MonthDate(DateRangeEnd, -8);
String YTD9Month = MonthDate(DateRangeEnd, -9);
String YTD10Month = MonthDate(DateRangeEnd, -10);
String YTD11Month = MonthDate(DateRangeEnd, -11);
String YTD12Month = MonthDate(DateRangeEnd, -12);
//get pmtdhdr data into dataadapter/table?
//order desc by date
String strSQL = PMTDSql(DateRangeStart, DateRangeEnd, strComp);
if (strSQL != "")
{
bw.ReportProgress(10, "Loading DataTable");
DataTable dt = new DataTable();
dt = da.LoadPMTD(strSQL);
if (dt.Rows.Count > 1)
{
//loop thru and assemble the YPUR
String APMFCustNo = "";
String SaveAPMFCustNo = "";
String RecDate = "";
YPUR y = new YPUR();
foreach (DataRow dr in dt.Rows)
{
//String RecDate = dr["RecDate"].ToString();
APMFCustNo = dr["APMF_CustomerNo"].ToString();
if (APMFCustNo != SaveAPMFCustNo)
{
//this means it is the next customer. Add to database then reset the data
y.CustNo = APMFCustNo;
y.ProductID = "";
y.Dollars = 0;
y.YTDDols = 0;
y.YTDlbs = 0;
y.PTDDols = 0;
y.PTDlbs = 0;
y.GLNO = "";
y.LastDte = "";
y.LastLbs = 0;
y.LastPrice = 0;
y.LYDols = 0;
y.LYLbs = 0;
y.M1Dols = 0;
y.M1Lbs = 0;
y.M2Dols = 0;
y.M2Lbs = 0;
y.M3Dols = 0;
y.M3Lbs = 0;
y.M4Dols = 0;
y.M4Lbs = 0;
y.M5Dols = 0;
y.M5Lbs = 0;
y.M6Dols = 0;
y.M6Lbs = 0;
y.M7Dols = 0;
y.M7Lbs = 0;
y.M8Dols = 0;
y.M8Lbs = 0;
y.M9Dols = 0;
y.M9Lbs = 0;
y.M10Dols = 0;
y.M10Lbs = 0;
y.M11Dols = 0;
y.M11Lbs = 0;
y.M12Dols = 0;
y.M12Lbs = 0;
ypur.Add(y);
}
SaveAPMFCustNo = APMFCustNo;
RecDate = dr["RecDate"].ToString();
}
}
bw.ReportProgress(50, "Records Finished");
}
}
}
return true;
}
-
Dec 3rd, 2012, 06:45 PM
#4
Re: The name does not exist in the current context
Do you understand the scope of variables concept well? This is probably where your issue lies... Although here, I don't see anything that would really help in determining where you see that error.
I don't get what you mean by this though:
Code:
//after these execute it tells me does not exist in current context
Where does it say they don't exist? Have you tried breakpoint stepping? Where is the error shown in the IDE specifically? You still haven't provided enough information for anybody to help yet. All I see is the declaration for YTD1Month, but nowhere after that where you try to use the string value.
As I see it though, your MonthDate function really isn't relevant to the problem you are having.
Last edited by AceInfinity; Dec 3rd, 2012 at 06:49 PM.
<<<------------
.NET Programming (2012 - 2018)
®Crestron - DMC-T Certified Programmer | Software Developer <<<------------
-
Dec 3rd, 2012, 09:24 PM
#5
Thread Starter
Fanatic Member
Re: The name does not exist in the current context
It says they don't exist when I hover over the variable as I am stepping through the code. Also when I try to print it in the Immediate window. I provided the MonthDate function so that it could be seen what I am trying to do with it. So as each of the MonthDate calls are made I hover over the variable YTD1Month, YTD2Month, etc.. the Immediate Windows says it does not exist in the current context. Now as far as variable scope, I do understand. That is why I don't know why I am not getting a value on those lines.
I appreciate the help in any way. What else should I post in order to get that help?
Last edited by mojo69; Dec 3rd, 2012 at 09:33 PM.
-
Dec 4th, 2012, 07:29 AM
#6
Hyperactive Member
Re: The name does not exist in the current context
The name 'YTD1Month' does not exist in the current context
At least this error message should not come if that is the actual code you are using, as the variable is defined just in scope.. Can you post the complete error message (with inner exception details) to further dig ??
-
Dec 4th, 2012, 08:26 AM
#7
Thread Starter
Fanatic Member
Re: The name does not exist in the current context
The message I posted to start off is the message.
I added this for a test and it shows me the value when I hover now. Does the message show up because I have not 'used' the variable yet? Is this an IDE issue?
Code:
String YTD1Month = MonthDate(DateRangeEnd, -1);
if (YTD1Month != "")
{
YTD1Month = "2012/11/01";
}
-
Dec 5th, 2012, 08:09 AM
#8
Thread Starter
Fanatic Member
Re: The name does not exist in the current context
Going to blame this on the IDE unless I hear different.
-
Dec 5th, 2012, 07:55 PM
#9
Re: [RESOLVED] The name does not exist in the current context
I would say that you should rebuild/clean your project. It probably just needs a refresher. There might have been nothing wrong with your code.
<<<------------
.NET Programming (2012 - 2018)
®Crestron - DMC-T Certified Programmer | Software Developer <<<------------
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|