将等式符号发送到If语句

基本上,我有一个函数在VBA中,你发送一些参数,然后它做一些math给它一个值。 我发送的一个参数是一个"<"或一个">" ,后来在if语句中使用

 if x > y 

要么

 if x < y 

取决于我发送。

目前,我把它作为一个string,标记为“约束”,并进行以下操作:

 if constraint = ">" then if x > y *code* end if elseif constraint = "<" then if x < y *code* end if end if 

如果这是有道理的。

这与我有的其他代码变得复杂。 有什么办法可以把这个变成一个if语句?

看起来,在这两种情况下,你都需要constraint是一个特定的string, x constraint y运行代码否则什么都不做。 因此:

 If constraint = ">" And x > y Then 'code ElseIf constraint = "<" And x < y Then 'code End If