Results 1 to 4 of 4

Thread: textbox calculate expression

  1. #1
    j0zef is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    May 2012
    Posts
    3
    Reputation
    0

    textbox calculate expression

    Hello,

    I have a question,

    I want fill in a textbox for example 25 + 25

    and in a label you can find the result 50

    can anyone help me?

  2. #2
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    11,346
    Reputation
    1543

  3. #3
    Solitaire is offline VB.NET Forum Miyagee
    .NET Framework
    .NET 4.0
    Join Date
    Jun 2004
    Location
    New York
    Posts
    418
    Reputation
    162
    Here's one solution:

    Dim op1 As Integer = 25
    Dim op2 As Integer = 25
    Dim ans As Integer = op1 + op2
    Textbox1.Text = op1 & " + " & op2
    Label1.Text = ans.ToString()

  4. #4
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    11,346
    Reputation
    1543
    Quote Originally Posted by Solitaire View Post
    Here's one solution:

    Dim op1 As Integer = 25
    Dim op2 As Integer = 25
    Dim ans As Integer = op1 + op2
    Textbox1.Text = op1 & " + " & op2
    Label1.Text = ans.ToString()
    I think the idea was that the user would type the expression into the TextBox and the app would parse it and display the result.

    If all you ever want to do is add two numbers then it's easy, but it becomes more and more difficult as you want to be able to use additional operators and longer expressions. Some the examples in the Google search I linked to will allow you to parse arbitrarily complex mathematical expressions.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking