Reputation: 429
Public Const ClassId = "92A1377A-7A3C-4FAF-94DA-C229AFFCFB12"
Public Const InterfaceId = "2DE393C7-300A-46DB-B33C-583B2765C2F9"
Public Const EventsId = "5452FC4D-C0C2-4E2B-87CA-8F43EAA14998"
I found this in a code snippet and need to create my own GUID in vb.net. But I didn't find a way that the program automatically creates constantes like this and shows them in the code. How can I do that? I'm not yet familiar with GUIDs but I suppose there were created automatically.
Thanks for any hints :)
Upvotes: 4
Views: 11847
Reputation: 172548
First point is that you cannot apply const
modifier to GUID's as const
is applied on primitive datatype. If you want you can use Shared ReadOnly
.
Second point is you can refer Guid.NewGuid Method () which is used to create GUID. Something like
Dim str = Guid.NewGuid.ToString()
EDIT:
A good MSDN reference which you have found yourself can be helpful.
Upvotes: 4
Reputation: 27342
Firstly you can use GuidGen
to create a new unique GUID for you:
Using menu TOOLS -> External Tools... add:
%Installation Path%\Microsoft Visual Studio 14.0\Common7\Tools\guidgen.exe
e.g.
C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\guidgen.exe
Give it a title of GUID Generator
Then you can run this to create a Guid String for yourself. Select option 4 (Registry Format)
Once you have created a guid, you can assign it to a constant string in your code:
Const MyGuidString = "{1606C5C9-9ECA-4227-9F7E-7FA032D153BE}"
This is however just a string. If you want to use it as an actual Guid, you can define a variable like this:
Dim guidObject = New Guid(MyGuidString)
Upvotes: 0