Elmo_loves_you 20 Junior Poster in Training

Hi Guys

I have managed to write values to a Windows Mobile CE Registry Editor from my application.

I have a writeIniReg() and a readIniReg() function

So, when the user enters their name in the textbox on the form it is written to the registry and read from it again the next time the user runs the program.

But my problem is that my readIniReg() gets a NullReferenceException when the program first loads .... but if I comment out the readIniReg() and run it to write data to the registry then uncomment the code, it can read from it...


Can anyone help me to check in my readIniReg() if the subKey folders exist first and create them if they dont exist ... so that I can get away from my error message.

Please even give some suggestions ... I still have a lot to learn with VB :)

Public Function readIniReg() As Boolean
        Dim localResult As Boolean
        Dim regKey As RegistryKey
        Dim regKeyCompany As RegistryKey
        Dim regKeyProduct As RegistryKey

        localResult = False

        regKey = Registry.CurrentUser.OpenSubKey("Software", True)
        regKeyCompany = regKey.OpenSubKey("Company", True)
        regKeyProduct = regKeyCompany.OpenSubKey("Data", True)

        'Name of value to return
        strName = regKeyProduct.GetValue("Username").ToString()
        'Pass username string variable to form1 variable
        Form1_LogIn.username = strName
        'Display Name in the textbox
        Form1_LogIn.txt_user.Text = strName


        'Close all keys
        regKeyCompany.Close()
        regKeyProduct.Close()
        regKey.Close()

Regards

Elmo

Comatose commented: Taste It -2