how to define a constant in VB?

  • Thread starter Thread starter serdar
  • Start date Start date
I get this error:

Compile error:
Constants not allowed as Public members of object modules

But this works:

Const PI = 3.14


...then what is the scope of above declaration, the module it is declared?
 
How about using Excel's built-in value

worksheetfunction.Pi

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
Serdar,

Const PI = 3.14 would have module-level visibility.

Public Const PI = 3.14 should work at the module level (above the subs and
functions). Regular module only. It works in XL 2002, English. It has
public visiblilty. Press F1 with the cursor on Const for help.
 
Using XL 2000 and public constant declaration causes error i defined
previously (above subs and functions).

Currently i dont need public scope so thats ok for me but i am curious why i
get that error message in XL 2000.
 
Hi Serdar,

What type of module are you trying to use the declaration in?

As Earl has already indicated, the declaration can only be used in a
standard module; it cannot be used in a sheet module, the ThisWorkbook
module or a userform code module and an attempt to use it in these modules
will produce the error you describe
 
thats ok it was a sheet module, sorry. thanks.

haber iletisinde þunlarý said:
Hi Serdar,

What type of module are you trying to use the declaration in?

As Earl has already indicated, the declaration can only be used in a
standard module; it cannot be used in a sheet module, the ThisWorkbook
module or a userform code module and an attempt to use it in these modules
will produce the error you describe
 
Back
Top