Results 1 to 5 of 5

Thread: [RESOLVED] Variable Declaration Question

  1. #1

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    My Mustang GT
    Posts
    4,562

    Resolved [RESOLVED] Variable Declaration Question

    May I ask exactly what this means: bool? bSendEmail ?

    I was getting an error from the compiler complaining of my use of an unassigned local variable if I just declared it as bool bSendEmail. I could not find where it wasn't being assigned. I was not sure if I wanted to initialize it to true or to false. The above made the compiler happy, but confused me.

    Thanks.
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Variable Declaration Question

    bool? means it's a nullable boolean... as opposed to bool which isn't nullable.
    In VB it would be
    Dim ridesBusToWork3 As Nullable(Of Boolean)

    More info -
    C# - http://msdn.microsoft.com/en-us/library/1t3y8s4s.aspx
    VB - http://msdn.microsoft.com/en-us/library/ms235245.aspx

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    My Mustang GT
    Posts
    4,562

    Re: Variable Declaration Question

    Cool (and thanks for the quick reply).

    So the compiler has intialized it to null for me, and that is why it doesn't complain anymore that it's unassigned?
    A Nullable<bool> can be assigned the values true false, or null
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Variable Declaration Question

    yup... because now null becomes a valid "value" for it.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    710

    Re: [RESOLVED] Variable Declaration Question

    A sidenote - in VB you can also use the '?' syntax:
    Dim b As Boolean?
    or
    Dim b? As Boolean
    or
    Dim b As Nullable(Of Boolean)
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width