option strict on !?

G

Gultekin Komanli

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.Text = 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.
--
 
M

Marina Levit [MVP]

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.
 
G

Gultekin Komanli

Thank you.
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.



--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top