How can I put an operator into a variable?

I have a config document that holds a field name, an operator and a string/value. For instance:fieldname: LName

Operator: =

String/Value: Smith

I have a script where I gather those values, then check another document to see if that document’s LName field = “Smith” and I can’t get it to recognize the operator for what it is when I try to build the conditional statement. I did get it to work a few times, but not consistently. Has anyone done this before? Here is one of the variations I was having limited success with:

fieldNm = LName

operator1 = “=”

UName = “Smith”

If doc.GetItemValue(fieldNm)(0) & Asc(operator1) & UName Then

I get a type mismatch when I do get an error. Any ideas are appreciated. If I can do it this way it will same me many many many lines of coding. Thx

Subject: How can I put an operator into a variable?

You’re building the string correctly, but you need to Execute it to make it evaluate:

success = Execute(doc.GetItemValue(fieldNm)(0) & Asc(operator1) & UName)

If success Then

Subject: RE: How can I put an operator into a variable?

Thanks! I gave it a try and I’m getting this error:$Execute$+1:Unexpected: 60;Expected:Statement

60 is the asci-value of <> and I understand what it’s saying, but I can’t quite get it to work. I’ve tried it with quotes and without and various other versions, but always get a variation on the above error.

I tried using =, rather than <> and got a variant does not contain an object error. However, the only difference was using = rather than <> and I really need to be able to use either depending on what the user enters.

Any other ideas on how to get it to work? I’m getting more and more confused! I know I’m close and it’s driving my crazy!

Thanks much!

Subject: RE: How can I put an operator into a variable?

If you want to use Execute for this (i.e. you are interpreting the comparison as LotusScript) then there are several things you need to do:

You have to arrange for the string that you pass to Execute to contain an End statement which returns your result. Execute executes statements, not expressions.

Any literals need to be expressed using a syntax that the LotusScript language accepts. E.g. rather than Smith, your expression will have to include the characters “Smith” (in quotes) or use other quote characters {} or || so that LotusScript knows you aren’t referring to a variable named Smith, but the string “Smith”.

If you have a string literal that contains quotes (or whatever character you’re using as a close quote) then you must “escape” those quotes, e.g. Robert “Big Bob” Morlane would become “Robert ““Big Bob”” Morlane”.

Then, assuming your field is a string, you would have something like:

retval = Execute (" End " + Quote(doc.GetItemValue(FieldNM)(0)) & Operator1 & Quote(UName)

Where Quote is a custom function that uses Replace to change a string to a quoted literal.

Function Quote(Byval x As String) As String

Quote = {"} & Replace(x, {"}, {""}) & {"}

End Function

However, I suspect that what you’re doing here is going to be very inefficient. If you’re searching for documents that meet certain user-specified conditions, and if you have multiple conditions, then rather than loading each document into memory and calling Execute multiple times for each to see whether it meets the criteria, you will be much better off creating one formula language expression or full-text query that incorporates all your conditions, and then use that with the Search or FTSearch method to make the system find just the ones you want, with a single call. You will of course still need to put quotes around your string literals, though the exact formatting is different with these different techniques.

Subject: RE: How can I put an operator into a variable?

Thanks for the help! I’ll give it a try later today or tomorrow and post my success or failure. What I’m trying to accomplish is to allow users to enter info into a configuration-type document. Using the conditions they enter I will be looking at the fields on a single document to determine if those conditions are true for that one document. Depending on whether they are true or not determines where the document routes. So I won’t be doing any searches and I don’t think performance will take a hit. Remains to be seen!

Thanks so much!

Subject: RE: How can I put an operator into a variable?

This little test works . . . just compares one to one and prints true if the operands are equal.

dgg

Const OPERATOR = "="

Dim blnRetVal As Boolean

Dim strVal As String



strVal$ = {

	Option Declare

	Sub Initialize()

		Dim intRC as Integer

		If Not(1 } & OPERATOR & { 1) Then

			intRC% = False

		Else 

			intRC% = True

		End If

		End intRC%

	End Sub

}

’ Msgbox strVal$, , “DEBUG . . .”

blnRetVal = Execute(strVal$)

If blnRetVal Then

	Print "The comparison returned true!"

Else

	Print "The comparison returned false!"

End If

Subject: RE: How can I put an operator into a variable?

Okay, I see where it’s choking. Try this:

success = False

testString$ = {If “} & doc.GetItemValue(fieldNm)(0) & {'} & Asc(operator1) & {”} & UName & {" Then success = True}

Execute(testString)

You may have to play with quotation marks within the Execute string.

Subject: RE: How can I put an operator into a variable?

Thanks! I haven’t had a chance to get back to this but hope to later today. I’ll give it a try! I really appreciate the help!