| |

VerySource

 Forgot password?
 Register
Search
View: 675|Reply: 1

How to get the value of a string expression in VB

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-3-12 01:30:01
| Show all posts |Read mode
When encountering such problems, variable expressions are stored in the database, such as a + b + (c / d)

Now I know that the value of abcd is to get the string "1 + 2 + 5/2", but I don't know how to get the value of this expression string.
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-6-8 14:00:01
| Show all posts
Haha, I know, answer it yourself
Public Function Test(ByVal Expression As String) As Single
    On Error GoTo ErrorHandle
    Dim domSource As New DOMDocument
    Dim domStyleSheet As New DOMDocument
    Dim domResult As New DOMDocument
    Dim str As String

    str = "<?xml version='1.0' encoding='GB2312'?>" + vbCrLf
    str = str + "<xml>"
    str = str + "<expression>"
    str = str + Expression
    str = str + "</expression>"
    str = str + "</xml>"


    domSource.loadXML str
    str = "<?xml version='1.0' encoding='gb2312'?>" + vbCrLf
    str = str + "<xsl:stylesheet xmlns:xsl='http://www.w3.org/TR/WD-xsl'>"
    str = str + "<xsl:template match='/'>"
    str = str + "<Result>"
    str = str + "<xsl:eval language='vbscript'>Eval(me.text)</xsl:eval>"
    str = str + "</Result>"
    str = str + "</xsl:template>"
    str = str + "</xsl:stylesheet>"

    domStyleSheet.loadXML str


    domSource.transformNodeToObject domStyleSheet, domResult
    Test = domResult.Text
'Test = True
    Exit Function
ErrorHandle:
    Test = False
End Function
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list