How to change VBA Constant from a textbox ?

shahshah

Registered User.
Local time
Today, 13:42
Joined
Feb 7, 2012
Messages
13
Hello,
i have a constant defined as public
like this: Public Const price As Integer = 5

is there a away to build a textbox in such Form and change this value, without going inside the module?

thx
 
is there a away to build a textbox in such Form and change this value, without going inside the module?
No! That's why it's called a Constant.

If you want to change it along the way then it simply shouldn't be a constant.
 
thanks for your replay, well, making it as a variable needs a lot of job because i used it for many calculations in my forms....
 
Create another variable. There's no restriction as to how many variables you can have.
 
okay but how to declare a variable as Global or public?i know how to make the constant public, but not a variable
 
Public Const price As Integer = 5
What you have already is a variable that is set at a fixed number of 5. If you take out Const and =5 you will have a global variable.

To elaborate:
Public myVariable As Integer
myVariable is a global Integer variable. A variable of type Number will always be initialised as 0.
 
so like this:
Public price As Integer ??
i did that, and then i typed the value under the declaration :
price = 5

i tried to change the value fom a textbox, then i get an error "outside procedure" ..
i don't understand this really..why we can declare a Const Global so easy, but the variable not so..
 
If you take out Const and =5 you will have a global variable

sorry, maybe i don't get what you mean by this..
 
You need to read up on some VBA basics. This is basic declarations issue.

The top section is for declarations, not for assigning values to variables.
 
No problem! Any assignment (for example initialisation) will need to be done in a Sub or a Function.
 

Users who are viewing this thread

Back
Top Bottom