How to add a constant for For Next startValue

How to add a constant for For Next startValue.
If I define a constant in the App.Open Event (NOT using the IDE, so it’s not a type Number, but in the App.open Event)

Const WdSndKc As Integer = 6 

I then try to use it in a FOR statement

For i = WdSndKc to ImgKc

I then get a does not exist error in a for statement
“ArManip.ArryFill, line 81
This item does not exist
For i = WdSndKc to ImgKc”

What is wrong?

I thought to stop the “does not exist” by adding Public but that just creates a syntax error. Not sure about that.

So What is wrong with using a Constant defined as Integer in a For statement?

If you create a Constant inside App.Open then its scope will only be inside App.Open and you wont be able to use it anywhere else.

If you want to add a program wide Constant, right click App and select Constant from the drop down and add it there.

I still get a

[quote]ArManip.ArryFill, line 84
This item does not exist
if i = WdSndKc then[/quote]

You need to reference it with App.WdSndKc where ever you use it.

If I right click App and select Constant, create WdSndKc = 6

I have to do this:

For i As Integer = app.WdSndKc to 15 // some code next

Is that correct?

Edit: Thank you Julian, you answered before I posted :slight_smile:

Yes

If you dont want to have to use App. everywhere you can add the constant to a module then you will be able to use it by WdSndKc or Module1.WdSndKc

Thanks, Julian. The things I didn’t try were adding App to the mentions, and adding it as a constant in a Module.
It’s good to know type number works.
I suspected incorrectly that type number wouldn’t work because of this discussion yesterday that mentions another discussion.
expected-int32-but-got-enum-mnstuff-ck

I also thought it’d work since we now get in Desktop Project files kFileQuitShortcut as a constant. However, it is never mentioned.