Results 1 to 5 of 5

Thread: Using InputBox to define a constant

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 1999
    Location
    Toronto, Ontario, Canada
    Posts
    8

    Post

    I'm having troule here is my string...

    Const Monday = InputBox("Enter Monday's Date", "Enter Monday's Date mm/dd/yy", 1 / 1 / 1980)

    This is in MS Excel 97 SR-2. It's in the Declarations section... it's telling me there is a compile error, Constant Expression required.

    I have no idea what it means!

    AidanEnos

  2. #2
    New Member
    Join Date
    Nov 1999
    Location
    INDIA
    Posts
    2

    Post

    you cannot assign a value to a constant using an input box .

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    More specifically, you can't assign a value to a constant in any way at run time.

    ------------------
    Marty

  4. #4
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892

    Post

    Try this:

    Dim m_vMonday

    Sub InputBoxToMonday(Prompt, Optional Title, Optional Default, Optional XPos, Optional YPos, Optional HelpFile, Optional Context)
    m_vMonday = InputBox(Prompt, Title, Default, XPos, YPos, HelpFile, Context)
    End Sub

    Property Get Monday()
    Monday = m_vMonday
    End Property

    ' Following from any event:
    ' Instead of this:

    ' Const Monday = InputBox("Enter Monday's Date", "Enter Monday's Date mm/dd/yy", 1 / 1 / 1980)
    ' Use this:
    Call InputBoxToMonday("Enter Monday's Date", "Enter Monday's Date mm/dd/yy", 1 / 1 / 1980)


    Using this code, Monday is a "constant" which can be "set" using InputBoxToMonday.

    ------------------
    Yonatan
    Teenage Programmer
    E-Mail: [email protected]
    ICQ: 19552879
    AIM: RYoni69


    [This message has been edited by Yonatan (edited 11-15-1999).]

  5. #5
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892

    Post

    Just another comment:

    1 / 1 / 1980 is not a date, it is a fraction: 1 divided by (1 divided by 1980) which is equivelant to 1 divided by 1980.

    If you want a date, use either:

    "1 / 1 / 1980" ' In any way you want

    Or:

    #1/1/80# ' In Control-Panel (Regional Settings) defined format

    Or:

    DateSerial(1980, 1, 1) ' In Year, Month, Day format

    ------------------
    Yonatan
    Teenage Programmer
    E-Mail: [email protected]
    ICQ: 19552879
    AIM: RYoni69

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