However, the function only saves the cursor position from the original text length, so it does not return the cursor to the end of the replaced string.
One more thing... i do not necessarily was the cursor to go to the end of the textbox
I'd imagine you would have to reduce or increase the cursor position based on the number of chars you removed or added. You most likely don't want to hard code the number because you will most likely be replacing different strings. So something like.
Dim replace1 as string = " 2w "
Dim replace2 as string = " 2 weeks "
if replace1.length > replace2.length then
cursorposition = cursorposition + (replace1.length - replace2.length)
elseif replace2.length > replace1.length then
cursorposition = cursorposition - (replace2.length - replace1.length)
end if
I have no idea if that code is right, but its just a theory. You also don't have to do anything when they are the same. Hense no else.
Last edited by Darkwanderer; Mar 18th, 2009 at 01:50 PM.
Reason: Sometimes I wonder how English is my only language...
Use Select Case on Text.Chars(Text.Length-2). Then, put all of your shortcuts in Case blocks for replacing text after Text.Length - 2. At the end of all of these blocks, add:
Dim cursorposition As String
Dim cursorposition1 As String
If e.KeyCode = Keys.Space Then
If TextBox5.Text.Contains(" 2w ") Then
cursorposition1 = TextBox5.SelectionStart()
TextBox5.Text = TextBox5.Text.Replace(" 2w ", " 2 weeks")
cursorposition = cursorposition1 + 4
TextBox5.SelectionStart = cursorposition
End If
End If
is there a way to read this information from central source in order to input it? how about a table? so it can pull the shortcut phrase, the replacement text, and the text length to redefine the cursor position?
lets say i type in 2 w and the textbox then displays
2 weeks and then i place the cursor between the w and e of weeks and press space. will i end up with
2 weekseeks
or
2 weeks eeks
i hope you are thinking this all the way through. if it were me i would start by having a second textbox with the decoded result in that.
lets say i type in 2 w and the textbox then displays
2 weeks and then i place the cursor between the w and e of weeks and press space. will i end up with
2 weekseeks
or
2 weeks eeks
i hope you are thinking this all the way through. if it were me i would start by having a second textbox with the decoded result in that.
You could also use a Sub to do all of this for you, just one line each Case.
You could read from a file, too, using a recursive Sub, but I'll let you figure that one out (unless you're really stuck.)
Was exactly what he was trying to avoid. What if they are typing in the middle of a 3 page essay. That's going to zoom them to the end of their text instead of where they were typing.
You could also use a Sub to do all of this for you, just one line each Case.
You could read from a file, too, using a recursive Sub, but I'll let you figure that one out (unless you're really stuck.)
Was exactly what he was trying to avoid. What if they are typing in the middle of a 3 page essay. That's going to zoom them to the end of their text instead of where they were typing.
Oh! You're right, my code only works if the user is typing at the end. Ok, then, I'll submit the proper code in a minute.
And yes. To fix all your problems, put my code in a Sub, and call it for each line in a file, with the proper length. But like I said, it only works if the user is typing at the end.
I should let you know I am getting this error from your previous code
'Substring' is not a member of 'System.Windows.Forms.TextBox'.
Originally Posted by minitech
Oh! You're right, my code only works if the user is typing at the end. Ok, then, I'll submit the proper code in a minute.
And yes. To fix all your problems, put my code in a Sub, and call it for each line in a file, with the proper length. But like I said, it only works if the user is typing at the end.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
LoadData() 'Load the data
End Sub
End Class
Oh, and I just realized... if they're in the middle of the text, then it doesn't register a space. Just change the sub to handle a KeyPress, then execute the instructions if it was a space.
Hope this helped!!!
___________________________________
MINITECH, Beginning VB Programmer
Remember to rate helpful posts.
And for your last question...
If you don't want to type it out ,use a FileStream with mode set to "Append" with a StreamWriter, like this:
Code:
Dim fs As New IO.FileStream("abbr_info.dat",IO.FileMode.Append,IO.FileAccess.Write)
Dim sw As New IO.StreamWriter(fs)
sw.WriteLine()
sw.Write(abbreviation & " ")
sw.Write(extended)
sw.Close()
fs.Close()
Attached is an example file. (ext. is .txt, change to .dat.)
Last edited by minitech; Mar 18th, 2009 at 04:00 PM.
so the structure of the .dat file is parsed with a , or tab or space?
Originally Posted by minitech
And for your last question...
If you don't want to type it out ,use a FileStream with mode set to "Append" with a StreamWriter, like this:
Code:
Dim fs As New IO.FileStream("abbr_info.dat",IO.FileMode.Append,IO.FileAccess.Write)
Dim sw As New IO.StreamWriter(fs)
sw.WriteLine()
sw.Write(abbreviation & " ")
sw.Write(extended)
sw.Close()
fs.Close()
I am at a loss right now, maybe I will come back later with fresh eyes and see if it will work - thanks for all of your help and effort. it is truly appreciated!!!!!!!!!
Originally Posted by cmalloy
Hmm. Error - Index and length must refer to a location within the string. Parameter name: Length