GetAgeValue Example for C#

//This example uses the predefined variable “Text1” of type “TextBox” from “.NET Framework”.
//LEADDICOM1 is a DICOM Dataset defined outside this method
private void TestGetAgeValue()
{
   int lCount = 0;
   short nRet = 0;
   LEADDICOM1.EnableMethodErrors = false;
   //move to the root element
   LEADDICOM1.MoveFirstElement(false);
   LEADDICOM1.MoveRootElement();
   //insert a new element for the Age Value
   LEADDICOM1.InsertElement(false, (int)LTDICLib.DicomDataSetTagConstants2.TAG_PATIENT_AGE, (short)LTDICLib.DicomVRCodeConstants.VR_AS, false, 0);
   //insert an Age value into the element
   LEADDICOM1.AgeValueCount = 1;
   LEADDICOM1.get_AgeValues(0).Number = 21;
   LEADDICOM1.get_AgeValues(0).Reference = System.Convert.ToInt16(System.Convert.ToInt32('Y'));
   //set the age
   nRet = LEADDICOM1.SetAgeValue(1);
   if (nRet != 0)
   {
      MessageBox.Show("Error");
      return;
   }
   LEADDICOM1.AgeValueCount = 0; //free the value
   //get the value count
   lCount = LEADDICOM1.GetValueCount();
   MessageBox.Show("There are " + System.Convert.ToString(lCount) + " values!");
   //get the value
   nRet = LEADDICOM1.GetAgeValue(0, lCount);
   //display the value
   Text1.Text = "Number: " + System.Convert.ToString(LEADDICOM1.get_AgeValues(0).Number) + "Ref: " + (char)(LEADDICOM1.get_AgeValues(0).Reference);
   LEADDICOM1.EnableMethodErrors = true;
   MessageBox.Show("wait");
}