Reputation: 63
I have below VB6 code where in VB6 code there are two parameters being passed to read a column value from an array of collection. How to migrated this code to Vb.Net. Even I below I mentioned wizard generated VB.Net code.
Private m_colBookmarks As Collection
Private Const COL_ERR_BKMARK_COMP_TITLE = 2
Private Property Get BookmarkCompTitle(ByVal strBookmarkNum As String) As String
BookmarkCompTitle = m_colBookmarks(strBookmarkNum)(COL_ERR_BKMARK_COMP_TITLE)
End Property
here is the vb.net code.
Private ReadOnly Property BookmarkCompTitle(ByVal strBookmarkNum As String) As String
Get
BookmarkCompTitle = m_colBookmarks.Item(strBookmarkNum)(COL_ERR_BKMARK_COMP_TITLE)
End Get
End Property
Upvotes: 0
Views: 196
Reputation: 2089
Option Strict On
Imports System.Collections.ObjectModel
Public Class Class1
Private m_colBookmarks As Collection(Of String())
Private Const COL_ERR_BKMARK_COMP_TITLE = 2
' here Is the vb.net code.
Private ReadOnly Property BookmarkCompTitle(ByVal strBookmarkNum As String) As String
Get
Dim bookmarkNum As Integer
If Not Int32.TryParse(strBookmarkNum, bookmarkNum) OrElse bookmarkNum < 0 Then
Throw New ArgumentException("strBookmarkNum must be a positive integer.")
End If
BookmarkCompTitle = m_colBookmarks.Item(bookmarkNum)(COL_ERR_BKMARK_COMP_TITLE)
End Get
End Property
End Class
Upvotes: 1