Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBScript compilation error

Status
Not open for further replies.

Joelo

MIS
Sep 27, 2003
61
I am run Win2000 server
Please could anyone tell me what I am doing wrong....I keep getting the following error message:

Microsoft VBScript compilation error '800a0401'

Expected end of statement

/maintenance/compliance/class_3D.asp, line 36

Public Default Function item ( k1,k2,k3)
-------------^


This is Code here:
<%
Class clsD3Dictionary
Private D3Dict
Private DebugFlag

' Initialize class
Private Sub Class_Initialize()
Set D3Dict = CreateObject(&quot;Scripting.Dictionary&quot;)
End Sub

' Add the key value &quot;key&quot; to given dictionary
Private Function addIndex(key,dict)
If Not dict.Exists(key) Then
dict.Add key, dict.Count
End if
End Function

Private Function getIndex(key,dict)
If Not dict.Exists(key) Then
dict.Add key, dict.Count
End If
getIndex = dict(key)
End Function

' Add to dictionary
Public Function Add( k1,k2,k3,v)
Dim i1,i2,i3,k
k = k1 & Chr(03) & k2 & Chr(03) & k3
If D3Dict.Exists(k) Then
D3Dict(k)= v
Else
D3Dict.Add k,v
End If
End Function

Public Default Function item ( k1,k2,k3)
Dim i1,i2,i3,k,v
k = k1 & Chr(03) & k2 & Chr(03) & k3
If D3Dict.Exists(k) Then
v=D3Dict(k)
Else
v=&quot;&quot;
End If
Item = v
End Function


' Check if the key exists
Public Function Exists( k1,k2,k3)
Dim i1,i2,i3,k,v
k = k1 & Chr(03) & k2 & Chr(03) & k3
Exists = D3Dict.Exists(k)
End Function

' data inferred with key and key number
Public Function Keys(k1,n)
Dim v,ky
keys = D3Dict.Keys
For Each key In Keys
v = Null
ky = split(key,chr(03))
If isArray(ky) Then
If n = 1 Then
v = ky(0)
ElseIf ky(0) = k1 Then
if n = 2 And Ubound(ky) >= 2 Then
v = ky(1)
Else
If n = 3 And Ubound(ky) >= 2 Then
v = ky(2)
End If
End If
End If
End If
If Not IsNull(v) And Instr(1,kx & Chr(03), v & Chr(03),1) <= 0 Then
If kx <> &quot;&quot; Then kx = kx & Chr(03)
kx = kx & v
End If
Next
Keys = Split(kx, Chr(03))
End Function

End Class
%>

 
Ooops sorry about that ....I forgot to remove <% %> in .vbs.

It ran alright without Error

what next should I do

Thanx
 
What next?
[1] Make up a simplified .asp and test it out on your server.
[2] As a reduced scale testing on the class itself, make your vbs to check its functionality.

I do see the points of certain of your private methods. (Have you something to hide?) In any case, I had browsed through some methods used within the listing you post, the most problematic code is your Public Function Keys(). Your use of IsArray() there and the If ... elseif ... end if etc show to me you have not thought through the problem.

I have remodelled the Keys() to a function that I know perform a definite task, UniqueKeys(). And, I modified here and there to make out something at least I can figure out the functionality. I post below a simple testing vbs. Hope you can sort out the idea and do to your script.
Code:
Dim cDic
Set cDic = new clsD3Dictionary

cDic.add &quot;a&quot;,&quot;b&quot;,&quot;c&quot;, &quot;d&quot;
cDic.add &quot;e&quot;,&quot;f&quot;,&quot;g&quot;,&quot;h&quot;
cDic.add &quot;i&quot;,&quot;j&quot;,&quot;k&quot;,&quot;l&quot;
cDic.add &quot;m&quot;,&quot;n&quot;,&quot;o&quot;,&quot;p&quot;
cDic.add &quot;a&quot;, &quot;b&quot;, &quot;e&quot;, &quot;q&quot;
wscript.echo cDic.item(&quot;a&quot;,&quot;b&quot;,&quot;c&quot;)
wscript.echo cDic.item(&quot;a&quot;,&quot;b&quot;,&quot;e&quot;)


Dim arX			'add method modified to pre-splitted string for testing
For n=1 to 3
arX = cDic.UniqueKeys(n)	'with base 1 in mind, ie, parameter must be >=1
	msgbox arX
Next

Set cDic = Nothing

Class clsD3Dictionary 
	'Public methods -----------------
	Public Sub Add(k1, k2, k3, v)
		Dim i1, i2, i3, k
		k = k1 & Chr(03) & k2 & Chr(03) & k3	'canonically formatted key
		If D3Dict.Exists(k) Then
			D3Dict.Item(k) = v
		Else
			D3Dict.Add k,v	'v here is not the count count
		End If 
	End Sub

	Public Default Function item (k1, k2, k3)
		Dim i1, i2, i3, k, v
		k = k1 & Chr(03) & k2 & Chr(03) & k3
		If D3Dict.Exists(k) Then
			v=D3Dict.Item(k)
		Else
			v=&quot;&quot;
		End If
		Item = v
	End Function

	' Check if the key exists
	Public Function Exists( k1,k2,k3)
		Dim i1,i2,i3,k,v
		k = k1 & Chr(03) & k2 & Chr(03) & k3	'format key k canonically
		Exists = D3Dict.Exists(k)
	End Function

	' unique nth (base-one) component in key set of the dictionary
	Public Function UniqueKeys(n)	'modified Keys()---guessing functionality
		Dim v, kx, ky, dimky
		If CInt(n)<=0 Then	'validation of n
			kx = &quot;&quot;
		Else
			keys = D3Dict.Keys
			For Each key In Keys
				v = Null
				ky = split(key,chr(03))
				dimky = UBound(ky) +1
				'IsArray() is redundant
				If n <= dimky Then v=ky(n-1)
				If Not (IsNull(v) Or Instr(1,kx & Chr(03), v & Chr(03),1) > 0) Then
					If kx <> &quot;&quot; Then kx = kx & Chr(03)
					kx = kx & v
				End If
			Next
		End If
		'Keys = Split(kx, Chr(03))	'original
		UniqueKeys = kx		'for testing purpose only
	End Function
	'Public methods ------------------

	'Private methods-------------------
	Private D3Dict
	'Private DebugFlag

	' Initialize class
	Private Sub Class_Initialize()
		Set D3Dict = CreateObject(&quot;Scripting.Dictionary&quot;)
	End Sub

	Private Sub Class_Terminate()
		Set D3Dict = Nothing
	End Sub
	
	'Private methods untested/useless-----------
	' Add the canonically formatted key value &quot;key&quot; to given dictionary
	Private Sub addIndex(key)
		If Not D3Dict.Exists(key) Then
			D3Dict.Add key, D3Dict.Count		
		End if
	End Sub

	Private Function getIndex(key)	
		If Not D3Dict.Exists(key) Then
			D3Dict.Add key, D3Dict.Count
		End If
		getIndex = D3Dict(key)
	End Function

	'Private methods--------------------

End Class
Not to forget that default should pose no problem, if your server is config'd properly. So the main thing is do your test on your server with an asp page.

I can't help you further if this is a school assignment. Besides I won't be available for 48 hours. Somebody might.

- tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top