enter key

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steve

    #1

    enter key

    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.Check ed Then

    Randomize(lblNu m1.Text = CInt(Int((TextB ox2.Text * Rnd()))))

    ElseIf CheckBox1.Check ed Then

    lblNum1.Text = TextBox1.Text

    Else

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

    End If

    If CheckBox3.Check ed Then

    lblNum2.Text = CInt(Int((TextB ox3.Text * Rnd())))

    ElseIf CheckBox4.Check ed 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.


  • Leon Mayne [MVP]

    #2
    Re: enter key

    Steve wrote:[color=blue]
    > 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.[/color]

    Set the AcceptButton property of the form to the name of the button.
    [color=blue]
    > One more question. I have two labelboxes. I have written code that
    > puts a random number into each labelbox. My code is below.[/color]
    <snip>[color=blue]
    > 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.[/color]

    Just put randomize separately before each call to Rnd:

    Randomize
    lblNum1.Text = CInt(Int((TextB ox2.Text * Rnd())))


    Comment

    • Steve

      #3
      Re: enter key

      Thanks.

      "Leon Mayne [MVP]" <l.rmv.mayne@ue a.ac.uk> wrote in message
      news:%23UMKN2z5 EHA.1452@TK2MSF TNGP11.phx.gbl. ..[color=blue]
      > Steve wrote:[color=green]
      >> 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.[/color]
      >
      > Set the AcceptButton property of the form to the name of the button.
      >[color=green]
      >> One more question. I have two labelboxes. I have written code that
      >> puts a random number into each labelbox. My code is below.[/color]
      > <snip>[color=green]
      >> 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.[/color]
      >
      > Just put randomize separately before each call to Rnd:
      >
      > Randomize
      > lblNum1.Text = CInt(Int((TextB ox2.Text * Rnd())))
      >
      >[/color]


      Comment

      Working...