#Include Statements and How They Work
Keywords: #include
Question:
I am trying to put some '#include' stmts in my winbatch script, which is actually a dialog box, and ran into some problems.My script looks like this:
addextender... #include "d:\\wbscriptb.wbt" ...bunch of other code setting up the ... dialog box..getting an answer switch case x call("wbscriptb"."") break ..rest of codeI then compile (99g) and the main menu comes up ok, but when i get:111 execution error. encrypted/encoded verification failed.Then when i click on that msg it actually brings up the file i '#include'd, without going throught the dialog and asking me to make a selection.Is there something magic about #includes that they can't all be at the beginning of the program and then let me call them as i need them?
What i envisioned was just having all the includes at the beginning, like assembler language, then having one big module result.
Answer:
Sort of kind of.I think what is going on is that although some code got included in your exe, your call statement went out looking for a WBT file, found the actual file (nothing to do with the include) and tried to run it.
- #Includes COPY the code right there into your program (in compiled mode anyway) It almost like copying and pasting the code into the script. You can't "CALL" the code you included, but you can GOSUB routines in it.
- If you put all the includes up on top, be sure to do a GOTO around the #include statements so they do not get executed when the script starts up
- Alternatively you can "encode" your sub-wbt files with the compiler, then when you compile the main program as an exe, include all those WBC files into the large exe you are making.
CALL's in a compiled EXE cannot run RAW exe files (they have to be encoded into WBC's first).
Question:
hmmm...on reading the answer again, is it possible that i can't call an #include'd wbc?if i do this: #include "d:\..\sname.wbc"
will i be able to do this: call("sname.wbc","")
or did the part about only being able to gosub only apply if i am copying in a raw wbt?
Answer:
Right. You can't do it *that way*. However you may be able to do it *other ways*.There is a problem in the definition of "referenced".
Consider the #include statement to be "executable". It is a line of code and it WILL execute just like all other lines of code.
If you include a WBC file it is executed right then and there. You cannot call the WBC file later in your script and expect it to have anything to do with the #include'd file.
Question:
I'm seeing something I've never seen before. I wrote a UDF and placed it in a separate file (we'll call it UDF_1.wbt). In my main program (I'll call it MAIN) I do a #include UDF_1.wbt near the top (prior to it being called of course). I compiled MAIN and ran it from the system I was developing on. Worked fine.Took the MAIN.exe to another system to run. I'm getting a 217 error saying it can't process the include file UDF_1.wbt.
Now I thought that anything #include'd was sucked in at compile time and therefore did not have to be present at runtime. I checked the docs but can't find any mention of this being different for UDFs.
Any idea what's happening?
Answer:
Post the *exact* code of the UDF. Read the #include docs.Somehow I think it did not get properly included.
What happens is that there can be two attempts to process a #include.
On the first attempt it tries to suck it in and make it part of the script. However if that fails for some reason (improperly coded #include ), then later, at execution time if it sees a #include is kind of tries again. The second time it needs the file.
The second pass is more forgiving than the first pass.
-----
#include "filename":
The keyword "#include" must be all lower-case. The file name must be delimited by double quotes. The file name may contain path information. Nothing else should appear on the line. ----------- Maybe put double quotes around the file name.
Article ID: W14216Filename: Include Statements - How They Work.txt