Solved

Variables with "All of Windows" Scope

Posted on 2004-03-29
10
259 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
  • 6
  • 2
  • 2
10 Comments
 
LVL 53

Assisted Solution

by:Dhaest
Dhaest earned 250 total points
Comment Utility
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
Comment Utility
I forget the what 'Global' scope is.

How would you store it in Registry.

0
 
LVL 53

Assisted Solution

by:Dhaest
Dhaest earned 250 total points
Comment Utility
0
 
LVL 1

Author Comment

by:sendtojp
Comment Utility
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
Comment Utility
I will check back in the morning (it's 0437 here), I have to goto bed.
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 1

Author Comment

by:sendtojp
Comment Utility
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
Comment Utility
That's   ...for your help opps
0
 
LVL 27

Accepted Solution

by:
Ark earned 250 total points
Comment Utility
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
Comment Utility
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 27

Expert Comment

by:Ark
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now