set numeric variables to null???

Posted on 2006-05-16
Last Modified: 2007-12-19
how can i set a non-string variable to null and not zero?


dim myInt as integer

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

i need it to work like a string
dim myStr as string

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
Question by:samtran0331
    LVL 52

    Assisted Solution

    by:Carl Tawn
    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;
    LVL 12

    Accepted Solution

    try, (do not declare myInt as Integer)
    Dim myInt
    myInt = DBNull.Value

    LVL 37

    Author Comment

    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 just doesn't 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 .... 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!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
    Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now