GetCharValue 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 TestGetCharValue()
   Dim lCount As Integer
   Dim x As Integer
   Dim nRet As Short
   Dim nLen As Short
   Dim szChars As String
   Dim szChar As String
   Dim byteVal As Byte

   LEADDICOM1.EnableMethodErrors = False
   'move to the root element
   LEADDICOM1.MoveFirstElement(False)
   LEADDICOM1.MoveRootElement()

   'insert a new element for the Char Values
   LEADDICOM1.InsertElement(False, LTDICLib.DicomDataSetTagConstants9.TAG_PIXEL_DATA, 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 = Len(szChars)
   LEADDICOM1.CharValueCount = nLen
   For x = 0 To nLen - 1
      szChar = Mid(szChars, x + 1, 1)
      byteVal = CByte(Asc(szChar))
      LEADDICOM1.CharValues(x) = CShort(byteVal)
   Next
   'set the chars
   nRet = LEADDICOM1.SetCharValue(nLen)

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

   'get the value count
   lCount = LEADDICOM1.GetValueCount
   MessageBox.Show("There are " & CStr(lCount) & " values!")

   'get the values
   nRet = LEADDICOM1.GetCharValue(0, lCount)
   If (nRet = 0) Then
      For x = 0 To LEADDICOM1.CharValueCount - 1
         'display each value separated by a '.'
         Text1.Text = Text1.Text & "." & Chr(LEADDICOM1.CharValues(x))
      Next
   End If
   LEADDICOM1.EnableMethodErrors = True
   MessageBox.Show("wait")
End Sub