kirby@wallaceinfo.com
|
| Posted: 02/19/2002, 11:04 AM |
|
I noticed that CodeCharge uses IsEmpty() to determine whether required fields have been entered or not.
However, IsEmpty() only tells if a variable as been initialized with a value or not. Thus, [Dim fldName: fldNAME = "" ] perfectly satisfies "IsEmpty()"
I'm sure I must be missing something, because in my short exposure to CodeCharge, it seems that CodeCharge always Dims vars and assigns an initial value of "" (blank). This means that the "required" field property will NEVER work. In fact, I have users who frequently subvert it by entering a SPACE. I'm sure CodeCharge didn't go out the door with that big of a bug, so I must be missing something - I just dunno what.
As a workaround, I wrote a replacement function for IsEmpty() which I put in my COMMON.ASP (via Global Functions). My IsEmpty() truly checks for empty, and so far seems to be happy. This is a FAR REACHING CHANGE because this will replace IsEmpty()'s functionality SITE-WIDE. But, given that in vbscript ALL variables are variants, I don't think there's any danger of a "Err 13 - Type Mismatch" in the code below.
Here's the function that I put in my MODULES->GLOBAL FUNCTIONS:
Function IsEmpty( vVar )
if len("" & trim(vVar)) = 0 Then
IsEmpty = True
else
IsEmpty = False
end if
End Function
Comments?
|
|
|
 |
Andrew B
|
| Posted: 02/19/2002, 8:16 PM |
|
I don't exactly see what the problem here is. What are you trying to check for that requires you to look for 'empty' values? By empty I assume that you mean 'no alphanumeric chars'.
I have not run into an instance where this has been a problem. In the few cases where I something is actually *required* for *real*, i put in a bit of custom validation
---
if (IsEmail(fldCheckMed) = false) then
sFormErr = sFrmErr & "You screwd it up!<br>"
end if
A much much more serious problem imho is the overuse of 'nulls'. CC changes blank fields to the literal NULL, and then those get inserted. This seriously screws up SQL Server DBs that rely on string concatenation. I have to modify this behavior in modules->common->get generated code. Bummer.
|
|
|
 |
kirby
|
| Posted: 02/20/2002, 9:13 AM |
|
The problem is that fields marked "required" will allow blanks. If a field is marked as "required" I expected CodeCharge to generate code that will actually ensure that a value is entered. But a space, or even an empty string ("") does not register as "empty" to IsEmpty().
? IsEmpty(" ")
False
.....a SPACE is not empty. Well, ok I guess. Technically. I can live with this. Except I don't think a space really qualifies as a "required entry."
? IsEmpty("")
False
.....What? An empty string is not empty????? But wait, it get's wierder.
? IsEmpty(Null) ' or vbNull
False
..... Oh come now. Surely a NULL should be considered EMPTY! But that's not the wierdest. Check out the next one.
? IsEmpty(Nul) ' or vbEmpty
True
.....Finally! The truth of the matter! Variables that have been declared but not assigned (even assigned Null) are the only things IsEmpty() will consider to be actually empty.
CodeCharge-generated code routinely Dims and Declares all it's field variables like this:
Dim fldFieldName: fldFieldName = ""
So fldFieldName will NEVER be "empty" because it's assigned a value as soon as it's dim'd. So using IsEmpty() to validate a required entry is useless.
My only caveat here is that CodeBase, as a product, supports "Required Entry" attributes on fields, and it does this by using IsEmpty(). But I can't imagine that they shipped the product with this feature just plain not working - it's too big of a bug to have been overlooked during QA. I MUST be missing something.
I already fixed the problem as described in my original post. I just want to know if this is actually an oversight on the part of CodeCharge, or if I'm just missing something.
What I suspect is that these fields are initially dim'd with empty strings, and are not "empty" to begin with, but later on when values are loaded from the data source (before they are edited), empty fields are assigned "vbEmpty" by GetParam(). If no entry is made, those fields will still contain the vbEmpty value that GetParam() assigned to them.
|
|
|
 |
Andrew B
|
| Posted: 02/20/2002, 7:11 PM |
|
I see more what you mean now. I don't usually worry about virtual 'empty' strings. If someone wants to put in a space, I'll let them. Usually I write a custom 'isValidLogin' type of function for those few, and do the custom checking for the others (like your new IsEmpty) by hand. I don't like modifying CC's code. I am forced to, however, in the case of toSql() since it is used so often.
Making custom validation stuff is pretty easy, so I usually don't fret it too much.
|
|
|
 |
|