Results 1 to 5 of 5

Thread: List1.listcount problem

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2010
    Posts
    185

    List1.listcount problem

    My program has come along nicely the past couple of days. After inserting and removing my errors along the way I've now come to the last stage of this part of the program.

    So far the user types in a website address into the combo. It brings up a list of files available for download from that webpage. It saves the list to disk, including the date the file(from website) was created, the size of the file, the users filename, webpage filename, and an indicator as to whether the file has been been downloaded yet or not.

    The user can then click on the listbox name and hit return, to indicate he has downloaded/not interested in downloading the file and it will move the file over to list2. It will also change the indicator on the file to show the file has been downloaded. In the same way if the user decides otherwise that he wants to download the file again he can go into list2 and click on the file name, hit the enter key and it will move the file back into list1 and change the txt file over to indicate the file hasn't been downloaded.

    Once the user has the list down to the files he wishes to download he can click on the files and click the Rename button and rename the files with a filename he finds useful. This is the users filename I mention up in paragraph 2. It doesn't change the webpage filename just the name the file will be saved under.

    The next step is to download the files. This wouldn't be a problem other than I have to get the the web address first. I'm planning to have it so the user could go out and have everything setup and hit either one of two buttons, Download This Site or Download All Sites. In either case their could many files, some quite big...I've see one file over 1GB in size already. I gave the user the option of being able to change the filenames ahead of time so he could get everything prepped and ready to download and then he could download while sleeping at night, at work the next day, etc. If he selects Download All Sites it will go through all the sites he has looked at and will download all the files from each of those sites that he wants to download.

    Once a file has been downloaded I'm planning on having the filename moved over to List2 and have the txt file indicator changed to show the file has already been downloaded.

    In some cases their could be several to many files from one site. At the same time their could be none from another site. The worst problem right now(the only thing I have tried thus far), I believe is when their is only one file from a given site that is to be downloaded.

    eTitle is the user filename and eYN(something already created for another section of the program and I'm just reusing it for right now) is the website filename. The program will pull the website domain from Combo1.

    Code:
        For i = List1.ListCount - 1 To 0 Step -1
            strTitle = List1.List(i)
            For j = Len(strTitle) To 0 Step -1
                    If Mid(strTitle, j, 1) = "/" Then 'looking for leading "/" to indicate beginning of filename
                        strTitle = Right(strTitle, Len(strTitle) - j)
    '                    List2.AddItem strTitle
    '                    List1.RemoveItem i
                        For Counter6 = 0 To i
                            If eTitle(Counter6) = strTemp Then
                                eId(Counter6) = "1"
                                strTemp = "http://" & Combo1.Text & "/" & eYN(Counter6)
    '                            Call SaveFileList
                            End If
                        Next Counter6
                        Exit For
                    End If
                Next j
        Next i
    It appears since List1 only has one file in it that the first file must be number 0. When I go to For Counter6 = 0 to i it doesn't want to execute the For...Next loop. As a result it won't create the address that is suppose to be downloaded.

    I have noticed in some other testing that I'm now having the same trouble in the Rename code. The code is pretty much copy and pasted from the Rename section to the Download section. I didn't have the problem earlier...then again I hadn't removed the files earlier to only have one file left to download in any one list.

    How do I eliminate this problem. I know ever since Saturday morning I've been fighting off and on at times with List1.Listcount trying to get that darn thing to work correctly.

    Thanks

    PS I just checked thanks to stumbling into something online. I downloaded the list from another website and decided to try to change the user filename. It changed slick as a whistle. I went back to one of the sites/lists where I only had one file. I tried to rename the file and it wouldn't bring up the Inputbox. I think the problem is now very evident.
    Last edited by hijack; Nov 21st, 2010 at 10:28 PM. Reason: I just made a quick check

  2. #2
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: List1.listcount problem

    I think the problem is elsewhere. A For / Next loop will execute whilst the loop control variable is less than or equal to the end value. Your Counter6 loop will execute once when i = 0. I suspect that eTitle(0) does not contain what you expect. ( I wonder if you've started at element 1 (rather than 0) when you populate eTitle)

  3. #3
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: List1.listcount problem

    Instead of that looping and other stuff in this portion:
    vb Code:
    1. '.....
    2.  
    3.     For j = Len(strTitle) To 0 Step -1
    4.         If Mid(strTitle, j, 1) = "/" Then 'looking for leading "/" to indicate beginning of filename
    5.             strTitle = Right(strTitle, Len(strTitle) - j)
    6.            
    7.             '....
    8.            
    9.             Exit For
    10.         End If
    11.     Next
    12. '....
    you could extract the filename using a single line of code.

    This is the code:
    Code:
    strTitle = Mid$(strTitle, InStrRev(strTitle, "/") + 1)
    Example:
    vb Code:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4.     Dim strTitle As String
    5.    
    6.     strTitle = "http://www.vbforums.com/images/logo.gif"
    7.    
    8.     strTitle = Mid$(strTitle, InStrRev(strTitle, "/") + 1)
    9.    
    10.     MsgBox strTitle
    11. End Sub
    ...

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  4. #4
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: List1.listcount problem

    The only 'problem' with using InStrRev like that, is if the "/" is not in the string. The code will return the complete string, since InStrRev(strTitle, "/") will return 0. I know it's not very likely to happen in this application, but ....

    I'd modify the example slightly
    Code:
    Option Explicit
    
    Private Sub Command1_Click()
        Dim strTitle As String
        Dim intI As Integer
        strTitle = "http://www.vbforums.com/images/logo.gif"
        intI = InStrRev(strTitle, "/")
        If intI > 0 Then
            strTitle = Mid$(strTitle, intI + 1)
            MsgBox strTitle
        Else
            MsgBox "/ Not Found in Title (" & strTitle & ")"
        End If
    End Sub

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Nov 2010
    Posts
    185

    Re: List1.listcount problem

    Okay, this may have taken care of a couple of things, one related and another totally unrelated. I'm going to have to play around with the code a little to see if I can shorten the code up using the InStr concept. I'm using InStr, just not this way. I'm going to have to try the idea out all the way and see what I can come up with.

    Back on the subject of List1.Listcount. I have noticed another problem now, for sure.

    Code:
    For i = List1.ListCount - 1 To 0 Step -1
            If List1.Selected(i) Then
                strTemp = List1.List(i)
                strTemp = Mid$(strTemp, InStr(strTemp, ".") + 6)
                List2.AddItem strTemp
                List1.RemoveItem i
                For Counter6 = 0 To Counter5
                    If eTitle(Counter6) = strTemp Then
                        eId(Counter6) = "1"
                        Exit For
                    End If
                Next Counter6
            End If
        Next i
        Call SaveList
    Up where I have it in List1 where they click on the name and move it over to list two. When ever they hit enter and it runs through this list it appears that it has did everything correctly...until. Until you go take a look at the txt file. Now the top entry is missing. For example you list from before the move was:

    1
    2
    3
    4
    5

    After the move the the txt file on the hard drive will only show:

    2
    3
    4
    5

    It has totally removed the first entry altogether.

    From what I've heard to be able to remove anything from one listbox I have to use List1.Listcount -1 which is where I'm thinking the problem lies. If I remove the -1 it always comes up with Invalid Array Property Index error, #381. How do I keep from losing the first entry?

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