advertisement
Login | Register   
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Download the code for this article
If you have worked with the VB.NET beta release, do you agree or disagree with the author's conclusions? Are there even simpler ways to accomplish these tasks in VB.NET or VB? Let us know in the vb.dotnet.discussion newsgroup.
Partners & Affiliates
advertisement
advertisement
advertisement
advertisement
advertisement
Average Rating: 3.8/5 | Rate this item | 11 users have rated this item.
VB.NET Faces Off Against Classic VB (cont'd)

Create a GUID (Globally Unique ID)
GUIDs are an odd-looking series of numbers and characters, such as: {05589FA1-C356-11CE-BF01-00AA0055595A}. You might expect that GUIDs, because they're how COM distinguishes between objects, would be easy to create in classic VB, which depends on COM. And you might expect that they'd be harder to create in VB.NET, which doesn't depend on them. So much for expectations.

advertisement





Classic VB:

 Private Declare Function CoCreateGuid Lib _
"ole32.dll" (buffer As Byte) As Long
Private Declare Function StringFromGUID2 Lib _
"ole32.dll" (buffer As Byte, ByVal lpsz As Long, _
ByVal cbMax As Long) As Long
Private Function getGUID() As String
Dim buffer(15) As Byte
Dim s As String
Dim ret As Long
s = String$(128, 0)
ret = CoCreateGuid(buffer(0))
ret = StringFromGUID2(buffer(0), StrPtr(s), 128)
getGUID = Left$(s, ret - 1)
End Function



VB.NET

 Private Function getGUID() As String
GetGUID = "{" & _
System.Guid.NewGUID().ToString & "}"
End Function
Previous Page: Introduction Next Page: #2: Retrieve a random number within a specified range


Page 1: IntroductionPage 7: #6: Read a registry value
Page 2: #1: Create a GUID (Globally Unique ID)Page 8: #7: Launch another program and wait until it exits
Page 3: #2: Retrieve a random number within a specified range Page 9: #8: Populate a ListBox with values from a String array
Page 4: #3: Create a control dynamically at run-time Page 10: #9: Retrieve multiple selected items from a ListBox
Page 5: #4: Set the tab order of controls on a form Page 11: #10: Read the contents of a text file
Page 6: #5: Increment a variable  
Please rate this item (5=best)
 1  2  3  4  5
advertisement