Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Is there a general way to check a string...

Is there a general way to check a string...

Scheduled Pinned Locked Moved Visual Basic
csharphelptutorialquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    viettho
    wrote on last edited by
    #1

    Is there a general way to check if an if statement is semantically correct in vb.net?. For example: Checking this: input string: Cost = 20 + Quantity - Discount and Cost = 49 or it could be: Cost = 20 * Quantity / Discount and Cost = 49 Note that Cost, Quantity, and Discount is an integer variables. Thanks in advance for your help. John

    D 1 Reply Last reply
    0
    • V viettho

      Is there a general way to check if an if statement is semantically correct in vb.net?. For example: Checking this: input string: Cost = 20 + Quantity - Discount and Cost = 49 or it could be: Cost = 20 * Quantity / Discount and Cost = 49 Note that Cost, Quantity, and Discount is an integer variables. Thanks in advance for your help. John

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      This question doesn't have an answer until it's put into the context of how it's being used... Are you saying that you want to check to see if this code is correct before being compiled? Or are you trying to parse this string and evalutate it? RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

      V 1 Reply Last reply
      0
      • D Dave Kreskowiak

        This question doesn't have an answer until it's put into the context of how it's being used... Are you saying that you want to check to see if this code is correct before being compiled? Or are you trying to parse this string and evalutate it? RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

        V Offline
        V Offline
        viettho
        wrote on last edited by
        #3

        Basically, the string is an if statement. For example: if Cost = 20 * Quantity / Discount and Cost = 49 then.... This is an input from user. And i'm trying to parse the string and check the "if" part only. John

        D 1 Reply Last reply
        0
        • V viettho

          Basically, the string is an if statement. For example: if Cost = 20 * Quantity / Discount and Cost = 49 then.... This is an input from user. And i'm trying to parse the string and check the "if" part only. John

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          Let me get this straight... This is your VB.NET code and your trying to do something like this:

          'Get some user input and put it in a variable. Then evaluate the expression...
          Dim strInput As String = "Cost = 20 * Quantity / Discount and Cost = 49"
          EvaluateUserExpression(strInput)
          .
          .
          .

          Public Function EvaluateUserExpression(ByVal strExpression As String) As Boolean
          If strExpression Then
          Return True
          Else
          Return False
          End If
          End Function

          Now, if I understand you correctly, the Cost, Quantity, and Discount terms are actual variables inside your code. Correct????? If this is true, then what you want to do can't be done using a simple if statement. You must parse up and validate the expression term-by-term and evaluate it along the way. You would ahve to check to see if the Cost/Quantity/Discount variables exist in your code, handle the equals signs and the operators yourself. You're looking for expression parsing techniques that, if covered in breif, are much too large to be taught over the forums. Google for 'VB mathematical expression parser' and you'll come up with tons links on various articles, techniques, some source code... RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups