visual basic do while input - vb.net

I have to make a "Do - while" input from a TextBox in Visual Basic. I mean I get some value for the amount of the numbers the user should type, and then I have to get this quantity of numbers from a textbox. I suppose the event is on TextBox1_KeyPress() but then the event is true even when I type in 0 for example and this way I won't be able to write the whole number, but the first digit. I want to be able to type in the whole number and then when I press Enter the value from the txtBox goes in some variable and cleans itself to write the next one.
Anyone who has any ideas? I'm really new in VB, sorry :(

dont use key_press. use key_up. in event args you will find keycode. for enter the code is 13. so when keycode = 13, extract textbox1.text to a variable. then clear the text box like textbox1.text = "". when ever you do this, increment a member variable by one. by that variable you will know how many values have been entered.

Related

Hello How can I update the value of a label with the value i get from a textbox?

The code I use is the following:
' (is on top of the listing directly after Public class form1)
Dim Score as Integer
...
Score=Val(Txtbox5.text) "Txtbox5 is control where I put in the value."
Lbl2.text=score "Lbl2 is the label where the score must display."
Txtbox5.text="" "Makes the Textbox empty."
Then the problem occurs: when I enter a new value in Txtbox5.text the I want this value update
the value in the label with the value that is already in the label by the score.
The code I use therefor is Lbl2.text=score +score but whats happend is the score in the label is double???
So what I want is: when I have a value in the label say 2 and I insert a new value in the textbox
say 3 then I want to see in the label a value of 5.
But I have tried everything but nothing works
Is there somebody who can help me with this problem??
If I understand you correctly you want to sum the current value of the TextBox5 to the Score variable and then update the label
This could be simply resolved without any thinking with
Score += Val(Textbox5.Text)
Lbl2.text=Score
Txtbox5.Text=""
But you could meet some problems because in your textbox the user can type anything, not just a number. In that context the Val function from the Microsoft.VisualBasic compatibility assemble doesn't tell you anything, simply converts the non numeric string to zero. This could be acceptable or not depending on your requirements. If you want to have a message for your user when the input is not good you could write
Dim currentInput as Integer
if Not Int32.TryParse(Txtbox5.Text, currentInput) Then
MessageBox.Show("You should input a numeric value!")
Else
Score = Score + currentInput
Lbl2.text=Score
Txtbox5.Text=""
End If
I have tried everything but nothing works
That's not strictly true..
Lbl2.Text = (Convert.ToInt32("0"&Lbl2.Text) + Convert.ToInt32(Txtbox5.Text)).ToString()
ps;
Your life would be a lot simpler if you used a couple of numericupdown controls, one readonly and no border etc to look like a label. Then life would be like:
resultNumericUpDown.Value += inputNumericUpDown.Value
Whenever you're asking the user for numbers, using a NUD saves a lot of headaches

Populating a textbox, if another textbox is populated

i've got two textboxes in my form.
According to title, when I write something in one textbox (a random one), i need that at the same time, in the other textbox a text (given in the code) appears.
1 letter for 1 letter
1)Example with random text:
1 textbox ) How are you?
2 textbox) Let's just c
2)Example with random text:
1 textbox ) What is the aim of the project?
2 textbox) Let's just chill out for a mome
thanks so much
You will need to determine which responses you would like to which questions. However, the tackle to letter for letter problem. I would use the substring method and get the length of the current text.
Dim Response as String = "Hello World!"
Private Sub Text(ByVal..) Handles Textbox1.changed
Textbox2.text = Response.Substring(0, Textbox1.text.length)
End Sub
As the text changes in the textbox you are typing in, this will output the response corresponding to the length of the text input. Since the event is textbox.changed, each character entered will update the second textbox
You need to use an event based code here. I would use a loop per stroke of the key and make the event "Key Press." Write the code onto the textbox you are inserting data into.

Visual Basic Help, format check

When I enter a non-numeric value into a numeric field, vb auto validates the field and the system does not allow me to proceed to fill the next text box.
How can I work around this? I want to write code to perform the validation on the numeric.
This is what happened as shown in picture. I cannot continue to input other fields.
field
There is probably an event handler that is limiting the input to numeric fields and possibly setting the focus on the textbox. This could be in Keydown, Leave, TextChanged, or some other events. You can replace this validation code with your own.

Two if conditions Visual Basic

I am trying to validate input in this VB program that calculates football stats. If both boxes are empty when a user clicks Update Stats, it should display a message box. However, with this code it shows the message whether both boxes are empty or if they have values entered. Any idea what I am doing wrong?
'validate user input (ensure textBoxes aren't blank)
If passYdTextBox.Text = "" And rushYdTextBox.Text = "" Then
MessageBox.Show("Please enter values into pass yards box or rush yards box")
End If
A better way to check this would be to use the IsNullOrWhiteSpace() method or even doing something like passYdTextBox.Text.Length > 0 as your problem could be due to data types and casting.
I'm sure you have already considered this as well, but this validation alone is not enough to avoid an exception. You will also need to ensure that the Text in the field is numeric before trying to cast the String.

Changing TextBox fields on Lost Focus

I am making a database with access 2007. I have a form for the call center to enter customer info; Name, Address, Phone Number, ect.
There is a field for credit card numbers and while we are supposed to enter them as first 4 numbers and last for number ie.1234xxxxxxxx4321
I want to make sure if they do enter them in that it keeps the first and last 4 numbers but changes other characters to "x" when the field loses focus. Could anyone point me in the right direction of how to do this?
Thanks in advance for all help in this matter.
If you are only storing the first 4 and last 4 digits then the following works. Modify the function validCreditCardNumber() to have whatever checks you want to apply.
Function validCreditCardNumber(creditCardNumber) As Boolean
If Len(creditCardNumber) = 12 Then
validCreditCardNumber = True
Else
validCreditCardNumber = False
End If
End Function
Private Sub cbxCreditCardNumber_LostFocus()
If validCreditCardNumber(cbxCreditCardNumber) Then
cbxCreditCardNumber.Text = Left(cbxCreditCardNumber.Text, 4) & "xxxxxxxx" & Right(cbxCreditCardNumber.Text, 4)
End If
End Sub
If you want to store the entire number but only hide the digits from the screen then I think a input masks are what you are looking for.
All you need is something like this in your form code.
Private Sub txtCC_LostFocus()
txtCC.Text = Left(txtCC, 4) & String(8, "x") & Right(txtCC, 4)
End Sub
Then what you see is what will get stored in the DB. ie.1234xxxxxxxx4321
I'm going to assume you don't want to actually keep the whole CC# in your DB. That is a huge no-no unless you spend massive time & money to meet PCI compliance. Here's some info on PCI: http://www.pcicomplianceguide.org/pcifaqs.php
There is no input mask available for partial masking of a string entry. You will need to use a custom function to change the data entered. The best way to do this would probably be to link the field in the table to a hidden textbox. You can then have a visible textbox apply some function to the value in the hidden textbox to change the characters to "X" in the LostFocus event of the visible textbox. However, it's also going to have to write the data to the hidden textbox when you change it.