Header
PowerPoint tips, hints and tutorials that will change your presentations for ever!

INDEX

 

Jigsaws
Sounds
Video
Custom Shows
vba code
NaviSlides
Games for teachers
Bullets
Triggers
Security
Flash Cards
Multiple Instances
PowerPoint 2007
Mail Merge
Random events
Animation
Hyperlinks
Set spellcheck language


Home buttonTutorial buttonContact buttonProducts button


Saving Settings

Let's imagine you have a game or App where the user can manually change certain settings OR change them by reaching a certain level. You would probably store these changed settings in a variable. The problem is they are lost when PowerPoint is closed. How can we save and load them?

The best answer is to write to the registry which may sound scary. Don't worry, as long as you use certain fixed keys it's easy and safe. Lets see how we can save the settings for a user. Start by creating Public variables (in most cases module wide variable will do but Public will work if you have other modules and won't cause a problem.

Public strUsername As String
Public lng_Level As Long

And now some typical code to get the username

Sub Get_Name()
Do
strUsername = InputBox("What is your name?")
Loop Until strUsername <> ""
End Sub

As the game progresses the value in lng_Level is updated to show the slide reached. When a save game button is clicked we want to save those settings - here's how.

Sub save_Game()
SaveSetting "mygame", strUsername, "level", lng_Level
'this creates a key for the gamename with a
'section for the user with a key holding the current level

End Sub

These settings will be retained even if the PC is powered down.

Next time the game is played get the username again and restore their settings like this:

Sub get_Level()
lng_Level = GetSetting("mygame", strUsername, "level", 1)
'the 1 is the default level if the key is empty
End Sub

You can easily then use the value to jump to a certain slide in the game.

To Delete a User:

Sub delete_Player()
On Error Resume Next
DeleteSetting "Mygame", "Put name here"
End Sub

If you understand the registry and want to find the keys you create they will be at :

HKEY_CURRENT_USER\Software\VB and VBA Program Settings\mygame

More than one setting? Create new sub keys like this:

Sub save_Game()
SaveSetting "mygame", strUsername, "level", lng_Level
SaveSetting "mygame", strUsername, "rating", "WIZZ"

'this creates a key for the gamename with a
'section for the user with a key holding the current level
'and another key with the rating

End Sub

 

 
 

Back to the Index Page

POWERPOINT BLOG

Articles on your favourite sport

Free Microsoft PowerPoint Advice, help and tutorials, Template Links
This website is sponsored by Technology Trish Ltd
© Technology Trish 2007
Registered in England and Wales No.5780175
PowerPoint® is a registered trademark of the Microsoft Corporation