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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dictionary Loading from An Array Problems

Status
Not open for further replies.

Kinl

Programmer
Mar 19, 2001
168
US
Ok, heres the scenario. I have an array of 3 elements, and I also have a dictionary object called strWords. When I add keywords the dictionary looks for the word 'and' OR the word 'or'. If it finds those words, it DOES NOT ADD THEM. I dont want these words in my dictionary.
That works fine. I then load my array again (by reDim'n by ReDim MyArray(strWords.Count - 1), cuz Arrays are zero based and Dictionarys are 1 based, and if I'm wrong, please let me know. But thats what I've read.
Once that is complete I then load the array from the dictionary through a for loop. This is where I have a problem. For some reason the loop increments automatically, and I dont have a variable to increment. I'm wondering is the Dictionary incrementing my loop? This causes a problem, by loading a 'blank' value or NULL value into one of my array slots. So, if I have an array that says 'dog or cat', it should return an array of 'dog, cat'. This is because at the ADD Procedure filters out the 'and' and the 'or' from the array that is loading the dictionary. I'll post the code below.
If this didnt make any sense, please let me know.

---------------------------------------------
Dictionary ObJect Code
---------------------------------------------
<%
CLASS clsSearchDict

Private KeySearch

Public Sub Class_Initialize
Set KeySearch = Server.CreateObject(&quot;Scripting.Dictionary&quot;)
End Sub

Public Sub Add(iCnt, word)
If word = &quot;or&quot; OR word = &quot;and&quot; then
'Nothing Happens!! Whooo hooo!!
Else
KeySearch.Add iCnt, word
Response.Write &quot;D - Added: &quot; & word & &quot;<BR><BR>&quot;
End If
End Sub

Public Property Get Count
Count = KeySearch.Count
End Property

END CLASS
%>

------------------
ASP Page Code
-----------------

I'm not going to post all of it, just the part i'm having a problem w/...

'strKeywords is the array that has 3 elements in it (cat, or, dog) this array was constructed from splitting a querystring. The only way i found to properly load the correct amount of elemets is to autoincrement 'i' and then deincrement it. I dont know why its working like that. I have no clue. I've spent over 10 hours trying to debug.


Dim strWords
Set strWords = New clsSearchDict
For i = 0 to UBOUND(strKeyWords)

i = i + 1
strWords.Add (i), strKeyWords(i - 1)
i = i - 1

Next




ReDim strKeyWords(strWords.Count - 1)

For i = 0 to (strWords.Count - 1)
strKeywords(i) = strWords.Item(i + 1)
Response.Write &quot;Still In Dictionary: &quot; & strKeyWords(i) & &quot;<BR><BR>&quot;
Response.Write i & &quot;<BR><BR>&quot;
Next

----------------------------

Thanx,

donn
 
The 1st paramter of the add is supposed to be key. You are using a number. Maybe 0 converts to a &quot;&quot;.

Ret
Code:
For i = 0 to UBOUND(strKeyWords)   
    strWords.Add &quot;Key&quot; & Cstr(I), strKeyWords(i)
Next
 
Thanx for the help. I actually just fixed it by using another array and dynamically ReDim'n the array to hold the new contents. That was easier and faster.

Thanx for the help though.

Donn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top