Learning PB is going well, but I ran into an error today I don't understand. I'll try to explain clearly enough so I don't have to post code:
I have my main source .pb file in which I have enumerated some menu items for my main (and only) window. The order of coding in this file is from top to bottom: 1. Define a couple of Global variables, 2. XInclude all other source code .pb files containing procedures, 3. Enumerate menu item constants, 4. Create and open my Main window, and 5. Event Loop.
I hand off some events to be processed by code in a Procedure contained in one of the XIncluded files. All works well until I try to change the state (Enable/Disable) menu items by referencing their assigned constants, at which time I get a "Constant not found" error during compilation. This operation is contained in an XIncluded Procedure source file. If I change the reference from the #Constant name to the constant numerical value all works as intended. Are constants defined/enumerated in the main source code file not global and available to procedures or do I have a code ordering problem?
Any help greatly appreciated.
Best,
john
Are enumerated constants Global?
-
jwrjrjwrjr
- User

- Posts: 14
- Joined: Sat May 23, 2015 3:12 am
- Location: The other Georgia
- netmaestro
- PureBasic Bullfrog

- Posts: 8453
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: Are enumerated constants Global?
Not everything in Purebasic is top-down sequential but a lot of important things are. For example, you can put a label anywhere in your code and reference it from anywhere in your code and there will be no problem. However, not so for procedures and not so for constants. It sounds like an include file is needing a constant that is declared later in your main code, which won't work if the included file gets included before the constants are declared. You could consider a couple of options, one being do all your declares in an include that gets called first, another is to do your constant declarations and then include the file. It doesn't have to be at the very top of the code.
BERESHEIT
-
jwrjrjwrjr
- User

- Posts: 14
- Joined: Sat May 23, 2015 3:12 am
- Location: The other Georgia
Re: Are enumerated constants Global?
Netmaestro,
You are awake at this hour (though I don't really know where you are.)
After looking at my code some more, I was actually hoping it was an ordering problem. Now with your explanation, I'll give a shot at some re-arranging.
Thanks (yet again) for your help,
John
You are awake at this hour (though I don't really know where you are.)
After looking at my code some more, I was actually hoping it was an ordering problem. Now with your explanation, I'll give a shot at some re-arranging.
Thanks (yet again) for your help,
John