Results 1 to 4 of 4

Thread: What is the Const command?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Leeds, UK
    Posts
    287

    Post

    Hi,

    I'm learning API and I offten see the Const command but I don't have a clue what it is and does. Could you please tell me?

    Thanks

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    It means Constant, a Variable who's value doesn't change.

    When using things like Window Styles it's easier to code WM_BORDER, or WM_DLGFRAME, rather than trying to remember the actual values.

    VB uses a whole host of Constants, ie.

    WindowState = vbMinimized

    vbMinimized is a Constant with a value always of 1

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]


  3. #3
    Dreamlax
    Guest
    A variable must change, hence it's name... if it were constant, it wouldn't be a variable!

    A better explanation would be that a constant has a particular value which doesn't change.

  4. #4
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819
    In the declarations section of a Module, you can declare a const as public or private. You can also use Dim, but that's not recommended.

    You must use Dim if you declare a const in a procedure. I don't think you can have a public const in a form or a class module.

    Also, you can declare the data type of the const

    All these are legal in a module but you can only have one of them since the name is the same.

    VB Code:
    1. Public Const MY_CONSTANT As Long = 1
    2. Public Const MY_CONSTANT = 1
    3. Private Const MY_CONSTANT As Long = 1
    4. Private Const MY_CONSTANT = 1
    5. Dim Const MY_CONSTANT =1

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