473,625 Members | 3,201 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reusable Code (Global Variables)

102 New Member
I have a set of variables that are used across multiple projects. How can the variables be reused? Can a dll be used?

Thanks.
Oct 22 '18 #1
1 2016
!NoItAll
297 Contributor
Ok - first to answer your question...

No - use a module. Put it in a folder common to all the projects in which you want to use them. When you add the module to the project(s) make sure you "Add as Link." Add as link is the same as adding it to your project, but it doesn't make a local copy. Instead it uses the one in your common folder. To add as link begin by adding it the way you normally do, but in the dialog where you click on "Add" you will notice a little drop-down arrow. Add as Link is one of the choices.

Be careful though - any changes you make to the common module will impact every program that uses it - and you WILL forget all of the programs that use it.

And next I want to challenge you to seek a better design...

Certainly there are times this approach makes sense (I'm not one of those "absolute" guys that will say "never do this.") There may be a better way to do what you need. Instead of globally referring to variables perhaps it will work better to make sure you are passing values into subs and functions, then handing them back as necessary. Make use of ByRef so any change you make to the variable will be reflected upon the function/sub return. Make use of ByVal if you want the sub/function to work with its own new copy of the variable. This can be a little tricky in VB though. Elementary types like integers will get copied in ByVal passing, but strings and instantiated objects will still pass in a reference and changes will be reflected up the chain unless you pass in a cloned copy. To avoid changing a string globally you can pass in string.clone. Some native dotnet objects support cloning - for your own objects you will need to implement iCloneable and decide if it needs to be shallow or deep. Implementing a deep-cloned class can be daunting...
Feb 10 '19 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

10
17850
by: Matt | last post by:
Greetings, What are people's thoughts on global variables in C++? Why are we taught not to use them in programming? Is it true that if you are running two copies of the C program one copy can overwrite another copies global variable? I know that you could overwrite a value in a global variable from a function, but you could also do that if you pass the variable in and then out again... so how is that any different?
8
2532
by: lawrence | last post by:
I'm learning Javascript. I downloaded a script for study. Please tell me how the variable "loop" can have scope in the first function when it is altered in the second function? It is not defined in global space, therefore it is not a global variable, yes? Even if it was global, how would it get from one function to another? In PHP variables are copied by value. Are they copied by reference in Javascript? <SCRIPT LANGUAGE="JavaScript">
17
5612
by: MLH | last post by:
A97 Topic: If there is a way to preserve the values assigned to global variables when an untrapped runtime error occurs? I don't think there is, but I thought I'd ask. During development, I'm constantly running tests on imperfect code. On of the cumbersome jobs encountered is reassigning global vars their values after a close encounter with an untrapped runtime error. Rather than writing a procedure to simply reassign them all with a...
8
1764
by: Fernan Bolando | last post by:
I have been going through some of the tutorials on the internet regarding coding styles in unix C programming. Most of the stuff I have read do not prefer using global variables, But for multi-file programs it is impossible not to have global variables. I am trying to learn of the best way to check if I am mis-using global variables. How do you guys know if there are to many global variables in your programs? I am not trying to start a...
7
3127
by: Michael | last post by:
Hi newsgroup, as the subject indicates I am looking for an advice using global variables. I am not if this problem is more about style then C. If its wrong in thi group, sorry. So I have a couple of function that all need the same information (all located in the same file). By now it looks like /* file beginns */
17
5520
by: Woody Splawn | last post by:
I am finding that time after time I have instances where I need to access information in a variable that is public. At the same time, the books I read say that one should not use public variables too much - that it's bad programming practice. Is there an easy way to deal with this? I would like to do things in the "Best Practices" way but at the same time I don't want to make a federal case out of it. This comes up over and over...
7
2568
by: zeecanvas | last post by:
Hi, First of all: Yes, I know global variables are bad, but I've a huge amount of legacy code, and I've to maintain it _as_is_. I'm maintaining a big program. I moved all (program-wide scope) global variables outside of the files they were defined it, and created some files that just hold global variables definitions (just variables, without any function definition). So, depending on the purpose/category of variables, they're defined...
9
8642
by: CDMAPoster | last post by:
About a year ago there was a thread about the use of global variables in A97: http://groups.google.com/group/comp.databases.ms-access/browse_frm/thread/fedc837a5aeb6157 Best Practices by Kang Su Gatlin, casual mention was made about using static variables as an alternative to using global variables. This caused me to think of the following: '-----Begin module code
5
11811
by: Sandman | last post by:
I dont think I understand them. I've read the section on scope in the manual inside out. I'm running PHP 5.2.0 Here is the code I'm working on: //include_me.php <?php $MYVAR = array(); global $MYVAR, $a; ?>
1
29338
weaknessforcats
by: weaknessforcats | last post by:
C++: The Case Against Global Variables Summary This article explores the negative ramifications of using global variables. The use of global variables is such a problem that C++ architects have called it polluting the global namespace. This article explores what happens when the global namespace becomes polluted and how to avoid this condition. The opinions expressed in this article are those of the author alone although many have...
0
8189
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8354
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8497
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7182
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6116
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4089
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4192
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.