Results 1 to 4 of 4

Thread: C to VB Translation

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2001
    Posts
    9

    Exclamation C to VB Translation

    HI everyone!

    I have a C function that I need to rewrite in VB, unfortunately I have NO C experience... if anyone can do this for me please, I would be very thankful.

    Here is the function I need translated:

    void randomize_guid(unsigned char *buf)
    {
    int digit, dig;
    time_t curtime;

    *buf++='{';
    time(&curtime);
    srand(curtime);
    for (digit=0; digit <32; digit++)
    {
    if (digit==8 || digit == 12 || digit == 16 || digit == 20) *buf++='-';

    dig = rand()%0xf;
    if (dig<10)
    *buf++='0'+dig;
    else
    *buf++='A'+(dig-10);
    }
    *buf++='}';
    *buf++='\0';
    }

    Thanks,
    Alan

  2. #2
    jim mcnamara
    Guest
    Translation to VB

    Code:
    Sub randomize_guid(ByRef buf as string)
      dim  digit as long, dig as long
      dim curtime as long
      buf = "{" 
    ' curtime is supposed to be the number of seconds since 1970, Jan 01
    ' used as a seed for the random number generator
    ' there is no direct VB equivalent.  You'll have to add up the number of seconds elapsed since then
      randomize(curtime)
      for digit=0 to 31
        
        if digit = 8 or digit = 12 or digit = 16 or digit = 20 then 
             buf = buf &"-"
             goto Bottom
        end if
        dig = rnd() mod 15
        if dig<10 then 
    	buf = buf & Cstr(dig)
        else 
    	buf = buf & chr(asc("A") + dig - 10
        end if
    
    Bottom:
    
      next digit
    
      buf = buf & "}"
      buf = buf & chr(0)
    
    ' this is because C strings all end with null char.
    End Sub

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2001
    Posts
    9
    Thanks Jim!

    Works perfectly with minor editing...

    I appreciate it...

    -- Alan

  4. #4
    Lively Member
    Join Date
    Dec 2000
    Location
    Indiana
    Posts
    73

    DLL

    Of course you can always make a DLL.......
    if(GetWindowLong(hwnd,GWL_ID)==IDC_MICROSOFT_APPLICATION)
    {
    SetWindowText(hwnd,"I suck.");
    SendMessage(hwnd,WM_START_SUCKING,0,0);
    SendMessage(hwnd,WM_CRASH,0,0);
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width