Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Variables with "All of Windows" Scope

Posted on 2004-03-29
10
Medium Priority
?
271 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 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
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 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
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

916 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