Getting and setting a non-linear VOI LUT Example for VB.NET

'LEADDICOM1 is a DICOM Dataset defined outside this method
Private Sub GettingSettingNonlinearVOILUT()
   ' This example will add a new VOI LUT to the dataset or
   ' replace the existing one(s)
   Dim VOILUTAttributes As LTDICLib.LVOILUTAttributes
   Dim iRet As Short
   Dim lVOILUTCount As Integer
   Dim lLUTIndex As Integer
   Dim lNewLUTIndex As Integer
   Dim lDataSize As Integer
   Dim LUTData As Object
   Dim bAddVOILUT As Boolean

   bAddVOILUT = True
   lVOILUTCount = 0
   lNewLUTIndex = 0
   ' Get the number of VOI LUT(s) in the file
   lVOILUTCount = LEADDICOM1.VOILUTCount
   If (lVOILUTCount > 0) Then

      ' Get he attributes of the first VOI LUT
      iRet = LEADDICOM1.GetVOILUTAttributes(0, 0)
      If (iRet <> 0) Then
         MessageBox.Show("error")
         Exit Sub
      End If
      VOILUTAttributes = LEADDICOM1.VOILUTAttributes
      lDataSize = VOILUTAttributes.LUTDescriptorNumberOfEntries
      ' Get the LUT data
      ReDim LUTData(lDataSize)
      iRet = LEADDICOM1.GetVOILUTData(0, LUTData, 0)
      If (iRet <> 0) Then
         MessageBox.Show("error")
         Exit Sub
      End If
      ' Remap the data
      For lLUTIndex = 0 To (lDataSize - 1)
         LUTData(lLUTIndex) = LUTData(lLUTIndex) / 2
      Next
   Else
      VOILUTAttributes = LEADDICOM1.VOILUTAttributes
      ' Define our own
      LUT VOILUTAttributes.LUTDescriptorFirstMapped = 0
      VOILUTAttributes.LUTDescriptorEntryBits = 16
      VOILUTAttributes.LUTDescriptorNumberOfEntries = &H10000
      lDataSize = VOILUTAttributes.LUTDescriptorNumberOfEntries
      ReDim LUTData(lDataSize)
      For lLUTIndex = 0 To (lDataSize - 1)
         LUTData(lLUTIndex) = lLUTIndex
      Next
   End If
   lNewLUTIndex = lVOILUTCount
   If (bAddVOILUT = False) Then
      ' Delete existing LUT
      iRet = LEADDICOM1.DeleteVOILUT(0)
      If (iRet <> 0) Then
         MessageBox.Show("error")
         Exit Sub
      End If
      lNewLUTIndex = 0
   End If
   ' Set the new LUT
   iRet = LEADDICOM1.SetVOILUT(lNewLUTIndex, LUTData, 0)
   If (iRet <> 0) Then
      MessageBox.Show("error")
      Exit Sub
   End If
End Sub