Ok, I'm writing a program in vb. It's simply a text editor. However i've run into a little snag. My program has options to click a button and text is inserted into the text box. I am using this line:
textbox.AppendText (sometext)
Now this code works great if i want the text to be added at the bottom of the page. So here's my question, is there any way to modify or maybe replace this code so that the text is inserted were the cursor is?
Try setting .SelectedText property or using .Paste(String).
Not through the textbox control itself, as far as I know. You will need to use the SelectionStart property to manually insert the text.
textBox1.Text = textBox1.Text.Substring(0, textBox1.SelectionStart) & "INSERTEDTEXT" & textBox1.Text.Substring(textBox1.SelectionStart)
This is assuming you want to insert the text and not just replace it.
Related
So I'm trying to create a conditional dropdown in Word. I've used a Legacy Drop-Down Form Field with multiple options.
What I want to happen is when one of the options is selected from the dropdown (and then I guess you have to Tab to enter it...), the Legacy Text Form Field below, that has a simple default text, should populate with a new string from the case statement.
Things that I've already done/got working:
the drop down is working, and on exit it runs a macro
case statement is written out
the result of the case statement is in a variable (string type), let's call it StringVar
can pull the text form field's text (default text) with ActiveDocument.FormFields("TextBox").Result
What I figure out, however, is how to replace the default text in the already existing Text Form Field with the case statement's string variable text.
I've tried
ActiveDocument.FormFields("TextBox").Result = StringVar
but it doesn't change anything inside the text form field. The default text is still there.
So I can answer my own question after pondering and being hit with an "oh, duh" moment.
I had unprotected the document (ActiveDocument.Unprotect Password:="") in order to do this:
ActiveDocument.Content.InsertAfter Text:=("This is my text")
because I was wondering if I was grabbing the right string.
Turns out,
ActiveDocument.FormFields("TextBox").Result = StringVar
DOES work. BUT the file has to be protected (filling in forms) for it to replace the string in the text form field. Otherwise, nothing shows up even though the result had indeed been updated. Fancy that.
I am trying to add text to current text that is in a textbox using a checkbox. Once the checkbox is checked, it will "add" the text to the textbox before the text already in the textbox.
example:
if the textbox said "Jake", it would say "Hello Jake" once the checkbox was checked.
EDIT: sorry for the quick question. I'm in a hurry. But the only method I could think of was concatenating and appending text. As far as I know append() adds only to the end, and concatening isn't the logical approach. I don't have a coded example because I dont even know how to approach this issue. thanks.
It's getting a thumbs down because its so simple, but not. I'm using multiple checkboxes. So one needs to be in the very front, one in the center, etc. Each checkbox injects text into the textbox a certain way. I can do this with nested if statements, but then we got a mess.
Try using this code :
if chbHello.Checked then
txtName.Text = chbHello.Text + " " + txtName.Text
Note : if the checkbox is the trigger put this code in the checkbox.
All it does is see if the checkbox was checked or not.
When its checked just concatenate the text of the textbox and the checkbox with the
checkbox first.
I have a form that I want refreshed when the submit button is clicked. Preferably those that have default values will be restored and those without will be blank.
The submit button has an attached OnClick Macro that, checks to make sure all fields are filled, if so an action query runs that inserts a new row into a table.
So its after this action query that I want the refresh to occur. I have tried researching and come across suggestions that suggest using VBA code Me.Requery or Me.Refresh. I'm not 100% on how to incorporate this into the macro. The RunCode command doesn't recognize the function I put the code in, and The convert macro to VBA option in the top left is grey'd out.
I'm new to Access and just not seeing where the communications are for code and macros if someone could please elaborate for me I would be greatly appreciated.
Please consider my solution as a brief introduction to VBA. If you care to learn the language, you will find there is very little you cannot do.
Within your submit button properties, there should be an 'Event' tab. In this tab, the On Click should be set to [Event Procedure]. Click the three dot button just to the right of that, and it will launch the VBA editor.
All you need to have here between the Private Sub and End Sub lines are these lines of code:
DoCmd.RunMacro ("Mac_1")
Me.TextBox1.Value = "Null"
Me.CombBox1.Value = "Null"
Me.Refresh
MsgBox "Your Save Was Successful.", vbOKOnly, "Saved"
"Mac_1" is the name of the macro you want to execute. the ME.Refresh executes as soon as mac_1 finishes, and will refresh the page. Be sure to enclose it in a proper quote (") and not a double tick ('').
The Requery command can be used from both within VBA code or a macro. It sounds like you are using the macro designer so you can use the Requery macro action instead of VBA.
Just add this to your macro after you have inserted your new data.
This macro action lets you specify a control to requery. The parameter can be left blank to requery the source of the active object. More information can be found here.
Edit
In response to your comments, I think you should try experimenting with the SetProperty macro action (more details here).
I have attached this macro to a button click event and the value from the TextBox called txtInputValue is cleared. The Value field is left blank as you want to fully remove the value from the text box.
I am a newbie to VB.Net. Before, I did programming in PHP. I made a spell checker in PHP which splitted a big string into single word by spaces, checked if the word is there in the dictionary, if not, it highlighted it and gave some suggestions when a user clicks on it. I want to make the same thing in VB.Net... Any ideas??
Thanks.
make use of a Dictionnary(Of String, String) for your dictionnary. ;
To split the string, you have the Split function (" ,;.") ;
define ExtWord, a class holding the word, a boolean stating if in or not the dictionnary,
and the proposed corrections.
Then you have a list of ExtWord that you bind to a ListView, the
listview having a Horizontal WrapPanel as ItemsPanel.
Set the background color of TextBlock depending if inside the Dictionnary or not .
Then handle the right click on a TextBlock, and can build a ContextMenu in code and add the correct words inside it in code, then show it.
Only problem i see is how to do the 'carriage return' with
the WrapPanel.
Hopes it helps to get to your solution.
Try below link for spell checker in vb.net
http://www.a1vbcode.com/app-3641.asp
http://www.codeproject.com/Articles/265823/i00-VB-NET-Spell-Check-No-3rd-Party-Components-Req
I want to programmatically set the focus to the last row (bottommost, its only one column wide) in the DataGridView control for Visual Basic. How can I do so?
So far, I have tried
DGV.Rows.GetLastRow(DataGridViewElementStates.Selected)
without success, though I did not expect that to work.
It absolutely must select that last cell. Otherwise, the application is nearly impossible to use!
Here is a screenshot of what I am making with this: http://www.mediafire.com/?mmyogzytgzt
The "Paste Clipboard Contents" button only pastes into the selected cell, though I guess I could find a workaround.
I solved it. I used a workaround to add the text in directly. I don't need this anymore!
To select the last column, last row in c# (sorry I don't have a vb project I'm working right now:
this._dg.ClearSelection(); // eliminates what they already have selected if you need
this._dg[this._dg.ColumnCount-1, this._dg.RowCount-1].Selected = true;
In VB.net replace 'this' with 'me', and [] with ().
This is also useful:
this._dg.Focus();
this._dg.CurrentCell = this._dg[this._dg.ColumnCount - 1, this._dg.RowCount - 1];
this._dg.BeginEdit(false); // true if you want all text highlighted
// for deletion or replacement