Quote: " I can only get them to work if they are defined in the same file as they are being used."
do you mean that you can only get a variable created as a type when the variable is declared in the same file as the type was defined?
Or can you only access/work with a typed variable in the same file as the type?
without more info on how and where you are setting up the types and typed variables, it sounds like a scoping issue (global vs local) of the variables.
UDTs cannot be declared inside of a function, it will throw a 'declaration not valid' error if you try, but the UDT declaration can appear anywhere else in any included file (using #include or via the IDE). Code execution doesn't even have to pass over it, and it will still be available to set to a variable at any time.
That being said, most include files are often just a collection of functions, and so any variables declared to be of the UDT in any of those functions will be local to the function unless declared to be global, and so would only be available in that file, and more specifically, that function.
now the help files on #include are misleading:
Quote: "Be aware that included source code is
appended to the end of the program, which means such declarations as TYPE and FUNCTION names included are only valid for use within the included file. If you want to use your TYPE globally, ensure it is declared in your main program.
"
it lies.
create the file "test.dba" as so:
type myType
someVariable as string
endtype
function included_function()
print "called include file function from main file"
rem print "local var: " + locMyType.someVariable
print "global var: " + globMyType.someVariable
endfunction
now create a new project as so:
#include "test.dba"
init_types()
included_function()
main_function()
end
function init_types()
locMyType as myType
locMyType.someVariable = "I'm local to this function"
global globMyType as myType
globMyType.someVariable = "I'm global"
endfunction
function main_function()
print "called main file function from main file"
wait key
endfunction
you can see that the main file is perfectly capable of calling the function from the included file and is able to set variables as the type declared in the included file (but watch your scoping).
Shazam!