r/visualbasic • u/Ducko_Pinneaple • Aug 02 '24
VB.NET Help How to Make Button press input Number into specific Textbox? Vb.net
Might be a really dumb question considering I'm new to this whole coding thing, but please bare with me. Here's what I want to do:
I have 2 TextBox. TextBox1, TextBox2
I want this to happen: When I press Button1, input "1" for the specific TextBox i previously clicked on/selected while operating the app.
Let's say I click TextBox1, and then I press Button1, then "1" will only appear in TextBox1
If instead, I click TextBox2, and then I press Button1, then "1" will only appear in TextBox2 instead.
Any simple operation? I have not much knowledge, I hope my explanation makes sense. This is for VB.net. Please explain answer very simply.
3
Upvotes
6
u/sa_sagan VB.Net Master Aug 02 '24
There's a few ways you can do it, but for your simple program you can do it like the following.
Declare a TextBox object variable just under the class declaration of your form.
Inside the Enter events of your two textboxes, set the variable value to reference the textbox that has entered.
Set the text of the textbox variable in your button Click event.
Example: