Iterating through a dictionary

Results 1 to 3 of 3

Thread: Iterating through a dictionary

  1. #1
    Join Date
    Dec 1969

    Default Iterating through a dictionary

    could someone tell me what is wrong with this code? I&#039;m getting this error. Thanks.<BR><BR>Microsoft VBScript runtime error &#039;800a000d&#039; <BR>Type mismatch: &#039;intValue&#039; <BR><BR>&#060;%<BR>x = 0<BR>k = objDict.Keys<BR>For i = 0 To objDict.Count - 1 <BR> intValue(x) = k(i) & "br tag" <BR>x = x + 1<BR>Next<BR>%&#062;<BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: Iterating through a dictionary

    intValue isn&#039;t an array or collection.<BR><BR>-Doug

  3. #3
    Join Date
    Dec 1969

    Default And also...

    You have named your array variable intValue but then you proceed to store strings into it. Why call it "int" anything if it will store strings? <BR><BR>You are using the variable x which has exactly the same value as the loop variable i. Why?<BR><BR>[Okay, neither of these are errors, per se, but I see *SO* many people doing this. Where are you all learning this from??? What&#039;s wrong with just doing:<BR><BR>&#060;%<BR>k = objDict.Keys<BR>Dim vals<BR>ReDim vals( objDict.count-1 )<BR>For i = 0 To objDict.Count - 1 <BR>&nbsp; &nbsp; vals(i) = k(i) & "br tag" <BR>Next<BR>%&#062;<BR><BR>But as long as I&#039;m quibbling: Why bother doing this AT ALL???<BR><BR>If you want an array of all the keys in the dictionary...well, you already have one! As you just demonstrated!<BR><BR>k<BR><BR>What in the world is the difference between vals(i) and k(i) ???<BR><BR>Why bother creating the second array???<BR><BR>

Posting Permissions

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