|
-
May 20th, 2008, 08:14 AM
#1
Thread Starter
Member
[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?
-
May 20th, 2008, 08:16 AM
#2
Re: [2005] Displaying a string
you're asking it to remove letters from the string, starting at the end of the string
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 20th, 2008, 08:21 AM
#3
Thread Starter
Member
Re: [2005] Displaying a string
I want to remove them from the end, and go backwards ... I thought that was what it did ... :S
-
May 20th, 2008, 08:24 AM
#4
Re: [2005] Displaying a string
try it this way
vb Code:
tempresult.Remove((tempresult.Length - letter), tempresult.Length - (tempresult.Length - letter))
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 20th, 2008, 08:43 AM
#5
Thread Starter
Member
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.
-
May 20th, 2008, 09:14 AM
#6
Thread Starter
Member
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?
-
May 20th, 2008, 09:19 AM
#7
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 20th, 2008, 09:47 AM
#8
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|