Solved

Variables with "All of Windows" Scope

Posted on 2004-03-29
10
266 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 250 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 250 total points
ID: 10703357
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 250 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

734 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