none
Help with C# Syntax RRS feed

  • Question

  • I haven't written C# for a while.  I am getting the following error and all the "=" are turning red in the Visual Studio editor in all the code that's BOLD.  This is sample code from HL7 message writer.  I think this is older C# syntax that needs to be updated.  It's using .NET 2.0 framework.  Thanks

    Error:  Invalid token '=' in class, struct, or interface member declaration

                PipeParser parser = new PipeParser();

                NHapi.Model.V231.Message.QRY_R02 qry = new

                NHapi.Model.V231.Message.QRY_R02();

                qry.MSH.MessageType.MessageType.Value ="QRY";

                qry.MSH.MessageType.TriggerEvent.Value = "R02";

                qry.MSH.MessageType.MessageStructure.Value = "QRY_R02";

                qry.MSH.FieldSeparator.Value = "|";

                qry.MSH.SendingApplication.NamespaceID.Value="CohieCentral";

                qry.MSH.SendingFacility.NamespaceID.Value = "COHIE";

                qry.MSH.ReceivingApplication.NamespaceID.Value="Clinical Data Provider";

                qry.MSH.ReceivingFacility.NamespaceID.Value=facility;

                qry.MSH.EncodingCharacters.Value = @"^~\&";

                qry.MSH.VersionID.VersionID.Value = "2.3.1";

                qry.MSH.DateTimeOfMessage.TimeOfAnEvent.SetLongDate(DateTime.Now);

                qry.MSH.MessageControlID.Value = messageControlId;

                qry.MSH.ProcessingID.ProcessingID.Value="P";

                XCN st = qry.QRD.getWhoSubjectFilter(0);

                st.AssigningAuthority.UniversalID.Value = facility;

                st.IDNumber.Value = mrn;qry.QRD.QueryDateTime.TimeOfAnEvent.SetLongDate(DateTime.Now);

                qry.QRD.QueryFormatCode.Value = "R";

                qry.QRD.QueryPriority.Value = "I";

                CE what = qry.QRD.getWhatSubjectFilter(0);

                what.Identifier.Value = "RES";

                return parser.encode(qry);

     

    Monday, November 13, 2017 12:25 AM

All replies

  • Those are the sorts of errors I would expect if the code is in a class but not in a method. I notice you end with a "return" statement, so it looks like you intend it to be in a method. You should check all the opening and closing braces to make sure that code has not ended up outside a method by accident.
    Monday, November 13, 2017 2:03 AM
  • Even before I looked at the code, based on the description, I suspected it was something such as what Ante Meridian said.

    Something that can help check the braces is to put the cursor on a brace and click Ctrl-]. That will take you to the matching brace or whatever. It works on multiple types of braces; both curly braces and parentheses. I think it even works on the comment operators /* and */.



    Sam Hobbs
    SimpleSamples.Info

    Monday, November 13, 2017 4:35 AM
  • Isn't this the issue:

    NHapi.Model.V231.Message.QRY_R02 qry = new

    That doesn't look like the correct way to substantiate a class, right?

    And what's the next line doing?

    NHapi.Model.V231.Message.QRY_R02();

    Thank you!


    • Edited by BlairRV Tuesday, November 14, 2017 11:17 PM formatting again
    Tuesday, November 14, 2017 11:15 PM
  • Normally the instantiation would be written on one line.

                 NHapi.Model.V231.Message.QRY_R02 qry = new NHapi.Model.V231.Message.QRY_R02();

    But split over two lines, it should still work. The compiler will just treat the second line as a continuation of the first, until it hits a semi-colon.

    Have you checked the braces, as we suggested?

    Wednesday, November 15, 2017 12:14 AM
  • Hi BlairRV,

    >>That doesn't look like the correct way to substantiate a class, right?

    Do you resolve the issue? if yes, please mark helpful reply as answer, it will be beneficial other communities who have the similar issue, if not, could you please share a simple demo, which could reproduce the issue, we'll try our best to find a solution to resolve it.

    Best regards,

    Zhanglong Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, November 20, 2017 6:46 AM
    Moderator
  • I tried the code above with the latest nHAPI package (2.5.0.6). It is compiling and working just fine.

    Maybe the error was in another part of your code.

    Here is my complete listing.

    using NHapi.Base.Model;
    using NHapi.Base.Parser;
    using NHapi.Model.V231.Datatype;
    using NHapi.Model.V231.Message;
    using NHapi.Model.V231.Segment;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;

    namespace GenerateurHL7
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }

            private void button1_Click(object sender, EventArgs e)
            {
                string result;
                textBox1.Text = test();
            }


            string test()
            {
                string facility = "";
                string messageControlId = "";
                string mrn = "";
                PipeParser parser = new PipeParser();
                NHapi.Model.V231.Message.QRY_R02 qry = new
                NHapi.Model.V231.Message.QRY_R02();
                qry.MSH.MessageType.MessageType.Value = "QRY";
                qry.MSH.MessageType.TriggerEvent.Value = "R02";
                qry.MSH.MessageType.MessageStructure.Value = "QRY_R02";
                qry.MSH.FieldSeparator.Value = "|";
                qry.MSH.SendingApplication.NamespaceID.Value = "CohieCentral";
                qry.MSH.SendingFacility.NamespaceID.Value = "COHIE";
                qry.MSH.ReceivingApplication.NamespaceID.Value = "Clinical Data Provider";
                qry.MSH.ReceivingFacility.NamespaceID.Value = facility;
                qry.MSH.EncodingCharacters.Value = @"^~\&";
                qry.MSH.VersionID.VersionID.Value = "2.3.1";
                qry.MSH.DateTimeOfMessage.TimeOfAnEvent.SetLongDate(DateTime.Now);
                qry.MSH.MessageControlID.Value = messageControlId;
                qry.MSH.ProcessingID.ProcessingID.Value = "P";
                XCN st = qry.QRD.GetWhoSubjectFilter(0); // G
                st.AssigningAuthority.UniversalID.Value = facility;
                st.IDNumber.Value = mrn;
                qry.QRD.QueryDateTime.TimeOfAnEvent.SetLongDate(DateTime.Now);
                qry.QRD.QueryFormatCode.Value = "R";
                qry.QRD.QueryPriority.Value = "I";
                CE what = qry.QRD.GetWhatSubjectFilter(0);
                what.Identifier.Value = "RES";
                return parser.Encode(qry);
            }
        }
    }


    Friday, October 23, 2020 1:20 AM