PDA

View Full Version : Help with an if loop


rbonas
07-03-2003, 09:46 AM
the code below for some odd reason will not work. The values for the session variables are being assigned when a database is queried. but for some reason if the session variable is empty it goes onto the else portion of the statement


if Session ("aoemail1") = "" then
strTo = strTo &"here"
else
strTo= strTo & Session ("aoemail1")
strTo= strTo & ";"
end if


if Session ("aoemail2") = "" then
strTo = strTo &"here"
else
strTo= strTo & Session ("aoemail2")
strTo= strTo & ";"
end if


if Session ("supemail2") = "" then
strTo = strTo &"here"
else
strTo= strTo & Session ("supemail1")
strTo= strTo & ";"
end if


if Session ("supemail2") = "" then
strTo = strTo &"here"
else
strTo= strTo & Session ("supemail2")
end if

JoeS
07-03-2003, 10:22 AM
There are two ways that DB engines will typically tell you that there has been nothing entered in a given field.

One might be to return a pointer to a place in memory where a string would be placed if there were any characters in it; i.e., a 0-length string. This is what your code is checking for (if string = "").

The other would be to return an null string pointer (i.e., the string pointer=0), this is probably what is happening here. It is usually trapped with some mechanism like if "IsNul(string)", which means "if the address of 'string' is 0".

Be aware that in many databases, string fields are null until they are used the first time; after that they will be 0-length strings (because the space for the string has been allocated). This means that you need to check both cases *everywhere* you test for a blank string.