|
Post by bfraley on Oct 27, 2013 4:44:55 GMT -5
As in most programming languages there's many ways to achieve the same task or result. I'm looking for the simplest way to define string variables in one .bas program and use them in another.
To clarify, these are string literals I store in variable names. So the values are already assigned and will not change. I would then like to use those variables as references within another application.
I know I can use object(s), or functions as methods of an object, etc. Also I don't need to exactly print, or render these values either. I just need to be able to access the string values for re-use.
They're just static string literal values to store in a variable name as a reference and I need to refer to them and use their text values in other .bas programs.
This is possible in many ways. Any suggestions or tips on the best way, the simplest way ?
Thanks in advance.
|
|
|
Post by bfraley on Oct 27, 2013 5:03:55 GMT -5
Additional example of the simplicity I'm going for.
stringFile.txt or stringFile.bas:
myVar$ = "These words are myVar's string value and won't change" end
someProgram.bas:
'I want to use myVar$, but I don't want to define it here, any help ?
print myVar$
'or
some #idObject=myVar$
end
|
|
|
Post by StefanPendl on Oct 28, 2013 5:04:01 GMT -5
The RUN command can be used to source in another program (BAS file).
You may have to build a function inside the sourced file to return the value of the variable.
|
|
|
Post by Mystic on Apr 2, 2014 13:58:07 GMT -5
I would save the required data in a file, then read the data into the other program.
|
|
neal
Full Member
Posts: 104
|
Post by neal on Apr 3, 2014 0:53:55 GMT -5
I'd go for the object approach - it's simple and it means the string values can't be accidently changed by the program (unlike a string variable): stringFile.basfunction myVar$() myVar$ = "These words are myVar's string value and won't change" end function someProgram.basrun #const, "stringFile.bas"
print #const myVar$() Downsides are: - Requires more typing
- The #object function$() syntax doesn't work everywhere that a string variable does
i.e. checkbox #myVar$, "Test", 0 works, but checkbox ##const myVar$(), "Test", 0 doesn't .
|
|