Results 1 to 8 of 8

Thread: [2005] Displaying a string

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2007
    Posts
    56

    [2005] Displaying a string

    Hello,

    I've recently completed a little bit of code and want to see it displayed in a message box. This I can do, the problem comes when it is displayed, it will read:

    -1

    This is my code:

    Code:
    HideWelcomeScreen()
            HideAddItems()
            lst_results.Visible = True
            lst_results.Items.Clear()
            counter_search = 0
            letter = Len(txt_search.Text)
    
            Do While counter_search < letter
                tempresult = tempresult + lst_dictionary.Items.Item(1)
                tempresult.Remove(tempresult.Length, (tempresult.Length - letter))
                counter_search += 1
            Loop
    
            MsgBox(tempresult, MsgBoxStyle.OkOnly, tempresult)
    The error says "Index and count must refer to a location within the string."
    This is pointing to here:

    tempresult.Remove(tempresult.Length, (tempresult.Length - letter))

    What can I do here?

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: [2005] Displaying a string

    you're asking it to remove letters from the string, starting at the end of the string

  3. #3

    Thread Starter
    Member
    Join Date
    Oct 2007
    Posts
    56

    Re: [2005] Displaying a string

    I want to remove them from the end, and go backwards ... I thought that was what it did ... :S

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: [2005] Displaying a string

    try it this way

    vb Code:
    1. tempresult.Remove((tempresult.Length - letter), tempresult.Length - (tempresult.Length - letter))

  5. #5

    Thread Starter
    Member
    Join Date
    Oct 2007
    Posts
    56

    Re: [2005] Displaying a string

    Code:
    HideWelcomeScreen()
            HideAddItems()
            lst_results.Visible = True
            lst_results.Items.Clear()
            counter_search = 0
            letter = Len(txt_search.Text)
    
            Do While counter_search < (lst_dictionary.Items.Count)
                tempresult = lst_dictionary.Items.Item(counter_search)
                tempresult.Remove((tempresult.Length - letter), tempresult.Length - (tempresult.Length - letter))
                If tempresult = txt_search.Text Then
                    lst_results.Items.Add(tempresult)
                End If
                counter_search += 1
            Loop
    That code seems to work perfectly, until you enter 3 characters, then I get the error message that "StartIndex cannot be less than zero." This is here again:

    tempresult.Remove((tempresult.Length - letter), tempresult.Length - (tempresult.Length - letter))

    If you want me to, I can zip the whole file up and you guys can have a look yourselves.


    I still have not managed to get a result in the lst_result list box.
    Last edited by Deadly Asphyxiation; May 20th, 2008 at 08:57 AM.

  6. #6

    Thread Starter
    Member
    Join Date
    Oct 2007
    Posts
    56

    Re: [2005] Displaying a string

    Okay, I think I've nearly completed this.

    The last part is to trim the end of the string: tempresult

    Basically, if a person enters "4" then it searches the first item on the listbox. That is 404 error. I want it to trim the "04 error" off of the "404 error" so only 4 is left. How can I do this?

    I've tried this code:

    Code:
    tempresult.Remove((tempresult.Length), tempresult.Length - (tempresult.Length - letter))
    And it doesn't work.

    Any ideas?

  7. #7
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: [2005] Displaying a string

    it works this way

    vb Code:
    1. .remove(startIndex, length)

    its zero based so startIndex cannot be less than zero & length + startIndex + 1 cannot be greater than the length of the string

  8. #8

    Thread Starter
    Member
    Join Date
    Oct 2007
    Posts
    56

    Re: [2005] Displaying a string

    So what should I place in there?

    I've tried a few variations of what I said didn't work, and still can't get it to work ...

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