GetCharValue 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 TestGetCharValue ()
{
   int lCount = 0;
   int x = 0;
   short nRet = 0;
   int nLen = 0;
   string szChars = null;
   string szChar = null;
   byte byteVal = 0;
   LEADDICOM1.EnableMethodErrors = false;
   //move to the root element
   LEADDICOM1.MoveFirstElement(false);
   LEADDICOM1.MoveRootElement();
   //insert a new element for the Char Values
   LEADDICOM1.InsertElement(false, (int)LTDICLib.DicomDataSetTagConstants9.TAG_PIXEL_DATA, (short)LTDICLib.DicomVRCodeConstants.VR_OB, false, 0);
   Text1.Visible = true;
   Text1.Text = "";
   //insert some char values into the element
   szChars = "This is a Test 1234!";
   nLen = szChars.Length;
   LEADDICOM1.CharValueCount = nLen;
   for (x = 0; x < nLen; x++)
   {
      szChar = szChars.Substring(x, 1);
      byteVal = System.Convert.ToByte(System.Convert.ToInt32(szChar[0]));
      LEADDICOM1.set_CharValues(x, System.Convert.ToInt16(byteVal));
   }
   //set the chars
   nRet = LEADDICOM1.SetCharValue(nLen);
   if (nRet != 0)
   {
      MessageBox.Show("Error");
      return;
   }
   LEADDICOM1.CharValueCount = 0;
   //free the values
   //get the value count
   lCount = LEADDICOM1.GetValueCount();
   MessageBox.Show("There are " + System.Convert.ToString(lCount) + " values!");
   //get the values
   nRet = LEADDICOM1.GetCharValue(0, lCount);
   if (nRet == 0)
   {
      for (x = 0; x < LEADDICOM1.CharValueCount; x++)
      {
         //display each value separated by a '.'
         Text1.Text = Text1.Text + "." + (char)(LEADDICOM1.get_CharValues(x));
      }
   }
   LEADDICOM1.EnableMethodErrors = true;
   MessageBox.Show("wait");
}