Jump to content

Set $vars in main script that are used in include UDF?


Recommended Posts

So I have created a so-called 'master/main' include that basically has a ton of udfs that I have collected over time that I commonly use in my many projects.

An issue I have running into is I am looking to set some global $vars in my main script that are used in my master include. I tried setting them as globals in my main script but they dont seem to carry over to my include. Its as though the include is read and $vars are processed before my main script is read at compile time. When I try to compile my main script it complains that $vars in my master/include have not been defined yet when they have been in my main project script. If that makes sense. 

Hope that makes sense and thanks for any feedback.

~GD

Link to comment
Share on other sites

  • Moderators

GoogleDude,

It sounds to me as if you need to recast your entire "main/include" philosophy!

But to deal with the immediate problem: the code of any include file is inserted into the main script at the point of the #include directive, so if you declare the Global variables before that point they should be visible within your includes.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Yes I agree with your 'you need to recast your entire "main/include" philosophy!' part. I have become accustomed to what I think are some bad scripting habits and introduce some if not a lot of the misc issue I end up having. Thanks for the immediate problem part. I always thought that includes needed to be at the top of my script before the global $vars.

~GD

Link to comment
Share on other sites

Good programming practices require that #include should be self-sufficient.  If you need to have some global vars declared for your include to work properly (and they should be at the very minimum), you should declare them directly in the include, not in the calling script.  Information between the main script and the include script should always be passed thru function parameters.

Edited by Nine
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...