string variables as external .bas resource

new BookmarkLockedFalling
bfraley
New Member
*

bfraley Avatar

Posts: 20

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.
bfraley
New Member
*

bfraley Avatar

Posts: 20

StefanPendl
Global Moderator
*****

StefanPendl Avatar

Run for BASIC ...
Posts: 945

Last Edit: Oct 28, 2013 5:05:14 GMT -5 by StefanPendl
[b]Stefan[/b] - [a href=http://stefanpendl.runbasichosting.com/]Homepage[/a][br][br][b]Please give credit if you use code I post, no need to ask for permission.[/b][br][br]Run BASIC 1.01, Fire-/Waterfox (IE11, Edge), Windows 10 Professional x64, Intel Core i7-4710MQ 2.5GHz, 16GB RAM
Mystic
New Member
*

Mystic Avatar

Posts: 29

- Rick
neal
Full Member
***

neal Avatar

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.bas

function myVar$()
myVar$ = "These words are myVar's string value and won't change"
end function


someProgram.bas

run #const, "stringFile.bas"

print #const myVar$()


Downsides are:

  1. Requires more typing
  2. 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 :(.