access vba - Null values for variables in VBA -


how define null string, date or integer in vba?

i need able assign null value fields records when data incomplete or irrelevant, if declare variable string, date or integer, errors when trying assign null value.

is solution use variant? if so, point of other datatypes in vba?

dim x variant x = null 

only variant data type can hold value null.

a variant special data type can contain kind of data [...] variant can contain special values empty, error, nothing, , null.

the "point" of other data types precisely cannot contain ol' kind of data. has 2 advantages can think of:

  • it's more difficult programmer assign data of unintended type variable mistake, since detected @ compile time. can prevent bugs , make things clearer , next person maintaining code.
  • narrow data types save storage space. putting integers in variant (16 bytes) takes way more memory putting them in int (2 bytes). becomes significant if have large arrays.

of course, variants have place, other threads on site discuss.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -