Go to the Beginning of String in "System.Windows.Forms.TextBox" - VB.Net - vb.net

I have an application written in VB.Net where I call a dialog window that lets a user select a file or folder to copy. In that window I have text pre-populated in the file name field as an informational type of message to the user. However the text is so long that it only shows the last bit of it, so I need a way to reset the cursor position to the first character in the string. I also have the text highlighted by default so that the user can just begin typing to overwrite it. Here's what I have so far-
pushLocationBox1.SelectAll()
cursorPosition = pushLocationBox1.SelectionStart
I think the "cursorPosition = pushLocationBox1.SelectionStart" is a good start at getting the location I need to point the cursor to, but I'm not sure where to go from there.
Thanks in advance.

Related

Search text file and put matching results in listbox

I have a VB.NET project in which there is a form where there is a TextBox control, a ListBox control and an external text file that contains a list of outlook folder paths for client emails.
Essentially, the user enters into the text box the name of a client and/or their unique reference number, presses the search button (yes - I know I could make the results appear as they type, I want a button!) and it comes up with the matching results for the company name or serial number that are in the text file and puts them in the list box, with the full path of the outlook email folder.
For example:
If I put into the textbox: "06967759-274D-40B2-A3EB-D7F9E73727D7"
It would put the following result into the listbox:
"EIS Admin\Contacts{06967759-274D-40B2-A3EB-D7F9E73727D7}"
And the user can then go to that folder and find the email(s).
I have gone through several revisions both of my own code and code pasted from online with people having the same issue, only to have Visual Studio throw no errors, run the code and have no luck, with it doing nothing but clearing the list box, and not showing matching results of any kind.
I understand this may be a repeat question but I am extremely confused, can't get anything to work and need some help regarding my issue.
Here is the current code (from online - not mine):
lbx_OFL_Results.Items.Clear()
Dim i As Integer
For i = 0 To lbx_OFL_Results.Items.Count - 1
If i > lbx_OFL_Results.Items.Count - 1 Then Exit For
If Not lbx_OFL_Results.Items(i).Contains(tbx_FindText.Text) Then
lbx_OFL_Results.Items.Remove(lbx_OFL_Results.Items(i))
i -= 1
End If
Next
The list box is called "lbx_OFL_Results"
The textbox is called "tbx_FindText"
I start by clearing the list box of all items (when the form loads, it fills the list box will all lines of the text file, so I need to clear it).
Form Load Event Code:
Dim lines1() As String = IO.File.ReadAllLines("C:\ProgramData\WPSECHELPER\.data\Outlook Folder Wizard\outlookfolders.txt")
lbx_OFL_Results.Items.AddRange(lines1)
For the rest of the code it seems to be doing some form of a 'sort search' then removing any excess results.
If anyone can suggest edits to my code, or new code then that would be sublime.
Thanks.
Thanks to #Jimi for the answer.
Code:
listbox.Items.Clear()
listbox.BeginUpdate()
For i as Integer = 0 To lines1().Length - 1
If lines1(i).Contains(searchbox.Text) Then
listbox.Items.Add(lines1(i))
End If
Next
listbox.EndUpdate()
I have another question which solves how to make this search non case-sensitive. It can be found here.

Visual Basic application store Settings in different paths

need to ask, I have simple app, which had one textbox and one button. When I type something to that textbox and push that button, it saves to my Settings...
see:
Dim Settings As New My.MySettings
Settings.something = TextBox2.Text
Settings.Save()
MessageBox.Show(Settings.something.ToString)
Everything works great, but when I build it and run for example from my desktop path, Enter number save it and close it. When I make a copy of this file to my documents path and open it, nothing loaded, but when I start it from the place where I last save it, it loads properly.
In the short description:
If I run app on my Desktop path and make a save, when I close the app and copy this file (.exe) to another path, I need to load previous saved data from Desktop path, or other different location.
Save in path A, copy it from and open anywhere in path B, C, D... etc.
Is it possible, if yes, how can I do that?
Thanks!
You may be looking for something like the 'SaveSetting" method
SaveSetting("MyApp", "Form1", "Text", "ValueToSave")
The first, second and third parameters indicate a "Path" where your value will be saved, and the fourth is the value itself.
Then, you can load the saved value using the following method:
MyText = GetSetting("MyApp", "Form1", "Text", "DefaultValue")
Note that the first three parameters must be the same as used on the save method, and the fourth is the default value, in case no previous data has been saved.

Insert/replace string in existing text form field in Word (VBA)

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.

Save a user popup selection in a custom Automator Action

Using Xcode 5.* for a cocoa-applescript automator action.
Interface is a a simple popup menu that gets populated using an outlet with:
tell thePopupMenu to removeAllItems()
tell thePopupMenu to addItemsWithTitles_(theList)
When the action is used in a workflow (a Service actually), I want the next time it is run and the action dialog shows up (I will have "Options:Show when run" selected), I want the popup menu to change the selection to the last one that was selected. Right now, the default first item shows, even though last time it was run, the user selected a different item in the popup menu.
My thought was that I need to capture a change in the popup menu with a Sent Action handler, and then set some type of default. I have a working handler:
on thePopupMenuSentAction_(sender)
set popupValue to (popupSelectedValue of my parameters()) as string
-- save this selection somewhere???
end
What's the right way to save this? Do I use User Defaults? My Bindings are currenly all tied through Parameter object/controller. If I should use User Defaults, can someone give example code for setting up User Defaults, and then how to get and set a new value using Cocoa-Applescript?
If I can get the name string of the menu item saved somewhere, I can get the string and then change the selection of the popup menu in the
on opened {}
-- set up the action interface
end
handler which gets called just before the action is displayed each time.
Thanks for any help,
Joe
I did mine a bit differently. I will assume you are referring to what XCode calls a "pop up button" (somewhat misleading). I did not use the parameters at all, although that is probably better for larger projects. Have a look at the code:
script Insert_Picture_into_Powerpoint_Slide_Show
property parent : class "AMBundleAction"
property menuChoices : {"Insert a Beginning", "Insert at End"}
property menuSelection : missing value
if (menuSelection as string) is "missing value"
set menuSelection to 0 as integer -- sets default value
end if
end script
I bound Content Values to File's Owner and under Model Key Path I put menuChoices.
Then you just bind the Selected Index to File's Owner and for the Model Key Path type menuSelection.
Defaults
On the initial run, if the user does not click anything, the menuSelection will be missing value. Because I couldn't find a way around this, I created a conditional which tests for this and sets it to the first choice by default (the one that is shown when you add the action).
When the user selections one of the menu choices, the choice is remembered on sequential runs.

Find the difference (text)

I need a way to run a sub every time that text is added to a richtextbox. There is a changed event, but I have to know exactly what was added and at what position (even as trivial as a single space). I was going to do 'onKeyUp' but if users press CTRL + V, instead of getting the inserted content, I'll end up with just a 'v'.
Is there a way to do this? I need to be able to get the position that the content was added at and what was added. I'm doing this in VB.net.
I want to basically do something similar to http://typewith.me/
Let me show an example of what I want:
TEXT 1:
This is a message, currently no changes have been performed.
TEXT 2:
This is a message, currently none changes have been performed.
OUTPUT:
'ne' added at index position 31.
Cheers!
This might not be the most elegant solution, but the first thing that springs to mind is to store the contents of the text box in a variable. Every time it's changed, check the new contents of the text box against the stored contents and do whatever you need to, then store it again. This handles typing, pasting, deleting, etc.