Solved

Variables with "All of Windows" Scope

Posted on 2004-03-29
10
267 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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

Industry Leaders: 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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
Suggested Courses
Course of the Month9 days, 23 hours left to enroll

623 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