InsertVR Example for VB.NET

'LEADDICOM1 is a DICOM Dataset defined outside this method
'This example uses the predefined variable "ListView1" of type "ListView" from ".NET Framework".
Private Sub TestInsertVR()
   Dim nRet As Short
   Dim ItemX As Windows.Forms.ListViewItem
   Dim nCode As Short
   Dim nRestrict As Short

   LEADDICOM1.EnableMethodErrors = True

On Error GoTo INSERTVRERROR

   LEADDICOM1.EnableMethodErrors = False
   nCode = 20322
   nRet = LEADDICOM1.FindVR(nCode)
   If (nRet = 0) Then
      MessageBox.Show("Already Exists!")
      Exit Sub
   End If

   nRestrict = LTDICLib.DicomVRRestrictionConstants.DICOM_VR_FIXED + LTDICLib.DicomVRRestrictionConstants.DICOM_VR_TEXT
   nRet = LEADDICOM1.InsertVR(nCode, "My Test VR", 64, nRestrict, 1)
   If (nRet <> 0) Then
      MessageBox.Show("Error")
   End If
   'add item to the ListView control
   ItemX = ListView1.Items.Add(New Windows.Forms.ListViewItem)
   ItemX.Text = CStr(LEADDICOM1.CurrentVR.Code)
   ItemX.SubItems.Add(LEADDICOM1.CurrentVR.Name)
   ItemX.SubItems.Add(CStr(LEADDICOM1.CurrentVR.Length))
   ItemX.SubItems.Add(CStr(LEADDICOM1.CurrentVR.Restrict))
   ItemX.SubItems.Add(CStr(LEADDICOM1.CurrentVR.UnitSize))

   ItemX.Selected = True
   ListView1.Refresh()
   ListView1.Focus()

   LEADDICOM1.EnableMethodErrors = True
   Exit Sub

INSERTVRERROR:
   MessageBox.Show("Error")

End Sub