Retrieving data from register

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michel Vanderbeke

    #1

    Retrieving data from register

    Hello,

    When I want to retrieve data from the register, the defaultvalue doesn't
    seem to work correctly.

    iCounter =
    CInt(My.Compute r.Registry.Getv alue("HKEY_LOCA L_MACHINE\Softw are\MyProg\Sett ings",
    "Articles", "80"))

    Is it correct that when the entry in the register does not exist, the string
    "80" is taken as default?
    This does not seem to work with me.
    When the key Articles doesn't exist, there is no error and iCounter is set
    to 80.
    When the key Settings doesn't exist, there is sometimes an error and
    sometimes iCounter is set to 0.

    Does anyone have any idea what goes wrong?

    Many thanks,

    Michel


  • Robin Tucker

    #2
    Re: Retrieving data from register

    Hi Michel,



    It's entirely possible you can determine what is going on by breaking down
    your code into more readable chunks. Does the key "Settings" exist? What
    about "MyProg"? Either way, its easier to see what is going on with
    something like:



    Dim theValue As String =
    My.Computer.Reg istry.GetValue( "HKEY_LOCAL_MAC HINE\Software\M yProg\Settings" ,
    "Articles", "80").ToString( )

    If theValue Is Nothing Then

    ' The key or part of the path does not exist

    Throw New Exception ( .... )

    End If



    Dim theResult As Integer

    If Not Integer.TryPars e(theValue, theResult) Then

    ' A value was returned but it wasn't an integer...

    Throw New Exception ( .... )

    End If






    Robin



    Dim theSetting As
    "Michel Vanderbeke" <michel.vanderb eke@skynet.bewr ote in message
    news:uCz2GJwlHH A.4552@TK2MSFTN GP04.phx.gbl...
    Hello,
    >
    When I want to retrieve data from the register, the defaultvalue doesn't
    seem to work correctly.
    >
    iCounter =
    CInt(My.Compute r.Registry.Getv alue("HKEY_LOCA L_MACHINE\Softw are\MyProg\Sett ings",
    "Articles", "80"))
    >
    Is it correct that when the entry in the register does not exist, the
    string "80" is taken as default?
    This does not seem to work with me.
    When the key Articles doesn't exist, there is no error and iCounter is set
    to 80.
    When the key Settings doesn't exist, there is sometimes an error and
    sometimes iCounter is set to 0.
    >
    Does anyone have any idea what goes wrong?
    >
    Many thanks,
    >
    Michel
    >
    >

    Comment

    Working...