Forums before death by AOL, social media and spammers... "We can't have nice things"
|    alt.comp.os.windows-xp    |    Actually wasn't too bad for a M$-OS    |    17,273 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 17,073 of 17,273    |
|    C-Sharp User to R.Wieser    |
|    Re: VBScript dictionary delete by index     |
|    06 Nov 25 22:40:40    |
   
   XPost: alt.comp.lang.vbscript, alt.windows7.general   
   From: csharp@invalid.invalid   
      
   On 06/11/2025 09:03, R.Wieser wrote:   
   > Hello all,   
   >   
   > I've got a vbscript Dictionary object, and need to be able to delete a   
   > key-item pair by its index. Can it be done and if so, how is it expressed ?   
   >   
   > Remark: I can use   
   >   
   > oDict.remove oDict.keys()(Index)   
   >   
   > , but that takes two steps and is doing more work than is needed (which also   
   > excludes converting to a pair of arrays and converting it back afterwards by   
   > the way :-) )   
   >   
   > Regards,   
   > Rudy Wieser   
   >   
   >   
      
   How about CoPilot method:   
      
      
   Dim dict, key   
   Set dict = CreateObject("Scripting.Dictionary")   
      
   dict.Add "a", "apple"   
   dict.Add "b", "banana"   
   dict.Add "c", "cherry"   
      
   ' Remove item by index (e.g., index 1)   
   key = dict.Keys()(1)   
   dict.Remove key   
      
   ' Show remaining items   
   For Each key In dict.Keys   
    WScript.Echo key & ": " & dict(key)   
   Next   
      
      
   > ' Create an array (range of values)   
   > Dim arr   
   > arr = Array(1, 2, 3, 4, 5)   
   >   
   > ' Define the start and end index for reversing   
   > Dim i   
   > Dim reversedArr   
   > ReDim reversedArr(UBound(arr)) ' Create a new array to store the   
   > reversed values   
   >   
   > ' Reverse the array using a loop   
   > For i = 0 To UBound(arr)   
   > reversedArr(i) = arr(UBound(arr) - i)   
   > Next   
   >   
   > ' Output the reversed array   
   > For i = 0 To UBound(reversedArr)   
   > WScript.Echo reversedArr(i)   
   > Next   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca