PDA

Click to See Complete Forum and Search --> : Using InputBox to define a constant


AidanEnos
Nov 14th, 1999, 11:43 AM
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

pMAHESH
Nov 14th, 1999, 01:23 PM
you cannot assign a value to a constant using an input box .

MartinLiss
Nov 14th, 1999, 09:32 PM
More specifically, you can't assign a value to a constant in any way at run time.

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

Yonatan
Nov 14th, 1999, 09:41 PM
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: RZvika@netvision.net.il
ICQ: 19552879 (http://www.icq.com/19552879)
AIM: RYoni69

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

Yonatan
Nov 14th, 1999, 09:49 PM
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: RZvika@netvision.net.il
ICQ: 19552879 (http://www.icq.com/19552879)
AIM: RYoni69