February 28, 2021
Hot Topics:

Using Graphics: Making a Lander Game - Part 3

  • By John Percival
  • Send Email »
  • More Articles »

Since we will be using VB's built in registry functions, we can't go far wrong, but the normal caveats still apply. The registry is an integral part of windows, so make sure that you backup before you start fiddling!

The registry functions must be able to read and write the entire high score table in the registry, according to the application's title, the name of the table and the number of rows in the table. The GetSetting and SaveSetting functions allow us to do all of this in only 4 lines of code! Check it out:

Public Sub ReadScores()
Dim getscore As Integer
For getscore = 1 To numberplaces
Scores(getscore).strName = GetSetting(App.Title, "Scores" _
  & scorename, getscore & "name", "No name")
Scores(getscore).intScore = GetSetting(App.Title, "Scores" _
  & scorename, getscore & "score", 1000)
End Sub
Public Sub WriteScores()
Dim putscore As Integer
For putscore = 1 To numberplaces
SaveSetting App.Title, "Scores" & scorename, putscore & _
  "name", Scores(putscore).strName
SaveSetting App.Title, "Scores" & scorename, putscore & _
  "score", Scores(putscore).intScore
End Sub

How much explanation does this code need? The read function goes through all the positions in the scores array, getting a value from the registry, and defaulting to "No name" and 1000 if none exist. The write function again goes through every element in the array, saving the value. You don't need any degrees or Microsoft Certifications to understand this!

(You can find out more about using the Registry in our topic area)

Page 4 of 6

This article was originally published on November 20, 2002

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date