GetBinaryValue Example for VB.NET

'LEADDICOM1 is a DICOM Dataset defined outside this method
'This example uses the predefined variable "Text1" of type "TextBox" from ".NET Framework".
Private Sub TestGetBinaryValue()
   Dim lCount As Integer
   Dim x As Integer
   Dim nRet As Short
   Dim nLen As Short
   Dim byteVal As Byte
   Dim szBytes As String
   Dim szByte As String

   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 = Len(szBytes)
   LEADDICOM1.BinaryValueCount = nLen
   For x = 0 To nLen - 1
      szByte = Mid(szBytes, x + 1, 1)
      byteVal = CByte(Asc(szByte))
      LEADDICOM1.BinaryValues(x) = CShort(byteVal)
   Next
   'set the bytes
   nRet = LEADDICOM1.SetBinaryValue(nLen)

   If (nRet <> 0) Then
      MessageBox.Show("Error")
      Exit Sub
   End If
   LEADDICOM1.BinaryValueCount = 0 'free the values

   'get the byte count
   lCount = LEADDICOM1.CurrentElement.Length
   MessageBox.Show("There are " & CStr(lCount) & " bytes!")

   'get the bytes
   nRet = LEADDICOM1.GetBinaryValue(lCount)
   If (nRet = 0) Then
      For x = 0 To LEADDICOM1.BinaryValueCount - 1
         'display each byte as a char separated by a space
         Text1.Text = Text1.Text & " " & Chr(LEADDICOM1.BinaryValues(x))
      Next
   End If
   LEADDICOM1.EnableMethodErrors = True
   MessageBox.Show("wait")

End Sub