Link to home
Start Free TrialLog in
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

User generated image
Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

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.
Avatar of Software Engineer
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.
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

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

That was when I got the error, upon clicking "Compile".
Well, indexers in C# are not separated by a dot from the object identifer.

But you should learn how to debug code.
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
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
Avatar of ste5an
ste5an
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you!!!  Removing the periods is what did it!

John