vb6.setitemdata

P

Pascal

hello

i would like to upgrade this code to vbnet, i tried without success:
Sub ListBoxControl(ByRef sMode As String)

Dim aryListBox() As String

Dim aryMain(,) As String

Dim aryTemp(,) As String

Dim glWordCount As Integer

' ***********************************************

' MODE OPERATION

' ---- ---------

' SAVE Save the new word

' CLEAR Clear the list box

' DELETE Remove the selected word

' SORT Sort the list from Longest to Shortest word

' ************************************************

Dim lPointer As Integer

Dim lCount As Integer


With Me.lstMots

Select Case UCase(sMode)

Case "SORT" ' by the longest word to the shortest

Dim sLastWord As String = ""

Dim bFlg As Boolean

Dim lWordCount As Integer

Dim lUpper As Integer

Dim bSortLoopFlg As Boolean

lCount = .Items.Count - 1

' *** set the item data to 0

' this will be used as a flag later

For lPointer = 0 To lCount

vb6.SetItemData(Me.lstMots, lPointer, 0)

Next

ReDim aryListBox(0)

bSortLoopFlg = False

Do Until bSortLoopFlg = True

bFlg = True

bSortLoopFlg = True

For lPointer = 0 To lCount

If bFlg = True Then

' *** get the first word that the item data is zero

If VB6.GetItemData(Me.lstMots, lPointer) <> -1 Then

bSortLoopFlg = False

' *** get the first word

sLastWord = VB6.GetItemString(Me.lstMots, lPointer)

lWordCount = lPointer

bFlg = False

End If '»If .ItemData(lPointer) <> -1 Then

Else

' *** get the next word that the item data is zero

If VB6.GetItemData(Me.lstMots, lPointer) <> -1 Then

' *** we still have words to check

bSortLoopFlg = False

' *** find the largest

If Len(Trim(sLastWord)) < Len(Trim(VB6.GetItemString(Me.lstMots, lPointer)))
Then

sLastWord = VB6.GetItemString(Me.lstMots, lPointer)

lWordCount = lPointer

End If '»If Len(sLastWord) < .List(lPointer) Then

End If '»If .ItemData(lPointer) <> -1 Then

End If '»If bFlg = True Then

Next '»For lPointer = 0 To lCount

lUpper = UBound(aryListBox, 1) + 1

ReDim Preserve aryListBox(lUpper)

aryListBox(lUpper) = sLastWord

VB6.SetItemData(Me.lstMots, lWordCount, -1)

Label1.Text = sLastWord

Loop '»Do Until bSortLoopFlg = True

Case "DELETE"

If .SelectedItems.Count = 0 Then Exit Sub

lCount = .Items.Count - 1

For lPointer = 0 To lCount

If .GetSelected(lPointer) = True Then

..Items.RemoveAt(lPointer)

Exit Sub

End If '»If .Selected(lPointer) = True Then

Next '»For lPointer = 0 To lCount

Case "SAVE"

..Items.Add(New VB6.ListBoxItem(UCase(Me.txtMotInput.Text), 0))

Me.txtMotInput.Text = ""

Me.txtMotInput.Focus()

Case "CLEAR"

..Items.Clear()

'Me.txtWord.Text = ""

Me.txtMotInput.Text = ""



Me.txtMotInput.Focus()

End Select '»Select Case UCase$(sMode)

End With '»With frmMain.lstInputWord

End Sub

End Class
 
P

Pascal

You have to add a refference to Microsoft.VisualBasic.Compatibility and
after in the code :
for example
:
For lPr = 0 To lCount

Compatibility.VB6.SetItemData(Me.listbox1, lPointer, 0) 'instead of
VB6.SetItemData(Me.listbox1, lPr, 0

Next




http://www.scalpa.info
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top