Print Page | Close Window

How to use this function

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=7580
Printed Date: 01 April 2026 at 1:00am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: How to use this function
Posted By: Crash1hd
Subject: How to use this function
Date Posted: 24 November 2003 at 8:47pm

I am having trouble with calling the following function?

'Generates a GUID
Function GenerateGUID()
 GenerateGUID = Mid(Server.CreateObject("Scriptlet.TypeLib").GUID, 1, 38)
End Function

'Generate a unique OIK
Function GenerateGUID(ByRef Connection, ByVal TableName, ByVal GUIDFieldName)
 Dim GUID, IsOk, SQL, RS
 IsOk = False
 
 Dim Counter
 Counter = 0
 
 'loop round generating new GUIDs until we've found one that hasn't been used yet!
 While Not IsOk
  Counter = Counter + 1
  
  GUID = GenerateGUID()
  
  SQL = "SELECT [" & GUIDFieldName & "] FROM [" & TableName & "] WHERE [" & GUIDFieldName & "]='" & GUID & "'"
  'Response.Write SQL & "<BR>"
  'Response.Flush
  
  Set RS = ExecuteQuery(Connection, SQL, False, True)
  
  If RS.EOF Then
   'No matching GUID found, so it really *is* unique
   IsOk = True
  End If

  Kill RS
 Wend
 
 'Response.Write "GenerateGUID took " & Counter & " attempts to generate a new GUID.<BR>"
 GenerateGUID = GUID
End Function

I thought you would call it like so

response.write GenerateGUID(Conn, CouponCode, CCode)

but it seems that I am incorrect!

Is there some code I am missing?




Replies:
Posted By: Phat
Date Posted: 24 November 2003 at 9:55pm
What's the error. You have two functions by the same name. Name one  makeGuid and one checkGuide and see what happens


Posted By: Crash1hd
Date Posted: 24 November 2003 at 11:35pm

Ok I changed it to this

<%

'Generates a GUID
Function MakeGUID()
 MakeGUID = Mid(Server.CreateObject("Scriptlet.TypeLib").GUID, 1, 38)
End Function

'Generate a unique OIK
Function GenerateGUID(ByRef Connection, ByVal TableName, ByVal GUIDFieldName)
 Dim GUID, IsOk, SQL, RS
 IsOk = False
 
 Dim Counter
 Counter = 0
 
 'loop round generating new GUIDs until we've found one that hasn't been used yet!
 While Not IsOk
  Counter = Counter + 1
  
  GUID = MakeGUID()
  
  SQL = "SELECT [" & GUIDFieldName & "] FROM [" & TableName & "] WHERE [" & GUIDFieldName & "]='" & GUID & "'"
  Response.Write SQL & "<BR>"
  'Response.Flush
  
  Set RS = ExecuteQuery(Connection, SQL, False, True)
  
  If RS.EOF Then
   'No matching GUID found, so it really *is* unique
   IsOk = True
  End If

  Kill RS
 Wend
 
 'Response.Write "GenerateGUID took " & Counter & " attempts to generate a new GUID.<BR>"
 GenerateGUID = GUID
End Function

Response.write GenerateGUID("Conn, CouponCode, CCode") '1

GenerateGUID("Conn, CouponCode, CCode") '2

%>

And now I get the following error useing number 1

SELECT [] FROM [] WHERE []='{8DA1D6A9-1C0F-4227-A211-550C4C747932}'

Microsoft VBScript runtime error '800a000d'

Type mismatch: 'ExecuteQuery'

/test.asp, line 33

And Line 33 is   Set RS = ExecuteQuery(Connection, SQL, False, True)

so I know that there is a problem with

GenerateGUID("Conn, CouponCode, CCode")

when I use the above Number 2 I get this error

Microsoft VBScript runtime error '800a01c2'

Wrong number of arguments or invalid property assignment: 'GenerateGUID'

/test.asp, line 48



Posted By: Mart
Date Posted: 25 November 2003 at 12:49am
Its because your not providing all the arguments. Try

GenerateGUID(Conn, CouponCode, CCode)


Posted By: Crash1hd
Date Posted: 25 November 2003 at 1:03am

Originally posted by Mart Mart wrote:

Its because your not providing all the arguments. Try

GenerateGUID(Conn, CouponCode, CCode)

I tried that and forgot to add it :( lol it gives me

Microsoft VBScript compilation error '800a0414'

Cannot use parentheses when calling a Sub

/test.asp, line 49

GenerateGUID(Conn, CouponCode, CCode)
-------------------------------------^
thats replacing 
GenerateGUID("Conn, CouponCode, CCode")
for
GenerateGUID(Conn, CouponCode, CCode) right?
Then I try
Call GenerateGUID(Conn, CouponCode, CCode) and I get this error
SELECT [] FROM [] WHERE []='F2D4F72B-52B5-4CF9-B23B-E3ECB08F163B'

Microsoft VBScript runtime error '800a000d'

Type mismatch: 'ExecuteQuery'

/test.asp, line 34



Posted By: Crash1hd
Date Posted: 25 November 2003 at 3:54am

Ok I found the proper way to call it! see below

GenerateGUID Conn, "CouponCode", "CCode"

But I still get an error of

SELECT CCode FROM CouponCode WHERE CCode = 'B7D25AA2-0BA5-4A7A-AFDF-FDE0030831CC'

Microsoft VBScript runtime error '800a000d'

Type mismatch: 'ExecuteQuery'

/test.asp, line 34

Line 34 is

Set RS = ExecuteQuery(Connection, SQL, False, True)



Posted By: Phat
Date Posted: 25 November 2003 at 4:55am
Type mismatch has something to do with the data types. Make sure you're coparing the same thing to the same thing.

E.g. String to string


Posted By: Crash1hd
Date Posted: 25 November 2003 at 5:07am

Originally posted by Phat Phat wrote:

Type mismatch has something to do with the data types. Make sure you're coparing the same thing to the same thing.

E.g. String to string

Please explain when you say string to string do you mean the name of the field in the db to the one in the script? cause they match the one I still feel I am having trouble with is the one in red

GenerateGUID Conn, "CouponCode", "CCode"



Posted By: Phat
Date Posted: 25 November 2003 at 5:46am
Originally posted by Crash1hd Crash1hd wrote:

GenerateGUID Conn, "CouponCode", "CCode"



Doing the above you're using couponcode and ccode instead of the vaules they represent.


Posted By: Crash1hd
Date Posted: 25 November 2003 at 6:17am

Actually I was missing some functions.  I had forgotten to add an include at the beginning of the file to get the function of ExecuteQuery works great now!

 

Thanks for all the help though! It was greatly appreciated

 



Posted By: Diep-Vriezer
Date Posted: 26 November 2003 at 3:32pm


-------------
Gone..



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net