Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sub / function variable sharing

Status
Not open for further replies.

culdood

Programmer
Sep 17, 2000
3
US
I was just writing a program, and I was wondering if anyone could possibly tell me how I can make ALL variables in sub or functions common throughout the entire program, without having to type them all out. there are hundreds of variables in my program, and I don't want to have to type them all out. I wrote this program the only way that I thought I could. its a character generator for a role-playing game. I uploaded it to my webpage, and if you want to take a look, its at Thanks for your help! [sig][/sig]
 
Did you consider using COMMON and SHARED? Check out your help file then if you any more specific problems, post again.

Sincerely,

MiggyD [sig]<p> <br><a href=mailto: > </a><br><a href= > </a><br>You can pick your friends and you can pick your teeth and you can pick your toes, just don't pick you nose.[/sig]
 
Culdood, I tried to look at your code but I received a &quot;File System Error 1026&quot; which, I believe, is the same as &quot;File does not exist&quot;.

In any case, trust MiggyD. Use DIM SHARED to share variables in the same module. Use COMMON SHARED to share variables in different modules.
[sig]<p> <br><a href=mailto: > </a><br><a href= plain black box</a><br>Don't sit down. It's time to dig another one.[/sig]
 
my problem isn't really not knowing what to use, but moreso of not wanting to use it. its my understanding, be it flawed or not (which is probably is, and I&quot;m probably looking really ignorant) that DIM SHARED and COMMON SHARED, you must define which variables to make common throughout the program. since there are so many variables, I'd prefer not to have to make them all common. so I was wondering if there was a command to make them all common with one command. [sig][/sig]
 
Alt255, I had gotten the same response from the server. &quot;[red]FORBIDEN[/red], I'm not allowed access to file(s). blah blah cranston-ip blah blah.&quot;

It's hard to help when you can't see the problem. [sig]<p> <br><a href=mailto: > </a><br><a href= > </a><br>You can pick your friends and you can pick your teeth and you can pick your toes, just don't pick you nose.[/sig]
 
Culdood, there are no commands to share all variables across all modules. The only way you can avoid the COMMON and SHARED statements is to place all of your code in one simple drop-through module (no functions or subs) using GOTO and GOSUB to branch through the program.

I shudder at the thought. The code would be unreadable and the program's size would be severly limited.

You are better off (for uncountable reasons) to declare your variables at the module level. Sorry I couldn't make it easier for you.

[sig]<p> <br><a href=mailto: > </a><br><a href= plain black box</a><br>Don't sit down. It's time to dig another one.[/sig]
 

Well....there you go!

Word to the wise: &quot;Use one or the other or none at all.&quot; [sig]<p> <br><a href=mailto: > </a><br><a href= > </a><br>You can pick your friends and you can pick your teeth and you can pick your toes, just don't pick you nose.[/sig]
 
Culdood,
If I understand what you're asking I think I can advise you.
I was looking at having to declare hundreds of variable definitions in one of my programs. I wanted the computer to be able to assign some of these and I always strive for efficent flow soooo...

In my opinion this is what Dim shared is all about. You can do one Dim Shared MYVARIABLE(300) Then you can have the computer assign values as needed with a simple ctr.

And you can always bust out the MYVARIABLE(0)=&quot;blehbleh&quot;
MYVARIABLE(1)=&quot;sunny&quot;
MYVARIABLE (2)=&quot;balentimes&quot;
etc

If that didn't help run by me again what your'e wanting to do.

Via con dios
[sig]<p>Lupine<br><a href=mailto:RobertCorrina@patownsend.com>RobertCorrina@patownsend.com</a><br><a href= > </a><br> [/sig]
 
Another notion culdood,

Is that data(especially the amount of data your talking about) should remain outside of the code(the logic)
Then you read the data in with a simple SUB or whatnot
the architecture is up to you but this is a solid way to deal with data.
One benefit of this approach is you can change the data without changing hardcode
GN [sig]<p>Lupine<br><a href=mailto:RobertCorrina@patownsend.com>RobertCorrina@patownsend.com</a><br><a href= > </a><br> [/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top