C#: Identifier Expected

John Ellis
John Ellis used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Miguel OzSenior Software Engineer
Top Expert 2009

Commented:
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.

Author

Commented:
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.
ste5anSenior Developer

Commented:
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

Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

Author

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

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

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

But you should learn how to debug code.
Most Valuable Expert 2018
Distinguished Expert 2018

Commented:
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

Author

Commented:
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
Senior Developer
Commented:
Please look at you code again: Either line 33 is wrong or lines 46-48.

It's not about the brackets per se, it's about the dot in front of it. This is not legal in C#.

Otherwise it's not C# and you need to ask the vendor.

Author

Commented:
Thank you!!!  Removing the periods is what did it!

John

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial