text box calculation

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

    text box calculation

    Help,

    I am new to visual basic programming and I was wondering how to allow a
    textbox
    to do a calculation by pressing enter

    ie I want to type the following into a textbox 25.2 * 2 press enter on the
    keyboard
    and the textbox to display 50.4 Any Ideas ???????


  • Hal Rosser

    #2
    Re: text box calculation

    check out the keypress event
    you'll see "keyascii" is given as an arg
    keyascii is a number representing the ascii code of the key pressed.
    that should get you started

    "Amanda" <bonni@bonzai.c o.uk> wrote in message
    news:41f131ce_2 @mk-nntp-2.news.uk.tisca li.com...[color=blue]
    > Help,
    >
    > I am new to visual basic programming and I was wondering how to allow a
    > textbox
    > to do a calculation by pressing enter
    >
    > ie I want to type the following into a textbox 25.2 * 2 press enter on[/color]
    the[color=blue]
    > keyboard
    > and the textbox to display 50.4 Any Ideas ???????
    >
    >[/color]


    Comment

    • preben nielsen

      #3
      Re: text box calculation


      "Hal Rosser" <hmrosser@bells outh.net> skrev i en meddelelse
      news:dbmId.2865 0$SK6.5469@bign ews3.bellsouth. net...[color=blue]
      > check out the keypress event
      > you'll see "keyascii" is given as an arg
      > keyascii is a number representing the ascii code of the key
      > pressed.
      > that should get you started[/color]

      How should that solve his problem ? He's looking for Expression
      Evaluator code.


      --
      /\ preben nielsen
      \/\ prel@post.tele. dk


      Comment

      • Steve Gerrard

        #4
        Re: text box calculation


        "Amanda" <bonni@bonzai.c o.uk> wrote in message
        news:41f131ce_2 @mk-nntp-2.news.uk.tisca li.com...
        | Help,
        |
        | I am new to visual basic programming and I was wondering how to allow
        a
        | textbox
        | to do a calculation by pressing enter
        |
        | ie I want to type the following into a textbox 25.2 * 2 press enter
        on the
        | keyboard
        | and the textbox to display 50.4 Any Ideas ???????
        |
        |

        Do you have the Microsoft Script Control in your list of components? If
        so, then add one to your form. You then just need this simple event
        handler:

        Private Sub Text1_KeyPress( KeyAscii As Integer)
        If KeyAscii = vbKeyReturn Then
        On Error Resume Next
        Text1.Text = ScriptControl1. Eval(Text1.Text )
        End If
        End Sub

        You might want to make Text1 multi-line, so you don't get a beep when
        you press enter.


        Comment

        • Hal Rosser

          #5
          Re: text box calculation


          "preben nielsen" <prel@post.tele .dk> wrote in message
          news:41f203bd$0 $17517$edfadb0f @dread14.news.t ele.dk...[color=blue]
          >
          > "Hal Rosser" <hmrosser@bells outh.net> skrev i en meddelelse
          > news:dbmId.2865 0$SK6.5469@bign ews3.bellsouth. net...[color=green]
          > > check out the keypress event
          > > you'll see "keyascii" is given as an arg
          > > keyascii is a number representing the ascii code of the key
          > > pressed.
          > > that should get you started[/color]
          >
          > How should that solve his problem ? He's looking for Expression
          > Evaluator code.[/color]

          Did I say it would "solve his problem" ? no - I said it shouild get him
          started.
          I know its unheard of in some circles - but its a starting point for the OP
          to "Write Code" that will evaluate the expression.


          Comment

          • Martin

            #6
            Re: text box calculation

            Many thanks for the tip Steve, it works a dream.

            Regards

            Martin

            "Steve Gerrard" <mynamehere@com cast.net> wrote in message
            news:oeWdnYdvTt cSuW_cRVn-gw@comcast.com. ..[color=blue]
            >
            > "Amanda" <bonni@bonzai.c o.uk> wrote in message
            > news:41f131ce_2 @mk-nntp-2.news.uk.tisca li.com...
            > | Help,
            > |
            > | I am new to visual basic programming and I was wondering how to allow
            > a
            > | textbox
            > | to do a calculation by pressing enter
            > |
            > | ie I want to type the following into a textbox 25.2 * 2 press enter
            > on the
            > | keyboard
            > | and the textbox to display 50.4 Any Ideas ???????
            > |
            > |
            >
            > Do you have the Microsoft Script Control in your list of components? If
            > so, then add one to your form. You then just need this simple event
            > handler:
            >
            > Private Sub Text1_KeyPress( KeyAscii As Integer)
            > If KeyAscii = vbKeyReturn Then
            > On Error Resume Next
            > Text1.Text = ScriptControl1. Eval(Text1.Text )
            > End If
            > End Sub
            >
            > You might want to make Text1 multi-line, so you don't get a beep when
            > you press enter.
            >
            >[/color]


            Comment

            • Nicola

              #7
              Re: text box calculation

              Thank you Steve it works flawlessly.

              "Steve Gerrard" <mynamehere@com cast.net> wrote in message
              news:oeWdnYdvTt cSuW_cRVn-gw@comcast.com. ..[color=blue]
              >
              > "Amanda" <bonni@bonzai.c o.uk> wrote in message
              > news:41f131ce_2 @mk-nntp-2.news.uk.tisca li.com...
              > | Help,
              > |
              > | I am new to visual basic programming and I was wondering how to allow
              > a
              > | textbox
              > | to do a calculation by pressing enter
              > |
              > | ie I want to type the following into a textbox 25.2 * 2 press enter
              > on the
              > | keyboard
              > | and the textbox to display 50.4 Any Ideas ???????
              > |
              > |
              >
              > Do you have the Microsoft Script Control in your list of components? If
              > so, then add one to your form. You then just need this simple event
              > handler:
              >
              > Private Sub Text1_KeyPress( KeyAscii As Integer)
              > If KeyAscii = vbKeyReturn Then
              > On Error Resume Next
              > Text1.Text = ScriptControl1. Eval(Text1.Text )
              > End If
              > End Sub
              >
              > You might want to make Text1 multi-line, so you don't get a beep when
              > you press enter.
              >
              >[/color]


              Comment

              • Steve Gerrard

                #8
                Re: text box calculation


                "Nicola" <bonni@bonzai.c o.uk> wrote in message
                news:42139d4a_4 @mk-nntp-2.news.uk.tisca li.com...
                | Thank you Steve it works flawlessly.
                |

                You are welcome. Hopefully you weren't in a hurry :)


                Comment

                Working...