- This topic has 13 replies, 4 voices, and was last updated 15 years ago by Admin.
-
AuthorPosts
-
March 29, 2009 at 7:36 pm #187406AdminAdministrator
Aigh so I am spitting the textbox text with this code.
Where the division would be made in the ” : “
Ya know like in paltalk nicks messages are like this
nick : my message here the codeDim s As String = Me.RichTextBox2.Text
Dim parts() As String = s.Split(":"c)
Me.TextBox1.Text = (parts(0))
Me.TextBox2.Text = (parts(1)).TrimIt works okie, but now and then I get this damn error
{“Index was outside the bounds of the array.”}
wtf is that 🙂March 29, 2009 at 7:59 pm #187419AdminAdministratorAh, the solved it in the vbforums.com forums ehhehe here the working code 8)
Dim s As String = Me.RichTextBox2.Text
Dim parts() As String = s.Split(":"c)
If parts.Length >= 2 Then
Me.TextBox1.Text = (parts(0))
Me.TextBox2.Text = (parts(1)).Trim
End IfMarch 30, 2009 at 7:49 pm #187418autopilotMemberyes what was happening was the line of text did not start with a nick so it did not have :
so parts would only have length of 1 {parts(0)}March 30, 2009 at 11:02 pm #187417AhFoxMemberif you have the timestamps on .. then thw whole shit is going bad
Test it with timestamps on / off.
March 31, 2009 at 2:18 pm #187416AdminAdministratorCrap, yeps timestamp messes it up 🙂 so wtf I gonna do now lol double split lol man you guys betta stop using time stamp lol
March 31, 2009 at 5:54 pm #187415AhFoxMemberhehe … a lot of programs out there did not check for timestamps … and most of the time the bot don’t work if you turn it on.
First check for timestamps .. then do the do the split
If timestamps on Remove all text before nickname, then do the split …
I don’t feel good about this method splitting man … think of something else … it might be a way to do it … but might not be the correct way 🙂
What if I enter,
:::wow::: cool …Then you’re missing the text 🙂
Hope this helps.
March 31, 2009 at 7:26 pm #187414autopilotMember@NVYE wrote:
What if I enter,
:::wow::: cool …Then you’re missing the text 🙂
if he wants to use the split method, he can always go with parts(0) contains the nic and then if the length of parts() > 2 then loop through parts(i) to reconstruct chat and then trim chat after it is reconstructed.
but there is a better way to do it
Dim sLineIn As String = Me.RichTextBox2.Text
Dim iSplit As Integer = sLineIn.IndexOf(":")
Dim sNic As String = sLineIn.Substring(0, iSplit)
Dim sChat As String = sLineIn.Substring(iSplit + 1)
TextBox1.Text = sNic.Trim
TextBox2.Text = sChat.Trimand once you understand what it is doing, it can be shortened to:
Dim iSplit As Integer = RichTextBox2.Text.IndexOf(":")
TextBox1.Text = RichTextBox2.Text.Substring(0, iSplit).Trim
TextBox2.Text = RichTextBox2.Text.Substring(iSplit + 1).TrimMarch 31, 2009 at 8:06 pm #187413autopilotMemberyou may even want to create 2 functions like this:
Private Function sNic(ByVal sLineIn As String) As String
Dim iSplit As Integer = sLineIn.IndexOf(":")
Return sLineIn.Substring(0, iSplit).Trim
End Function
Private Function sChat(ByVal sLineIn As String) As String
Dim iSplit As Integer = sLineIn.IndexOf(":")
Return sLineIn.Substring(iSplit + 1).Trim
End Functionand then call them like this:
TextBox1.Text = sNic(RichTextBox2.Text)
TextBox2.Text = sChat(RichTextBox2.Text)if you have a task that is done in more then 1 place in the app, it is usually best to make it into its own sub/function so you dont have repeating code all over your app to write/update.
this also helps for troubleshooting. you do not have to troubleshoot a large piece of code, you can troubleshoot just a small portion at a time. Once that is working, move on to the next piece.
March 31, 2009 at 8:10 pm #187412AdminAdministratorBetter way 🙄 umm like looping to find the first ” : ” then split that 😆
March 31, 2009 at 8:27 pm #187411autopilotMember@Admin wrote:
Better way 🙄 umm like looping to find the first ” : ” then split that 😆
how much code would it take you to loop through to : and how long will it take to process? I have it boiled down to 3 lines if you dont use the functions & 2 lines per function if you do use the functions. and without looping, you will not be burning up processor power for the task.
March 31, 2009 at 8:45 pm #187410AdminAdministrator🙂 man I don’t know, hey auto but when I use the code I still got the problem with time stamp, man why people like using time stamp
March 31, 2009 at 8:49 pm #187409AdminAdministratorGot and idea, why not check if timestamp is on and then get the message to the right of “PM)” or “AM) ” :swift:
March 31, 2009 at 9:39 pm #187408AhFoxMember@autopilot wrote:
but there is a better way to do it
Dim sLineIn As String = Me.RichTextBox2.Text
Dim iSplit As Integer = sLineIn.IndexOf(":")
Dim sNic As String = sLineIn.Substring(0, iSplit)
Dim sChat As String = sLineIn.Substring(iSplit + 1)
TextBox1.Text = sNic.Trim
TextBox2.Text = sChat.Trimand once you understand what it is doing, it can be shortened to:
Dim iSplit As Integer = RichTextBox2.Text.IndexOf(":")
TextBox1.Text = RichTextBox2.Text.Substring(0, iSplit).Trim
TextBox2.Text = RichTextBox2.Text.Substring(iSplit + 1).TrimThis looks like a good solution.
March 31, 2009 at 11:43 pm #187407ChikeMember@Admin wrote:
Got and idea, why not check if timestamp is on and then get the message to the right of “PM)” or “AM) ” :swift:
First look if timstamp item in settings menu is checked, then you positively know if it’s on or not. I once posted code to find commands at runtime, you can make it more simple by hard coding the submenu and item number.
Then look if the line begins with space, only notification lines begin with space, and process accordingly.
if timestamp is on look for “) ” before the line, wether user or notofication.
User names ends with “: “, find the index and split like autopilot, but is iSplit + 2, no need to trim.
of course you need to check for whispers, and there is no realy reliable way to tell if the line is a whole line or part of line that broke because it’s long, unless you gonna subclass the room text control.Regardin processor usage, it’s not only how many lines of “code” you have.
Split cause creation of 2 new string and copy from the original, Trim cause another creation of string and copy. But it’s nothing compared to what you still gonna do.
Worry less about cpu and more on how to get it right first. Then if there’s a problem you can look into optimizations -
AuthorPosts
Related
- You must be logged in to reply to this topic.