Avatar of Software Engineer
Software Engineer
 asked on

C#: Identifier Expected

Hi:

I'm getting "Identifier expected" on lines 37, 38, 39, and 45 of the code below.

I have attached a screenshot to show where these lines are at.

How do I get rid of this error?

Thanks!

John

string dt ="1/1/1900";
if (po.val_Required_Date ==po.val_PO_Date)
{
Console.WriteLine(dt.ToString());
dt = po.val_Required_Date.ToString();
}
//return"";

//PO PreSave for header fields//

if (po.val_Required_Date == Genframe4.Utils.DateTimeExtensions.MinValue)
{
	e.Cancel = true;
	return "Required Date is a required field.";
}
//return String.Empty;

//PO PreSave for line item fields//

//foreach (SalesPad.Bus.PurchaseLineItem pli in po.LineItems)
//{
//if (pli.IsChanged)
//{
//	pli.val_Required_Date = Genframe4.Utils.DateTimeExtensions.MinValue;
//	pli.val_Promised_Ship_Date = Genframe4.Utils.DateTimeExtensions.MinValue;
//	pli.val_Promised_Date = Genframe4.Utils.DateTimeExtensions.MinValue;
//}}

//return "";

foreach (SalesPad.Bus.PurchaseLineItem pli in po.LineItems)
{
if (pli ["xFinal_Site"] == "" )
{
          e.Cancel = true;
          return "Final Site is a required field.";
}
}

//return String.Empty;

foreach (SalesPad.Bus.PurchaseLineItem pli in po.LineItems)
{
if (pli.IsChanged)
{
	pli.["xRequiredDate"] = Genframe4.Utils.DateTimeExtensions.MinValue;
	pli.["xNewPromisedDate"] = Genframe4.Utils.DateTimeExtensions.MinValue;
	pli.["xPromisedDate"] = Genframe4.Utils.DateTimeExtensions.MinValue;
}}
//return "";

foreach (SalesPad.Bus.PurchaseLineItem pli in po.LineItems)
{
if (pli.["xRequiredDate"] == Genframe4.Utils.DateTimeExtensions.MinValue)
{
	e.Cancel = true;
	return "Required Date is a required field.";
}
}
return String.Empty;

/*
if (sd.IsNew &&  sd.val_Sales_Doc_ID.ToString() == "STDORD")
{
	DateTime dt = DateTime.Now;
dt = dt.AddDays(3);
Console.WriteLine(dt.ToString());	
sd.val_Req_Ship_Date =dt;	
foreach (SalesPad.Bus.SalesLineItem sli in sd.LineItems)
{
sli.val_Req_Ship_Date =dt;
}
*/

Open in new window

Identifier expected
C#

Avatar of undefined
Last Comment
Software Engineer

8/22/2022 - Mon
Miguel Oz

Is this code part of a class or static function?
I need the whole code file to provide a correct assessment:
- Try checking that all your code is in a method of a class.
- If above exists, then you add this code outside a namespace.
Software Engineer

ASKER
That is all of the code, Miguel.  It is within a script editor window used by a third-party add-on for an ERP application.
ste5an

It's pretty simple, just start with one test. Remove all other code as well as dead code. E.g. what happens when your script only consists of four lines:

if (po.val_Required_Date == Genframe4.Utils.DateTimeExtensions.MinValue)
{
      e.Cancel = true;
      return "Required Date is a required field.";
}

Open in new window

This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Software Engineer

ASKER
Everything worked fine today, until I added the code in the line numbers indicated.

That was when I got the error, upon clicking "Compile".
ste5an

Well, indexers in C# are not separated by a dot from the object identifer.

But you should learn how to debug code.
Chris Stanyon

In C#, you access Object members using the dot syntax:

instance.member

You access Array keys using the square brackets:

array["key"]

On the lines that you're getting the errors, you're mixing the 2:

pli.["xRequiredDate"]

In your code, sometimes you're treating pli as an array and sometimes you're treating it as an object. Depending on your types, choose one or the other:

pli["xRequiredDate"]

or

pli.xRequiredDate
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Software Engineer

ASKER
Hi Chris:

Thank you, for your quick response!

Unfortunately, the software package that I'm conducting this code in requires those brackets only because fields such as the Required Date are user-defined fields that I created in that package.  Those brackets don't reference an array the same way that standard C# references an array.

How does that change your response?

John
ASKER CERTIFIED SOLUTION
ste5an

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Software Engineer

ASKER
Thank you!!!  Removing the periods is what did it!

John