[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1192
  • Last Modified:

set numeric variables to null???

how can i set a non-string variable to null and not zero?

like

dim myInt as integer
response.write(myInt)

...the above will display a "0"...the number zero

i need it to work like a string
dim myStr as string
response.write(myStr)

would render nothing


i understand why never letting a numeric var be null is ...overall ...a good thing...

but i'm working on an app that works with another app written in PowerBuilder...and those developers use null numerics a lot in the code and need a way to continue using null numerics
0
samtran0331
Asked:
samtran0331
2 Solutions
 
Carl TawnSystems and Integration DeveloperCommented:
You can't set a value type to null. One option would be use objects and cast them to the relevant numeric when necessary:

    object obj = 10;
    int i = (int)obj;

    obj = null;
0
 
bsdotnetCommented:
try, (do not declare myInt as Integer)
Dim myInt
myInt = DBNull.Value

Response.Write(myInt)
Response.Write(IsDBNull(myInt))
0
 
samtran0331Author Commented:
Thanks guys!
Such a tiny issue led to some really interesting testing...

It's been so long since I've done classic asp...and vb6....but I completely forgot that you can declare a var without giving it a type!
If I remember right...there was only one type..."Variant"....
and interestingly enough...

declaring a variable without a type in .Net doesn't make it a Variant or Object type....it just doesn't exist...in that doing a GetType on the var will throw a null object err...
HOWEVER, you can do different types of math (int, double, etc) or assign a string to the var back and forth and it will take the type of what you're tring to do...
declaring as an Object type...changed the rules somewhat and whatever was doing the automatic casting wouldn't cast the object ....

...so for our PowerBuilder developers....I think they can work with the untyped var in .Net.....
I think technically this falls into the category of "Bad Programming Practices" ...but necessary to keep the PowerBuilder app and the .Net app playing nice together against the same database.

Thanks again!
Sam
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now