Click to See Complete Forum and Search --> : Variable assigned hard space?


Nicodemas
09-25-2003, 05:26 AM
I have a value that is assigned to a variable called intAlternateID. The value that is assigned is the value that was submitted from the form on the same page. However, in the beginning of the page, I have a test condition that asks if the variable is null or not so as to inform the page to process an update statement or not.

When I use:

If Not IsNull(intAlternateID) Then ...

...
End If

The statement executes, even though the form was never submitted! Instead, it is assigning the variable a hard space as a value.

Why?


Sample code:



Dim intTopUnit, intPOC, intAlternateID, intSubUnit

intTopUnit = Request.Querystring("topunit") '// The group ID that the alternate will maintain.
intPOC = Request.Querystring("poc") '// The ID number of the alternate.
intAlternateID = Request("intAlternateID") '// The ID number of the alternate passed through the form below.
intSubUnit = Request("select_subunit") '// The ID number of the subunit the users submits through the form below.

'//-------------------------------------------------------------------
'//
'// Why does the logic insert a blank space into intAlternateID?
'//
'// For the time being, allow the code to execute backwards.
'//
'//-------------------------------------------------------------------

If Not IsNull(intAlternateID) Then

strSQL = "UPDATE tblAlternate SET intSubAlternateGroup = "& intSubUnit &" WHERE intPOC = "& intAlternateID &" AND intGroupLabel = "& intTopUnit
ysnSuccess = adlExecuteSQL(strDB,strSQL,NULL)

If ysnSuccess = TRUE Then
Response.Write "<H3>You may close this window</H3>"
End If

End If

rdoekes
09-25-2003, 07:20 AM
isNull is used primarily for values coming in from a database, since null is a usuable value for a lot of databases.

variables of the type variant (which are all variables initially in VBscript), will never have the value null unless you explicitly assign the value null to it:
intAlternateID = Null

You need to test for IsEmpty or Len(intAlternateID) = 0, where I personally prefer Len() = 0

Hope this helps,

-Rogier Doekes

Nicodemas
09-25-2003, 07:48 AM
The Len = 0 works!

Thanks, my friend.