views:

606

answers:

6

Hello,

I made a game and I would like to store the high score and other values in the windows registry. It's made in vb .net. Could someone give me a sample code example of simple reading and writing to the registry.

Thanks

+2  A: 

Writing

Reading

Links found using Google.

Rob
+1  A: 

I'm more comfortable with C#, but it's pretty straightforward with VB.NET too. Here's an example of how to write to the registry, and another example of how to read from the registry. Don't forget to import the Microsoft.Win32 namespace.

Matt Davis
A: 

Simply...

  Imports Microsoft.VisualBasic

  Dim s As String

  SaveSetting("(AppName)", "(SectionName)", "(Key)", "(Your Value)")

  s = GetSetting("(AppName)", "(SectionName)", "(Key)", "(Default Value)")

Replace (AppName), (SectionName), (Key) with appropriate values. The data will be saved in HKEY_CURRENT_USER\Software\VB and VBA Program Settings\(AppName)

Bill
A: 

You can use registry.getvalue and registry.setvalue. Here are a couple of examples used for default file types:

Registry.GetValue("HKEY_CURRENT_USER\software\classes" & "\" & fileFormatExt(i), "", "error")

Registry.SetValue("HKEY_CURRENT_USER\software\classes\" & FileType, "", appTag) ' set new value, overwrite any other, creates key if not there.
xpda
A: 

I am using code for web page in aspx page for registry value set

Dim IERegKey As RegistryKey

        Dim header As String
        Dim footer As String
        Dim margin_left As String
        Dim margin_top As String
        Dim margin_bottom As String
        Dim bottom As Double
        footer = ""
        header = ""
        IERegKey = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Internet Explorer\\PageSetup", True)

        'footer = IERegKey.GetValue("footer", 0)
        'header = IERegKey.GetValue("header", 0)
        'margin_top = IERegKey.GetValue("margin_top", 0)
        'margin_bottom = IERegKey.GetValue("margin_bottom", 0)
        bottom = 0.25
        IERegKey.SetValue("footer", "")
        'IERegKey.SetValue("header", "")
        ''IERegKey.SetValue("margin_top", bottom)
        'IERegKey.SetValue("margin_bottom", 0)

when I am testing the code from working project it will running but when i make websetup and installed in application server it shows erros as

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 56: 'margin_bottom = IERegKey.GetValue("margin_bottom", 0) Line 57: bottom = 0.25 Line 58: IERegKey.SetValue("footer", "") Line 59: 'IERegKey.SetValue("header", "") Line 60: ''IERegKey.SetValue("margin_top", bottom)

please do help me

Upal Bhowmik