GetBinaryValue 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 TestGetBinaryValue()
{
   int lCount = 0;
   int x = 0;
   short nRet = 0;
   int nLen = 0;
   byte byteVal = 0;
   string szBytes = null;
   string szByte = null;
   LEADDICOM1.EnableMethodErrors = false;
   //move to the root element
   LEADDICOM1.MoveFirstElement(false);
   LEADDICOM1.MoveRootElement();
   Text1.Visible = true;
   Text1.Text = "";
   //insert some bytes into the element
   szBytes = "This is a Test 1234!";
   nLen = szBytes.Length;
   LEADDICOM1.BinaryValueCount = nLen;
   for (x = 0; x < nLen; x++)
   {
      szByte = szBytes.Substring(x, 1);
      byteVal = System.Convert.ToByte(System.Convert.ToInt32(szByte[0]));
      LEADDICOM1.set_BinaryValues(x, System.Convert.ToInt16(byteVal)) ;
   }
   //set the bytes
   nRet = LEADDICOM1.SetBinaryValue(nLen);
   if (nRet != 0)
   {
      MessageBox.Show("Error");
      return;
   }
   LEADDICOM1.BinaryValueCount = 0;
   //free the values
   //get the byte count
   lCount = LEADDICOM1.get_CurrentElement().Length;
   MessageBox.Show("There are " + System.Convert.ToString(lCount) + " bytes!");
   //get the bytes
   nRet = LEADDICOM1.GetBinaryValue(lCount);
   if (nRet == 0)
   {
      for (x = 0; x < LEADDICOM1.BinaryValueCount; x++)
      {
         //display each byte as a char separated by a space
         Text1.Text = Text1.Text + " " + (char)(LEADDICOM1.get_BinaryValues(x));
      }
   }
   LEADDICOM1.EnableMethodErrors = true;
   MessageBox.Show("wait");
}