enter key

  • Thread starter Thread starter Steve
  • Start date Start date
S

Steve

I am new to vb. I have visual studio .net 2003. I have a textbox the user
enters information into. After the information is entered, I have a button
they click and this executes code. However, I would like for them to be
able to press the enter key on the keyboard and the code for my button will
be executed. Any help would be much appreciated.

One more question. I have two labelboxes. I have written code that puts a
random number into each labelbox. My code is below.

If CheckBox2.Checked Then

Randomize(lblNum1.Text = CInt(Int((TextBox2.Text * Rnd()))))

ElseIf CheckBox1.Checked Then

lblNum1.Text = TextBox1.Text

Else

lblNum1.Text = CInt(Int((13 * Rnd())))

End If

If CheckBox3.Checked Then

lblNum2.Text = CInt(Int((TextBox3.Text * Rnd())))

ElseIf CheckBox4.Checked Then

lblNum2.Text = TextBox4.Text

Else

lblNum2.Text = CInt(Int((13 * Rnd())))

End If

When the code is executed for the first time it always puts the same two
numbers in each of the labelboxes. Why is it doing this. I even used the
randomize function and it still does this.

Thanks for any help.
 
Steve said:
I would
like for them to be able to press the enter key on the keyboard and
the code for my button will be executed.

Set the AcceptButton property of the form to the name of the button.
One more question. I have two labelboxes. I have written code that
puts a random number into each labelbox. My code is below.
When the code is executed for the first time it always puts the same
two numbers in each of the labelboxes. Why is it doing this. I even
used the randomize function and it still does this.

Just put randomize separately before each call to Rnd:

Randomize
lblNum1.Text = CInt(Int((TextBox2.Text * Rnd())))
 
Thanks.

Leon Mayne said:
Set the AcceptButton property of the form to the name of the button.



Just put randomize separately before each call to Rnd:

Randomize
lblNum1.Text = CInt(Int((TextBox2.Text * Rnd())))
 
Back
Top