Results 1 to 3 of 3

Thread: Help converting this.

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2004
    Posts
    25

    Question Help converting this.

    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:
    1. Private Sub Command1_Click()
    2.     Dim lNewRec As Long
    3.     'Store the info and return the record number
    4.     lNewRec = StoreURL(urld.Text, urll.Text)
    5.       MsgBox "Record Number " & lNewRec & " was added to the file"
    6.    
    7.     'add display name to the list
    8.     List1.AddItem urld.Text
    9.     'store the record number in the itemdata property so we can retrieve it later
    10.     'see List1_DoubleClick
    11.     List1.ItemData(List1.NewIndex) = lNewRec
    12.  
    13. End Sub
    14.  
    15. Private Sub Command2_Click()
    16.     Dim lCounter As Long
    17.     Dim sName As String
    18.     Dim sLocal As String
    19.    
    20.     List1.Clear
    21.     Do
    22.         lCounter = lCounter + 1
    23.         RetreiveURL lCounter, sName, sLocal
    24.         If Len(Trim$(sName)) > 0 Then
    25.             'add the display name to the list
    26.             List1.AddItem sName
    27.             'store the record number in the itemdata property so we can retrieve it later
    28.             'see List1_DoubleClick
    29.             List1.ItemData(List1.NewIndex) = lCounter
    30.         Else
    31.             Exit Do
    32.         End If
    33.     Loop
    34. End Sub
    35. Private Sub List1_DblClick()
    36.     Dim lCounter As Long
    37.     Dim sName As String
    38.     Dim sLocal As String
    39.     'get the url storeed at the record according to the itemdata property
    40.     RetreiveURL CLng(List1.ItemData(List1.ListIndex)), sName, sLocal
    41.  
    42.     MsgBox sName & vbCrLf & sLocal
    43. End Sub

    And this is the module.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Type tURLInfo
    4.     sURLName As String * 260
    5.     sURL  As String * 260
    6. End Type
    7. Public Sub RetreiveURL(lRecNum As Long, sURLName As String, sURL As String)
    8.     Dim lFreeFile  As Long
    9.     Dim URLInfo As tURLInfo
    10.     Dim sFileName As String
    11.    
    12.     sFileName = App.Path & "\URL.dat"
    13.    
    14.     lFreeFile = FreeFile
    15.     Open sFileName For Random As lFreeFile Len = Len(URLInfo)
    16.         'Get the requested record from the file
    17.         Get #lFreeFile, lRecNum, URLInfo
    18.        
    19.         'clean up the info and populate vars
    20.         sURLName = Trim$(StripTerminator(URLInfo.sURLName))
    21.         sURL = Trim$(StripTerminator(URLInfo.sURL))
    22.        
    23.     Close lFreeFile
    24.  
    25. End Sub
    26. Public Function StripTerminator(ByVal strString As String) As String
    27.     Dim intZeroPos As Long
    28.     intZeroPos = InStr(strString, Chr$(0))
    29.     If intZeroPos > 0 Then
    30.         StripTerminator = Left$(strString, intZeroPos - 1)
    31.     Else
    32.         StripTerminator = strString
    33.     End If
    34. End Function
    35.  
    36.  
    37.  
    38.  
    39. Public Function StoreURL(sURLName As String, sURL As String) As Long
    40.     Dim lFreeFile  As Long
    41.     Dim lRecNum As Long
    42.     Dim URLInfo As tURLInfo
    43.     Dim sFileName As String
    44.    
    45.     sFileName = App.Path & "\URL.dat"
    46.    
    47.     'Get the record number of the next available record
    48.     If Len(Dir$(sFileName)) > 0 Then
    49.         lRecNum = FileLen(sFileName) / Len(URLInfo) + 1
    50.     Else
    51.         lRecNum = 1
    52.     End If
    53.    
    54.     'open the file
    55.     lFreeFile = FreeFile
    56.     Open sFileName For Random As lFreeFile Len = Len(URLInfo)
    57.         'populate the UDT with the info
    58.         URLInfo.sURLName = sURLName
    59.         URLInfo.sURL = sURL
    60.  
    61.         'put it in the file at the next record local
    62.         Put #lFreeFile, lRecNum, URLInfo
    63.     Close lFreeFile
    64.    
    65.     StoreURL = lRecNum
    66. End Function

  2. #2

    Thread Starter
    Junior Member
    Join Date
    Apr 2004
    Posts
    25
    I was able to figure out the new index stuff in the form, still need help in the module with the FilePut and FileGet.

    This is figured out.
    VB Code:
    1. Dim x As Integer
    2.         Dim lNewRec As Integer
    3.         lNewRec = StoreURL(aaa.Text, bbb.Text)
    4.         MsgBox("Record Number " & lNewRec & " was added to the file")
    5.         x = List1.Items.Add(aaa.Text)
    6.         List1.SelectedIndex = x

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2004
    Posts
    25
    Can someone please help me with the FileGet error or syntax.


    VB Code:
    1. Public Sub RetreiveURL(ByRef lRecNum As Integer, ByRef sURLName As String, ByRef sURL As String)
    2.         Dim lFreeFile As Integer
    3.         Dim URLInfo As tURLInfo
    4.         Dim sFileName As String
    5.        
    6.         sFileName = VB6.GetPath & "\URL.dat"
    7.        
    8.         lFreeFile = FreeFile
    9.         FileOpen(lFreeFile, sFileName, OpenMode.Random, , , Len(URLInfo))
    10.         'Get the requested record from the file
    11.         '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"'
    12.         FileGet(lFreeFile, URLInfo, lRecNum)
    13.  
    14.         'clean up the info and populate vars
    15.         sURLName = Trim(StripTerminator(URLInfo.sURLName))
    16.         sURL = Trim(StripTerminator(URLInfo.sURL))
    17.        
    18.         FileClose(lFreeFile)
    19.        
    20.     End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width