0

I have a simple function that checks for text on a page. It first checks if a specific argument has a value, if so then executes code otherwise exits the function.

Example:

Function ck(reqA,reqB,optC)
IF optC <> "" Then
...run code
End If
End Function
ck(A,B,C)

The variable C points to a datatable that may or may not contain a value. The function works fine if C is the only value in the parameter. The problem I'm having is occasionally there is a need to have some form of static text concatenated to C like:

ck(A,B,"Jibberish " & C)

In the above example, optC always evaluates to TRUE because the string "Jibberish " is found. I'm looking for a way to ignore any string and only check if the actual variable C is empty before executing the code. Suggestions?

4
  • trim away the static text or, better yet, put it in its own parameter. Commented May 16, 2013 at 17:52
  • I've thought about trimming the static text, but this text is different for every situation. One could use ck(A,B,"Testing " & C) while the next use may require ck(A,B,"Testing, Testing, 1,2," & C). Is there any way to differentiate the contents of argument optC into string and variable? The additional parameter would be ideal, but it would require too many changes to existing calls to the function. Commented May 16, 2013 at 18:23
  • 1
    No. "foo " & C is concatenated to a single string, which is then assigned to optC. There is no way for a function to know how the value of one of its arguments came to pass. Commented May 16, 2013 at 18:45
  • made an edit to my answer, it's gonna be the only quick and automatic way i'm afraid.. Commented May 17, 2013 at 21:29

1 Answer 1

1

Either provide the static text in your receiving function like

Function ck(reqA,reqB,optC)
IF optC <> "" Then
 optC = "jibberish " & optC
End If
End Function
ck(A,B,C)

Or check if there is only the static text

Function ck(reqA,reqB,optC)
IF optC > "jibberish " Then
...run code
End If
End Function
ck(A,B,C)

If the 'static' text is also variable and you have no way of differentiating between the 2 parts of optC then there is no way you can do this without adapting your calling function, in that case just add a parameter so that you can check if one of thelm is empty

EDIT: i think your best option is to do a search and replace with a decent editor (Sublime Text or something like that) and search with a regular expression for ck(A,B,"xxxxxxxx" & C) and do a replace with ck(A,B,"xxxxxxxx|" & C) (replace the '" &' with '|" &', adapt the ck function by checking for the special character | (or any other) so you see if this is the last character or not and whether the function needs to be executed or not. Such a search and replace can be done over multiple scripts if necessary, success !!

Sign up to request clarification or add additional context in comments.

2 Comments

This function is used by many in many different scenarios. Sometimes a string will be included, other times just a variable. I was searching for a way to make it universal. My initial thought was to check if a "&" was found then extract whatever variable name before/after the & but I can't seem to get that to work as any comparison I do to the argument does not see the &, only the string combined with the variable value.
to be sure, please publish an example of how you call the function, the & is the operator for concateneting the two string together, is it not transwitteg to the function, only the concatenated string

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.