Quantcast
Channel: SCN : All Content - All Communities
Viewing all articles
Browse latest Browse all 3280

Evaluating a DW column's ValidationMsg Correctly

$
0
0

In my application I replace the Messagebox with a custom HTML Messagebox object, so that it can have larger fonts and thus be more readable, use boldface for emphasis, etc. (It's my object, which I originally paid someone to develop in C++, then enhanced further myself. A slightly older version of it is available for free at www.html-messagebox.com - I plan to update it soon when I get some time.)

 

So one of the things I wanted to do with that is replace PB's validation messages, which show up in a messagebox with the title "Data Entry Error" (which I also don't like).

 

To do that, I have an inherited DW control, u_dw, with an ItemError event that evaluates the ValidationMsg for the row and column, then posts my Messagebox replacement showing it. However, since a ValidationMsg can include complex expressions (mine often do) it turned out it was really quite complicated to evaluate them properly and get the right message. Here is the code which I think I have finally settled on, which seems to work whether single or double quotes (or some combination) is used in the expression (which is what complicated things).

 

// Evaluate and return the validation message for the passed-in column name and row.

String validation, msg
Boolean lbRemovedQuotes

validation = Trim(this.Describe(asColName + ".ValidationMsg"))

// The following sometimes needed, because some expressions come in with double quotes added.
// But don't use gf_trim_quotes, which also trims single quotes, which we need to keep, e.g. for validation
//    messages that are just single quoted strings.
lbRemovedQuotes = gf_trim_double_quotes(validation)

// Escape tildes, single and double quotes in the message, things mess up otherwise!
// However, if we reomoved double quotes around the message, any double quotes within it will already be
//    escaped, sose need to first hide them, then put them back in.
if lbRemovedQuotes then
gf_replace_all(validation, '~~"', "XYZX")
end if
gf_replace_all(validation, "~~", "~~~~") // tildes
gf_replace_all(validation, "'", "~~'") // single quotes
gf_replace_all(validation, '"', '~~"') // double quotes
if lbRemovedQuotes then
gf_replace_all(validation, "XYZX", '~~"')
end if

// The validation string it might be an expression, have to evaluate it
msg = this.Describe("Evaluate('" + validation + "', " + String(llRow) + ")")

return msg

Note: my gf_trim_double_quotes function is to remove leading and trailing double quotes from strings; it returns TRUE if it did so, FALSE if no such change was needed because the string wasn't surrounded with double quotes.

 

I would welcome any comments on this code!


Viewing all articles
Browse latest Browse all 3280

Trending Articles