I have a "bug/glitch" in my vb program need assistance - vb.net

I have a program that replaces every letter of the alphabet with something new inside the same textbox by clicking a button then buy clicking the button it translates it back to original text.
However when i run this program, yes it does work as needed but not 100%
Because after i click the button to translate, (yes it shows translated)
If delete the translated text and type something new, it goes back to the old text.
(this does not happen if i click the button again, it shows the orignal text. But if i type something new it will translate it.)
Any suggestions?

This is a continuation of your other question. You will need to reset your Boolean variable when you type in your TextBox i.e.
Private Sub TextBox1_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
bConverted = False
End Sub

Related

How can I make a textbox perform a backspace when I'm Not typing in it VB.NET

I'm making a hex keyboard converter with two TextBoxes: TextBox1 for typing in the key you want to convert, and TextBox2 for displaying what you converted.
So far I have gotten it to convert as I typed, but when I press Backspace, TextBox1 will erase the key but TextBox2 will remain with the same converted code, meaning I have to go to TextBox2 to erase it manually.
Is there a way I can make it so that when I press Backspace while typing in TextBox1, the TextBox2 will go back as well? And is there a way I can tell it how many spaces to go back?
It sounds like you are building the string by capturing each key. But couldn't you just convert the entire contents of TextBox1 and put it into TextBox2?
This is another way of doing it. See if it works
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
TextBox2.Text = shiftCharacters(TextBox1.Text)
End Sub
Private Function shiftCharacters(input As String) As String
Return String.Join("", input.Select(Function(c) ChrW(AscW(c) + 1)))
End Function
Since I don't know how you convert each character, I just shifted each character up by 1.
Here are some images
Then I deleted 123 with backspace.
Is this going to work?

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"

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 strange textbox behavior

A customer of mine is having a problem with a text box. When he clicks on the string in the text box the cursor always jumps to the end of the string. This is a standard VB.net 2005 text box with multi-line true. On my development machine it works correctly. I click in the middle of a string and can edit where I click. Can anyone suggest what is wrong?
He has run the program both under terminal server and locally on his lap top and has the same problem.
TIA,
John
Is it possible to observe the user? For example, the user might be pressing shift-tab when they are past the text-box, and refering to that as "clicking" the text box.
You can always force behavior like:
Private Sub TextBox1_GotFocus(sender As Object, e As System.EventArgs) Handles TextBox1.GotFocus
TextBox1.SelectionStart = 0
End Sub

VB.Net - How do you "dynamically" select an object?

I'm not sure if the question properly asks what I want, because I'm a bit new, but what I am trying to do is write a sub or function that I can run when a label is clicked, and I want to to be reusable on multiple labels. There will be 12 in total, and I don't wish to write the same thing over and over, with slightly different characters. A programmer never wants to write the same thing twice, right? Also, something else is making it a necessity to do it dynamically.
So, how I was trying to accomplish that was by using a string, and adding the name of the label to the string on click.
click1 = "Label1"
As it turns out, you can't just say click1.Text and return the text of Label1. The reason it's important to do it implicitly is because I need to somehow remember the one I clicked before, to compare the first click and second click, and if they match, do A, and if they don't match, do B.
The first parameter (it is called sender) to the event handler your wrote to respond to the click event is the object which sent the event.
If you assign the same routine to respond to on click of all your labels, it will be called for every one of them, but the sender parameter will point to the actual label which was clicked
HTH
mfeingold is correct, if you're unsure of the syntax:
Private Sub LabelClicked (ByVal sender As Object, ByVal e As EventArgs) Handles Label1.Click, Label2.Click, Label3.Click
sender.Text = "I've been clicked."
End Sub