can you tell us what you want to do? Do you just want to have automatically numbered chunks of material?
Right now, you are setting the counter after defining the environment, i think this should give the first error if you would use the counter in your newly defined environment.
Instead of your label/ref mechanism (which is wrong here), you should use \refstepcounter.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Dear Johannes, thank you for your reply and apologies for not replying sooner, but I did not see the reply on my previous checks to the page. Shame on me!
What I want to achieve is to get a collection of definitions and equations gathered under the Specification heading and references of the form Specification x when I refer to specifications in the main text and Specification A.y when I refer to specifications in the Appendix.
My definition works correctly for those in the text (actually the \refstepcounter causes some compilation error), but for those in the Appendix I get that the heading is Specification Appendix A.y. and also the reference in text reads Specification Appendix A.y.
By the way, I am compiling under the Elsevier article style
Thank you very much. I would have never imagined of anything such that.
The only problem is that now I have a conflict between the hyperref package required by this and the xr-hyperref one that the elsevier style seems to prefer.
However this just gives me a few warnings, so I think I can live with that.