1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Function to create GUID

Discussion in 'Suggestions' started by mikea, Oct 12, 2013.

  1. mikea

    Joined:
    Dec 7, 2009
    Messages:
    210
    Likes Received:
    2
    I can (and often do) generate a GUID and get it into a variable this way:

    set xyzzy=%@execstr[uuidgen.exe]

    Or, as often as not, like this:

    set xyzzy=%@upper[%@replace[-,,%@execstr[uuidgen.exe]]]

    But of course that calls for always having UUIDGEN on tap. If there's some other tool for this other than ActiveState's Perl, with its Win32 extensions, I haven't run across it.

    Any chance of ever having a variable function such as %@guid[], which would immediately generate it? The frosting on the cake would be switches for returning the GUID in upper- or lower-case, and with or without hyphens separating the number groups.
     
  2. Joe Caverly

    Joined:
    Aug 28, 2009
    Messages:
    659
    Likes Received:
    8
    Every Windows system, from XP forward, comes with VBC.EXE, which is the Visual Basic Compiler for .NET. I have mine aliased as follows;

    Code:
    which vbc
    vbc is an alias : c:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc.exe
    You can create your own GUID generator with the following VB.NET code;

    Code:
    Imports System
    
    Class Sample
      Public Shared Sub Main()
      Dim g As Guid
      g = Guid.NewGuid()
      Console.WriteLine(g)
      End Sub 'Main
    End Class 'Sample
    Save the code as guid.bas, and execute the following;

    Code:
    vbc guid.bas
    This will create the file guid.exe, which you can use to create your own unique guid.

    Joe
     
  3. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,523
    Likes Received:
    4
    Joe:
    Could someone more familiar with VBC etc. than I am use your code above as the framework for a plugin, instead of creating an external executable? Of course, while we do not usually think of them that way, plugins are actually also externals, so the function would still use an external, just a different type (and the load time delay, if any, would occur at a different time).
     
  4. Joe Caverly

    Joined:
    Aug 28, 2009
    Messages:
    659
    Likes Received:
    8
  5. Joe Caverly

    Joined:
    Aug 28, 2009
    Messages:
    659
    Likes Received:
    8
    Updated: https://sites.google.com/site/jlcprogrammingstuff/home/tcc/jlcguid

    Contains the @guid[] variable function, and the guid command.

    guid -h

    UUID Generator v2013.10 Build 14

    usage: guid [-cdh]
    c - Output GUID in upper case
    d - Remove Hyphens
    h - Display command option summary


    echo @guid[] returns a UUID in uppercase, with hyphens, and {} braces.

    Joe
     
  6. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,523
    Likes Received:
    4
    Thanks! But a simple request - TCC's defaults to slash "/", just like CMD's, as the option prefix, not the POSIX-style hyphen. My own few utilities accept both (they predate TCC). Most plugins which process commands with options expect the slash...
     
  7. Joe Caverly

    Joined:
    Aug 28, 2009
    Messages:
    659
    Likes Received:
    8
  8. mikea

    Joined:
    Dec 7, 2009
    Messages:
    210
    Likes Received:
    2
    Thanks. Talk about instant gratification. : ) ... a few minutes later ... not having used 4NT or TCC plugins before, I guess I need to do some catching-up. I made a PLUGINS subdirectory of the install directory for TCC, added the new DLL to it, and closed and launched TCC.

    c:\takecommand> echo %@guid[]

    produced an error message about an incorrect function. Ok, let's load the DLL manually.

    plugin /L plugins\jlcGuid.dll

    Result: TCC: (Sys) plugins\jlcGuid.dll is not a valid Win32 application.

    or in case TCC assumes you've used a PLUGINS subdirectory:

    plugin /L jlcGuid.dll (same result)

    ...and echo %@guid[] had the same result as earlier

    So -- there must be some simple step I'm omitting here...
     
    #8 mikea, Oct 14, 2013
    Last edited: Oct 14, 2013
  9. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,287
    Likes Received:
    39
    Works here. Are you by any chance using a 64-bit build of TCC?
     
  10. Joe Caverly

    Joined:
    Aug 28, 2009
    Messages:
    659
    Likes Received:
    8
    Maybe, during your download of the file, it became corrupt?

    Delete the jlcGuid.dll and jlcGuid.zip, and download the file again.

    This may not be the problem, but it will eliminate one possibility.

    Joe
     
  11. mikea

    Joined:
    Dec 7, 2009
    Messages:
    210
    Likes Received:
    2
    Yes, 64-bit.

    Testing the .zip file's integrity with 7-zip, I'm not getting any errors.
     
  12. Joe Caverly

    Joined:
    Aug 28, 2009
    Messages:
    659
    Likes Received:
    8
    The compiler that I use is 32-bit, and the company has no plans to make a 64-bit version of their compiler.

    If you want, I can make a 32-bit .EXE version of the plugin for you.

    Joe
     
  13. mikea

    Joined:
    Dec 7, 2009
    Messages:
    210
    Likes Received:
    2
    Interesting decision on their part, given that 64-bit devices seem to be taking over. I appreciate the offer. I think I'm good with what I have, because I also have 4NT on a creaky old WinXP box, and I would think the DLL will work with that version.
     
  14. Joe Caverly

    Joined:
    Aug 28, 2009
    Messages:
    659
    Likes Received:
    8
    Since Bob Zale passed away, I'm not sure what direction PowerBASIC is taking. There have been assurances from his wife, Vivian Zale, that they are "preparing to launch new and innovative products", but I remember a year ago Bob saying that, since PowerBASIC is written in assembler, it is quite the task to create "new development syntax for hundreds of thousands of lines of assembler code. New generated machine code. New calling conventions. New optimization techniques. New register preservation."

    Bob Zale was PowerBASIC, and I will just have to wait and see what happens.

    Joe
     

Share This Page