那个Eval问题又来了...... [英] That Eval Question Again...

查看:45
本文介绍了那个Eval问题又来了......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想我应该更好地解释一下(我对此很新,所以我可能不会以最好的方式提出问题)

通常情况下,人们会使用简单的代码:


如果x> y然后

什么

结束如果

....但我有一个存储在数据库列上的文本字符串,表示我想要评估的内容。换句话说,相反

知道我想提前查看x> y,我只知道我希望确定字符串是否存储在某些表格列中

在运行时是否正确。显然,eval命令/函数在其他语言中执行此操作,但不在VB中执行此操作。


也许其他人列出的某些引用可能有用 - 需要时间来阅读和消化。


如果有人能用非常简单的语言解释如何做到这一点,初学者可以理解,我会很感激。


Jeff



-

通过 http://www.teranews.com

解决方案



杰夫写道:


我想我应该更好地解释一下(我对此很新,所以我可能不会在最好的方式)


通常,人们会使用简单的代码:


如果x> y那么

某事

结束如果


...但是我有一个存储在数据库列上的文本字符串这代表了我想要评估的东西。换句话说,相反

知道我想提前查看x> y,我只知道我希望确定字符串是否存储在某些表格列中

在运行时是否正确。显然,eval命令/函数在其他语言中执行此操作,但不在VB中执行此操作。


也许其他人列出的某些引用可能有用 - 需要时间来阅读和消化。


如果有人能用非常简单的语言解释如何做到这一点,初学者可以理解,我会很感激。


Jeff



杰夫 - 这个列表中有一些非常好的建议,并且取决于表达式复杂性的
,其中一些可能更多

适合其他人(参见Herfried的名单)。这是我建议的那个。
暗示。如果你的表达式很简单,那么这很有效。

比较/数学表达式 - 但它确实需要一点点

的错误捕获和输入验证,因为它可以允许任意

执行jscript代码,因此如果您不小心输入,它可能会发生危险的事情。


要使用此建议:


1.创建一个名为evaluator.js的文件并添加以下代码:


// JScript源代码

类EvalClass

{

函数评估(表达式)

{

return eval (表达);

}

}


2.启动vs.net命令行并进入你所在的目录

保存了这个文件并输入以下命令:


jsc / target:library evaluator.js


这将在该目录中创建一个名为evaluator.dll的dll


3.创建一个简单的控制台e在VS.NET中的应用程序并向已编译的evaluateator.dll和microsoft.jscript.dll添加一个引用




4.以下是代码:


选项严格开启

选项明确开启


进口系统


模块模块1


Sub Main()

Dim s As String =" 5> 4"

Dim e As新的EvalClass()


如果是DirectCast(e.Evaluate(s),Boolean)那么

Console.ForegroundColor = ConsoleColor.DarkGreen

Console.WriteLine(It Worked!)

Else

Console.ForegroundColor = ConsoleColor.DarkRed

Console.WriteLine( 它失败了!

结束如果

结束子


结束模块

您应该收到一条绿色消息,上面写着It Worked!。就像我说的那样,在生产应用程序中,你需要确保输入到
EvalClass.Evaluate是安全的。如果你所做的只是简单的比较/数学运算,那么使用几行RegEx就可以轻松实现



那么简单吗?鉴于这些步骤,你至少可以用它来实验
:)


-

Tom Shelton




" Tom Shelton" < to*@mtogden.com在留言新闻中写道:11 ********************** @ i42g2000cwa.googlegr oups.com ...
< blockquote class =post_quotes>
杰夫 - 在这个列表中有一些非常好的建议,并且依赖于表达式复杂性的
,其中一些可能更多

适合其他人(参见Herfried的名单)。这是我建议的那个。
暗示。如果你的表达式很简单,那么这很有效。

比较/数学表达式 - 但它确实需要一点点

的错误捕获和输入验证,因为它可以允许任意

执行jscript代码,因此如果您不小心输入,它可能会发生危险的事情。



谢谢,但同样,我还处于学习的早期阶段。在其他语言中,这是一个简单的内置函数。

。特别令人沮丧的是,语言和脚本有很多小的变化,类似的,如果我在

互联网上找到可能的答案,我会花几分钟时间不是时候最终确定它不适用于我的Visual Web 2005快递版本




例如,我现在已经搜索了一下无处不在的简单部分

