[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?
Re: [2005] Displaying a string
you're asking it to remove letters from the string, starting at the end of the string
Re: [2005] Displaying a string
I want to remove them from the end, and go backwards ... I thought that was what it did ... :S
Re: [2005] Displaying a string
try it this way
vb Code:
tempresult.Remove((tempresult.Length - letter), tempresult.Length - (tempresult.Length - letter))
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.
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?
Re: [2005] Displaying a string
it works this way
vb Code:
.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
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 ...