Use A Class To Convert Code

Use A Class To Convert Code

In VB3 if you wanted to convert your code from one custom control toanother, there were no options other than changing your code. By writingthe proper class you can make use of your current syntax with a differentcontrol. This code demonstrates how to write a VB class to change standardlist-box syntax to use a ListView control. MyList.AddItem and .RemoveItemmethods and the .Text property will interface to the ListView Control usingthis class:

 'Form1 would have a listView control on it'dim a module wide object variableDim MyList As ObjectPrivate Sub Form_Load()	'create an instance of our class	Set MyList = New FakeList	'tell the class what control to use	Set MyList.ListItem = ListView1End Sub'The Class code follows'This holds the listview control'that we will interface withPublic ListItem As ListViewPublic Sub AddItem(sString As String)	'convert AddItem to Add	ListItem.ListItems.Add , , sStringEnd SubPublic Sub RemoveItem(lItem As Long)	'Convert RemoveItem to Remove	ListItem.ListItems.Remove lItemEnd SubPublic Property Get Text() As String	'Get the text from the selected item	Text = ListItem.SelectedItem.TextEnd PropertyPublic Property Let Text(sString As String)	'set the text in the selected item	ListItem.SelectedItem.Text = sStringEnd Property
See also  5 Tips to Manage a Remote Workforce

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist