Overload Clipboard.SetText VB.net 3.5 (or how to copy 3-4 text box conents at same time) - vb.net

I have a form where I require user input and when the user presses the "generate" key it will copy all the data from the relevant text boxes to the clipboard for them to enter the data in an external application.
At the moment i can only find out how to get the function to copy one text box at a time, and not string them into a sentence.
Private Sub Notes_Click(sender As Object, e As EventArgs) Handles Notes.Click
My.Computer.Clipboard.SetText(TextBox1.Text, TextBox6.Text, TextBox5.Text, TextDataFormat.Text)
The problem is that the function can no be overloaded. Can someone please confirm the function i can use (or provide me a sample code) for how to copy all text box contents to the clipboard?
This is ALL on one form

The clipboard only accepts one text value at a time, so it's pretty clear why your overload won't work. If you need multiple values, concatenate them; if you need to keep them separately identifiable, put a separator character between them and parse them back out on the receiving end.
My.Computer.SetText(TextBox1.Text + TextBox2.Text + TextBox3.Text +...)

Related

Creating a Userform to compare 4 scanned items

I apologize if this seems very simple. I am new to VBA and am struggling to determine where to begin.
I am trying to create a Userform where you scan a sample, and then 3 tubes that should match the first sample, and if they do, it will send that data to a spreadsheet, and if they do not, then it will highlight Red and make you restart.
I am running into a few problems. I am not sure how to auto enter to the next text box after the first sample is scanned. For ease of use, I would like the user to just be able to scan, scan, scan, scan without interaction with the spreadsheet.
I also have tried to make use of the AutoTab function by putting in an If/Else statement, saying if value of the textbox is NOT null, it will AutoTab to the next box in the tab index, but that does not seem to be working
Please let me know of any advice you may have.
Basically, the input of the barcode scanner is the same as if someone enters the data manually - just all characters come at once (as if it is pasted). Usually, the scanner should be able to send some End-sign, in that case you should be fine as TAB or ENTER will jump to the next field automatically.
If the scanner really send the data, you have to deal with the Change-Event of the text boxes and check if the data is valid. The following example checks for a length of 8 characters. Adapt the CheckBarcodeInput to your needs. If a valid barcode was entered, the focus is set to the next textbox.
Private Sub TextBox1_Change()
If CheckBarcodeInput(Me.TextBox1.Text) Then Me.TextBox2.SetFocus
End Sub
Private Sub TextBox2_Change()
If CheckBarcodeInput(Me.TextBox2.Text) Then Me.TextBox3.SetFocus
End Sub
(...)
Private Function CheckBarcodeInput(s As String) As Boolean
' Check if barcode is valid. In this example, it simply checks the length.
If Len(s) >= 8 Then CheckBarcodeInput = True
End Function

Textbox: missing first character typed on the TextBox

I have 2 text boxes to accept info but only one of them is need at the same time (One is for selection of the first letter and the other is for selection of any part of the name)
So I need to delete the text of the other textbox when the user start typing on the textbox
Something like this work:
Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
TextBox1.Text = ""
End Sub
But there's a problem, the first character the user type is not displayed, I think is because the first character typed is used to launch the event.
Example:
TextBox1.Text = "A"
when the user click on TextBox2 and type michael the "m" is lost
I don´t want to use the "GotFocus" event because a simple TAB pulsed to jump from TextBox1 to another control can delete the text on TextBox1 when the user stop on TextBox2, even if he don´t want to type anything there
How can I manage this mistake?
Right answer:
From #Plutonix
"No user is going to expect this behavior and you will go mad trying to divine when to execute and when not to. A better thing might be to select the text on the Enter event - at least that has been seen before by users"

Saving Multiple Times of Day in TextBox - Visual Basic

I'm having trouble figuring out how to save the time of day to a text box. The time of day is generated on a click, and I would like it to add it to the list every time I click, while keeping the older values in the list. I know how to make a list from list a list box, but I need to copy and paste the times from the box into excel. (And if I haven't asked enough already, how to format those times to be used in Excel)
To generate the time, I'm using
Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Timer1.Start()
TextBox1.Text = Date.Now.ToString("hh:mm:ss")
You can use a ListBox
On button click event do
ListBox1.Items.Add(DateTime.Now.ToString()
But it you have to use text box
Then use ' +=' operator
TextBox1.text += DateTime.Now.ToString()

Replace certain word in textbox with vb and retrieve whole string after

I'm looking to make an application that replaces a users selected word with underscores, the issue here is the fact that it does that well, however, it does not return the entire string but rather the underscores themselves.
tbText.Text = Replace(tbText.Text, tbText.SelectedText,
generateUnderscores(tbText.SelectedText), tbText.SelectionStart, 1)
Generateunderscores is a function i created that returns underscores depending on the number of letters in the selectedtext
tbText is the textbox, when a user highlights it I want this function to run. This will replace the selected text with underscores.
Notice how I make tbText.Text contain this, it then becomes ONLY underscores without the remainder of the text in the textbox.
How can I return the text in the text-box as-well as the underscores in it?
I've tried using a string replace however, the issue with that was it found multiple words instead of the ONE word I wanted removed (selected word)
Thanks.
when a user highlights it I want this function to run I dont know how you will do this part, because there is no TextSelected or SelectedTextChanged event. I used right mouse down. You could try to use Left Mouse Up, but that means the text is changed even if the user wants to made a mistake or wants to change whats selected.
Private Sub TextBox1_MouseDown(sender As Object, e As MouseEventArgs)
Handles TextBox1.MouseDown
If e.Button = Windows.Forms.MouseButtons.Right AndAlso
TextBox1.SelectedText.Length > 0 Then
TextBox1.SelectedText = MakeUnderScores(TextBox1.SelectedText.Length)
End If
End Sub
Function MakeUnderScores(n As Integer) As String
Return New String("_"c, n)
End Function
I am not sure that VB's Replace function wouldn't do the same as String.Replace

VB.NET How to insert text at cursor position in a different window?

I have a small application that displays a listbox under the cursor position when the user uses a shortcut key.
When the user double clicks a selection from the listbox I want to insert that selected text at the curser position of that opened window.
Example: user has microsoft word open. He/she uses a shortcut key that displays a listbox just under the cursor position. The listbox has a collection of text. When the user double clicks a selection that selected text is inserted at the cursor position.
I tried the following:
Private Sub ListBox1_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
Text.Insert(Cursor.Position, ListBox1.SelectedItem)
End Sub
But that doesn't work.
Any help will be sincerely appreciated.
The best (most generic) approaches will be to trick the application into thinking you have entered some text. For example:
Send keypress windows messages for all of the characters you wish to "type" to the target window (e.g. with WM_KEYDOWN or WM_CHAR type messages. Some experimentaiton may be needed to find the approach that works best).
Copy the text onto the clipboard and send a single ctrl+V keypress message to the application. (This will overrite the clipboard and may not work in apps that don't support that key shortcut though)
If you know the specfic application (e.g. MS Word) then you may be able to use application-specific automation (OLE, etc) interfaces to insert text.