有关如何打开你提到的vs.net命令行的信息。我可以通过谷歌搜索提到的各种名称下找不到

..exe,也不会像FoxPro中那样在Visual Web GUI中找到任何类型的

命令行处理器。 br />

所以,有人可以解释一下如何打开vs.net命令行

这是Express版本中找不到的东西吗?


我理解其余部分。


谢谢


杰夫


-

通过 http:// www的免费Usenet帐户发布.teranews.com




Jeff写道:


" Tom Shelton" < to*@mtogden.com在留言新闻中写道:11 ********************** @ i42g2000cwa.googlegr oups.com ...
< blockquote class =post_quotes>
杰夫 - 在这个列表中有一些非常好的建议,并且依赖于表达式复杂性的
,其中一些可能更多

适合其他人(参见Herfried的名单)。这是我建议的那个。
暗示。如果你的表达式很简单,那么这很有效。

比较/数学表达式 - 但它确实需要一点点

的错误捕获和输入验证,因为它可以允许任意

执行jscript代码,因此如果您不小心输入,它可能会发生危险的事情。



谢谢,但同样,我还处于学习的早期阶段。在其他语言中,这是一个简单的内置函数。




虽然它不在VB.NET中 - 但它在JScript.NET中。我向您展示的内容

是一种将其暴露给您的VB.NET应用程序的技术。这是一个关于.NET的好东西之一。

。你可以使用用其他语言编写的类和

对象。


特别令人沮丧的是,有那么多小的

语言和脚本的变体和类似的,如果我在

互联网上找到可能的答案,我花费几分钟,如果不是几小时最终确定它不适用于

我的Visual Web 2005快递版。



嗯,Express Editions有一些限制。但是,在这种情况下

它应该没问题,因为你必须在命令上编译dll

line :)


例如,我现在几乎无处不在地搜索有关如何打开你提到的vs.net命令行的简单的

信息。我可以通过谷歌搜索提到的各种名称下找不到

.exe,也不会像FoxPro中那样在Visual Web GUI中找到任何类型的
命令行处理器。 />

所以,有人可以解释如何打开vs.net命令行

这是Express版本中找不到的东西吗?



我的猜测是否定的。它只是一个bat文件,它设置了一堆

环境变量,然后运行命令行。基本上,

提供.NET命令行环境。我很确定快递版本没有

这样的东西。因此,在您的情况下,您将要求
需要将框架目录添加到您的路径中,或者输入

完整路径到jsc.exe。示例:


C:\ C:\ WINDOWS \ Microsoftoft.NET\Framework\v2.0.50727\j sc.exe

/ target:library evaluator.js

-

Tom Shelton



I guess that I should have explained better (I''m stil new with this, so I may not be asking the questions in the best way)
Normally, one would use the simple code:

if x>y then
something
end if
....but I have a text string stored on a database column that represents something that I want to evaluate. In other words, instead
of knowing that I want to see if x>y in advance, I only know that I wish to determine whether the string stored in some table column
is true or not at run time. Apparently the eval command/function does this in other languages, but not in VB.

Perhaps some of the references that others have listed might work - it will take time to read and digest.

If anyone can explain how to do this in very simple language that a beginner can understand, I would appreciate it.

Jeff


--
Posted via a free Usenet account from http://www.teranews.com

解决方案


Jeff wrote:

I guess that I should have explained better (I''m stil new with this, so I may not be asking the questions in the best way)
Normally, one would use the simple code:

if x>y then
something
end if
...but I have a text string stored on a database column that represents something that I want to evaluate. In other words, instead
of knowing that I want to see if x>y in advance, I only know that I wish to determine whether the string stored in some table column
is true or not at run time. Apparently the eval command/function does this in other languages, but not in VB.

Perhaps some of the references that others have listed might work - it will take time to read and digest.

If anyone can explain how to do this in very simple language that a beginner can understand, I would appreciate it.

Jeff

Jeff - there are some very good suggestions in that list, and depending
on the complexity of the expressions, then some of them maybe more
suitable then others (see Herfried''s list). Here is the one I was
suggesting. This works really well if your expressions are simple
comparisons/mathmatical expressions - but it does require a little bit
of error trapping and input validation, because it can allow arbitrary
execution of jscript code, so it can potentially do dangerous things if
you aren''t carefull with your input.

To use this suggestion:

1. Create a file called evaluator.js and add the following code:

