Newbie Q about DIM statement....

  • Thread starter Thread starter Gary
  • Start date Start date
G

Gary

Hi,

Just downloaded some sample code, a registry write/delete sample , works
alright no problems, but I thought I would have a go and start making the
same code myself and then I get an error "type registrykey is not defined".

Dim regKey As RegistryKey


I have tracked down the error, when I start typing the "DIM regKey As" I
cant declare it as "RegistryKey"! like how come I don't see it in my drop
down box??? in the sample it says that "this class is a registry
encapsulation"

Gary
 
its possible that you have not imported the namespace that contains
RegistryKey (i think its in Microsoft.Win32)
to do this (over your entire project) go to menu project, project
properties, in there go to common, imports and add the namespace.
 
BINGO!!!

thanks a lot

gee this is a whole lot different to VB6, there is so much to learn :-)

Thanks again

Gary
 
* "Gary said:
Just downloaded some sample code, a registry write/delete sample , works
alright no problems, but I thought I would have a go and start making the
same code myself and then I get an error "type registrykey is not defined".

Dim regKey As RegistryKey

I have tracked down the error, when I start typing the "DIM regKey As" I
cant declare it as "RegistryKey"! like how come I don't see it in my drop
down box??? in the sample it says that "this class is a registry
encapsulation"

Type '... As Microsoft.Win32.RegistryKey'.

- or -

Add 'Imports Microsoft.Win32' on top of your file and use the code you
posted above.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

Improve your quoting style:
<http://learn.to/quote>
<http://www.plig.net/nnq/nquote.html>
 
Gary,
An alternative to importing the name space is to list it on the variable.

Which is useful when you have the same type in different namespaces and you
want to use both classes in the same source file.

Hope this helps
Jay
 
Back
Top