option strict on !?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gultekin Komanli

    #1

    option strict on !?

    Hi All,

    When I use "option strict on" the lines below are producing errors
    ("implicit conversion").


    chkMove.Checked = RegKey.GetValue (C_RK_MOVEFILES , False)
    txtUserName.Tex t = RegKey.GetValue (C_RK_USERNAME, "")

    Is there any function like GetValueBoolean , GetValueString for reading
    registry keys?

    Or should I use CType for conversion ?


    Cheers.
    Gultekin.
    --

  • Marina Levit [MVP]

    #2
    Re: option strict on !?

    Yes, always keep it on.

    And here, you are responsible for converting these values to the appropriate
    types. So you can use CType, or the more specialized CBool, CInt, CStr. You
    can also do things like Int32.Parse or Int32.TryParse, to actually parse
    strings as integers.
    These conversions will fail if what you are getting from the registry cannot
    be cast as the appropriate type.

    You can just construct your own wrapper that has GetValueBoolean , and so on,
    where you do all these conversions. Then you just call your own method,
    which retrieves the registry key, does the appropriate conversion, checks if
    it's empty, and so on.

    "Gultekin Komanli" <gkomanli@gmail .comwrote in message
    news:%23ls9oSm1 GHA.4816@TK2MSF TNGP06.phx.gbl. ..
    Hi All,
    >
    When I use "option strict on" the lines below are producing errors
    ("implicit conversion").
    >
    >
    chkMove.Checked = RegKey.GetValue (C_RK_MOVEFILES , False)
    txtUserName.Tex t = RegKey.GetValue (C_RK_USERNAME, "")
    >
    Is there any function like GetValueBoolean , GetValueString for reading
    registry keys?
    >
    Or should I use CType for conversion ?
    >
    >
    Cheers.
    Gultekin.
    --
    >

    Comment

    • Gultekin Komanli

      #3
      Re: option strict on !?

      Thank you.

      Marina Levit [MVP] wrote:
      Yes, always keep it on.
      >
      And here, you are responsible for converting these values to the
      appropriate types. So you can use CType, or the more specialized
      CBool, CInt, CStr. You can also do things like Int32.Parse or
      Int32.TryParse, to actually parse strings as integers. These
      conversions will fail if what you are getting from the registry
      cannot be cast as the appropriate type.
      >
      You can just construct your own wrapper that has GetValueBoolean , and
      so on, where you do all these conversions. Then you just call your
      own method, which retrieves the registry key, does the appropriate
      conversion, checks if it's empty, and so on.
      >
      "Gultekin Komanli" <gkomanli@gmail .comwrote in message
      news:%23ls9oSm1 GHA.4816@TK2MSF TNGP06.phx.gbl. ..
      Hi All,

      When I use "option strict on" the lines below are producing errors
      ("implicit conversion").


      chkMove.Checked = RegKey.GetValue (C_RK_MOVEFILES , False)
      txtUserName.Tex t = RegKey.GetValue (C_RK_USERNAME, "")

      Is there any function like GetValueBoolean , GetValueString for
      reading registry keys?

      Or should I use CType for conversion ?


      Cheers.
      Gultekin.
      --


      --

      Comment

      Working...