// JScript Source Code
class EvalClass
{
function Evaluate(expression)
{
return eval(expression);
}
}

2. start the vs.net command line and get to the directory where you
saved this file and type in the following command:

jsc /target:library evaluator.js

this will create a dll in that directory called evaluator.dll

3. Create a simple console application in VS.NET and add a reference
to the compiled evaluator.dll and microsoft.jscript.dll.

4. Here is the code:

Option Strict On
Option Explicit On

Imports System

Module Module1

Sub Main()
Dim s As String = "5>4"
Dim e As New EvalClass()

If DirectCast(e.Evaluate(s), Boolean) Then
Console.ForegroundColor = ConsoleColor.DarkGreen
Console.WriteLine("It Worked!")
Else
Console.ForegroundColor = ConsoleColor.DarkRed
Console.WriteLine("It failed!")
End If
End Sub

End Module
You should get a green message that says "It Worked!". Like I said, in
the production application, you''ll want to make sure that the input to
EvalClass.Evaluate is safe. If all your doing is simple
comparisons/mathmatical operations, then this is relatively easy to
accomplish with a couple lines of RegEx.

Is that simple enough? Given these steps you can at least experiment
with it :)

--
Tom Shelton



"Tom Shelton" <to*@mtogden.comwrote in message news:11**********************@i42g2000cwa.googlegr oups.com...

Jeff - there are some very good suggestions in that list, and depending
on the complexity of the expressions, then some of them maybe more
suitable then others (see Herfried''s list). Here is the one I was
suggesting. This works really well if your expressions are simple
comparisons/mathmatical expressions - but it does require a little bit
of error trapping and input validation, because it can allow arbitrary
execution of jscript code, so it can potentially do dangerous things if
you aren''t carefull with your input.

Thanks, but again, I''m still in the early stages of learning. In other languages, this is
a simple built-in function. What is particularly frustrating is that there are so many small
variations of languages and scripts and similar, that if I find a possible answer on the
internet, I spend minutes if not hours eventually determining that it isn''t applicable to
my Visual Web 2005 express edition.

For example, I''ve now searched just about everywhere for the simple piece of
information about how to open the vs.net command line that you mentioned. I can find no
..exe anywhere under various names mentioned through a google search, nor any type of
command line processor within the Visual Web GUI like in FoxPro.

So, can someone explain simply how to "open the vs.net command line"
Is this something not found in the Express version?

I understand the rest.

Thanks

Jeff

--
Posted via a free Usenet account from http://www.teranews.com



Jeff wrote:

"Tom Shelton" <to*@mtogden.comwrote in message news:11**********************@i42g2000cwa.googlegr oups.com...

Jeff - there are some very good suggestions in that list, and depending
on the complexity of the expressions, then some of them maybe more
suitable then others (see Herfried''s list). Here is the one I was
suggesting. This works really well if your expressions are simple
comparisons/mathmatical expressions - but it does require a little bit
of error trapping and input validation, because it can allow arbitrary
execution of jscript code, so it can potentially do dangerous things if
you aren''t carefull with your input.


Thanks, but again, I''m still in the early stages of learning. In other languages, this is
a simple built-in function.

While it''s not in VB.NET - it is in JScript.NET. What I am showing you
is a technique for exposing that to your VB.NET application. This is
one of the great things about .NET. You are able to use classes and
object written in other languages.

What is particularly frustrating is that there are so many small
variations of languages and scripts and similar, that if I find a possible answer on the
internet, I spend minutes if not hours eventually determining that it isn''t applicable to
my Visual Web 2005 express edition.

Well, there are limitations on the Express Editions. But, in this case
it should be ok, because you have to compile the dll on the command
line :)

For example, I''ve now searched just about everywhere for the simple piece of
information about how to open the vs.net command line that you mentioned. I can find no
.exe anywhere under various names mentioned through a google search, nor any type of
command line processor within the Visual Web GUI like in FoxPro.

So, can someone explain simply how to "open the vs.net command line"
Is this something not found in the Express version?

My guess is no. It is simply a bat file that sets a bunch of
environment variables and then runs the command line. Basically,
providing a .NET command line environment. I''m pretty sure there is no
such thing with the express editions. So, in your case you will either
need to add the framework directory to your path or type in the
complete path to the jsc.exe. Example:

C:\C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\j sc.exe
/target:library evaluator.js

--
Tom Shelton


这篇关于那个Eval问题又来了......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