-
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
-
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
-
Thanks Jim!
Works perfectly with minor editing...
I appreciate it...
-- Alan
-
DLL
Of course you can always make a DLL.......