Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Variables with "All of Windows" Scope

Posted on 2004-03-29
10
Medium Priority
?
268 Views
Last Modified: 2010-05-02
I was wondering if it is possible to create code for Variables that will last for any Application during a session of Windows.

Example:

I open CountApples.exe which Apples=120
I close CountApples.exe

I open InventoryList.exe which prints Apples=120

0
Comment
Question by:sendtojp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 2
  • 2
10 Comments
 
LVL 53

Assisted Solution

by:Dhaest
Dhaest earned 1000 total points
ID: 10703273
The easiest way is to store it in a file, registry,database,... when closing the first application and reading the file within the second application.
I don't see any other way to do it.
0
 
LVL 1

Author Comment

by:sendtojp
ID: 10703322
I forget the what 'Global' scope is.

How would you store it in Registry.

0
 
LVL 53

Assisted Solution

by:Dhaest
Dhaest earned 1000 total points
ID: 10703357
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Author Comment

by:sendtojp
ID: 10703413
Is there a 'Plain Vanilla' subroutine with a few lines of code to gain a quick understanding.  I spppose you can use Registry to simulate a Variable.
0
 
LVL 1

Author Comment

by:sendtojp
ID: 10703473
I will check back in the morning (it's 0437 here), I have to goto bed.
0
 
LVL 1

Author Comment

by:sendtojp
ID: 10709092
Dhaest,

Do you have I 'Plain Vanilla'  (aka 'Hello World' Example).  I have accessed DLL's before but never have I written to the Registry.  You can use above Apple example or equalvant.  I will also raise the point and give you an 'A' grade.

Thank You your help,

-JP
0
 
LVL 1

Author Comment

by:sendtojp
ID: 10709098
That's   ...for your help opps
0
 
LVL 28

Accepted Solution

by:
Ark earned 1000 total points
ID: 10709715
Public Sub SetAllWindowsScopeVariable(ByVal sVarName As String, Byval sVarValue As String)
   SaveSetting("MyApp","GlobalVar",sVarName,sVarValue)
End Sub

Public Function GetAllWindowsScopeVariable(ByVal sVarName As String, Optional sDefaultValue As String="") As String
   GetAllWindowsScopeVariable = GetSetting("MyApp","GlobalVar",sVarName,sDefaultValue)
End Sub

Place both subs in all your apps bas modules.
'Now, to get value any time:
Apple = GetAllWindowsScopeVariable("Apple",120) '120 is default value if no variables set

'To save value:
Call SetAllWindowsScopeVariable("Apple", "240")
0
 
LVL 1

Author Comment

by:sendtojp
ID: 10719646
Can you explain the Arguments of SaveSetting, I checked it in MSDN it assumes you know the Registry.


SaveSetting appname, section, key, setting

When this is done, I will raise the points and give some to Dhaest and Ark.

Thanks for both your help.

-JP




0
 
LVL 28

Expert Comment

by:Ark
ID: 10720520
Hi
Get/Save settings works with HKEY_CURRENT_USER\Software\VB and VBA Program Settings registry key.
Arguments:
appname - string - subkey under above key. Usually set to App.EXE name, though it can be any unique string
section    - string - subkey under "appname" subkey. Any string (unique) you want.
key         - string - subkey under "section" subkey. Any string (unique) you want. Usualy sets to variable name.
setting    - string - registry value of "key" subkey. Usually sets to variable value.

In my sample above:
appname = MyApp
section = GlobalVar
key = "Apple"
setting = 240

So, my sample above use a subkey(s) (create one if it doesn't exist):
HKEY_CURRENT_USER\Software\VB and VBA Program Settings\MyApp\GlobalVar\XXXXX
where XXXXX is your variable(s) name(s) ("Apple" in sample) and set it (they) value(s) to YYYYYY (240 in a sample).
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question