I have attempted to modify this code to work from VB6 which it does, to VB.Net but VB.Net doesnt like the .NewIndex and I have already checked the MSDN and attemped to change it to what they recommended and still doesnt work.
The msdn said to use SelectedIndex but when i run it i get:
An unhandled exception of type 'System.Exception' occurred in microsoft.visualbasic.dll
Additional information: Invalid property array index
After the upgrade these are the upgrade error's I got: I provided as much info as i could so i hope it helps you guys out.
1) 'UPGRADE_ISSUE: ListBox property List1.NewIndex was not upgraded. Click for more: 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="vbup2059"'
And in the module
1) 'UPGRADE_WARNING: Get was upgraded to FileGet and has a new behavior. Click for more: 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="vbup1041"'
2) 'UPGRADE_WARNING: Dir has a new behavior. Click for more: 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="vbup1041"'
3) 'UPGRADE_WARNING: Put was upgraded to FilePut and has a new behavior. Click for more: 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="vbup1041"'
Any help greatly appriciated!
VB Code:
Private Sub Command1_Click() Dim lNewRec As Long 'Store the info and return the record number lNewRec = StoreURL(urld.Text, urll.Text) MsgBox "Record Number " & lNewRec & " was added to the file" 'add display name to the list List1.AddItem urld.Text 'store the record number in the itemdata property so we can retrieve it later 'see List1_DoubleClick List1.ItemData(List1.NewIndex) = lNewRec End Sub Private Sub Command2_Click() Dim lCounter As Long Dim sName As String Dim sLocal As String List1.Clear Do lCounter = lCounter + 1 RetreiveURL lCounter, sName, sLocal If Len(Trim$(sName)) > 0 Then 'add the display name to the list List1.AddItem sName 'store the record number in the itemdata property so we can retrieve it later 'see List1_DoubleClick List1.ItemData(List1.NewIndex) = lCounter Else Exit Do End If Loop End Sub Private Sub List1_DblClick() Dim lCounter As Long Dim sName As String Dim sLocal As String 'get the url storeed at the record according to the itemdata property RetreiveURL CLng(List1.ItemData(List1.ListIndex)), sName, sLocal MsgBox sName & vbCrLf & sLocal End Sub
And this is the module.
VB Code:
Option Explicit Private Type tURLInfo sURLName As String * 260 sURL As String * 260 End Type Public Sub RetreiveURL(lRecNum As Long, sURLName As String, sURL As String) Dim lFreeFile As Long Dim URLInfo As tURLInfo Dim sFileName As String sFileName = App.Path & "\URL.dat" lFreeFile = FreeFile Open sFileName For Random As lFreeFile Len = Len(URLInfo) 'Get the requested record from the file Get #lFreeFile, lRecNum, URLInfo 'clean up the info and populate vars sURLName = Trim$(StripTerminator(URLInfo.sURLName)) sURL = Trim$(StripTerminator(URLInfo.sURL)) Close lFreeFile End Sub Public Function StripTerminator(ByVal strString As String) As String Dim intZeroPos As Long intZeroPos = InStr(strString, Chr$(0)) If intZeroPos > 0 Then StripTerminator = Left$(strString, intZeroPos - 1) Else StripTerminator = strString End If End Function Public Function StoreURL(sURLName As String, sURL As String) As Long Dim lFreeFile As Long Dim lRecNum As Long Dim URLInfo As tURLInfo Dim sFileName As String sFileName = App.Path & "\URL.dat" 'Get the record number of the next available record If Len(Dir$(sFileName)) > 0 Then lRecNum = FileLen(sFileName) / Len(URLInfo) + 1 Else lRecNum = 1 End If 'open the file lFreeFile = FreeFile Open sFileName For Random As lFreeFile Len = Len(URLInfo) 'populate the UDT with the info URLInfo.sURLName = sURLName URLInfo.sURL = sURL 'put it in the file at the next record local Put #lFreeFile, lRecNum, URLInfo Close lFreeFile StoreURL = lRecNum End Function




Reply With Quote