Guest User

Untitled

a guest
Apr 25th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 KB | None | 0 0
  1. #include <_HashTable.au3>
  2. ; Same script as Garys modified for the _HashTable.au3
  3. _Main()
  4.  
  5. Func _Main()
  6. ; Initialize the hash table
  7. _HashTableInit()
  8. Local $vKey, $sItem, $sMsg
  9.  
  10. ; Add keys with items
  11. _DebugPrint('_AddItem("One", "Same")' & @TAB & _HT_AddItem("One", "Same"))
  12. _DebugPrint('_AddItem("Two", "Car")' & @TAB & _HT_AddItem("Two", "Car"))
  13. _DebugPrint('_AddItem("Three", "House")' & @TAB & _HT_AddItem("Three", "House"))
  14. _DebugPrint('_AddItem("Three", "House")' & @TAB & _HT_AddItem("Three", "House"))
  15. _DebugPrint('_AddItem("Four", "Boat")' & @TAB & _HT_AddItem("Four", "Boat"))
  16. ; Display items
  17. MsgBox(0x0, 'Items Count: ' & _HT_GetCount(), $sItem, 3)
  18. If _HT_FindItem('One') Then
  19. ; Display item
  20. MsgBox(0x0, 'Item One', _HT_GetItem('One'), 2)
  21. ; Set an item
  22. _HT_UpdateItem('One', 'Changed')
  23. ; Display item
  24. MsgBox(0x20, 'Did Item One Change?', _HT_GetItem('One'), 3)
  25. ; Remove key
  26. _HT_RemoveItem('One')
  27. ;
  28. EndIf
  29.  
  30. ; Store items into a variable
  31. For $vKey In $a_HT_TableKeys
  32. If $vKey <> "" Then $sItem &= $vKey & " : " & _HT_GetItem($vKey) & @CRLF
  33. Next
  34.  
  35. ; Display items
  36. MsgBox(0x0, 'Items Count: ' & _HT_GetCount(), $sItem, 3)
  37.  
  38. ; Add items into an array
  39. $aArray = _HT_ToArray()
  40.  
  41. ; Display items in the array
  42. For $i = 0 To _HT_GetCount() - 1
  43. MsgBox(0x0, 'Array [ ' & $i & ' ]', $aArray[$i], 2)
  44. Next
  45.  
  46. _DebugPrint('_ItemRemove("Two")' & @TAB & _HT_RemoveItem("Two"))
  47. _DebugPrint('_ItemRemove("Three")' & @TAB & _HT_RemoveItem("Three"))
  48. _DebugPrint('_ItemRemove("Three")' & @TAB & _HT_RemoveItem("Three"))
  49. _DebugPrint('_ItemRemove("Four")' & @TAB & _HT_RemoveItem("Four"))
  50. _DebugPrint('$sz_HT_Deleted' &@TAB & $sz_HT_Deleted)
  51. ; use keys like an array index
  52. For $x = 1 To 3
  53. _HT_AddItem($x, "")
  54. Next
  55. $sItem = ""
  56. _HT_UpdateItem(2, "My Custom Item")
  57. _HT_UpdateItem(1, "This is the 1st item")
  58. _HT_UpdateItem(3, "This is the last item")
  59. For $vKey In $a_HT_TableKeys
  60. If $vKey <> "" Then $sItem &= $vKey & " : " & _HT_GetItem($vKey) & @CRLF
  61. Next
  62. ; Display items
  63. MsgBox(0x0, 'Items Count: ' & _HT_GetCount(), $sItem, 3)
  64.  
  65. $sItem = ""
  66.  
  67. _HT_ChangeKey(2, "My New Key")
  68. if @error Then _DebugPrint(StringFormat("error changing key\t%d\t%d",@error,@extended))
  69. For $vKey In $a_HT_TableKeys
  70. If $vKey <> "" Then $sItem &= $vKey & " : " & _HT_GetItem($vKey) & @CRLF
  71. Next
  72. ; Display items
  73. MsgBox(0x0, 'Items Count: ' & _HT_GetCount(), $sItem, 3)
  74.  
  75. _HT_RemoveAll()
  76. MsgBox(0x0, 'Items Count',_HT_GetCount(), 3)
  77.  
  78.  
  79. EndFunc ;==>_Main
  80. Func _DebugPrint($s_Text)
  81. ConsoleWrite( _
  82. "!===========================================================" & @LF & _
  83. "+===========================================================" & @LF & _
  84. "-->" & $s_Text & @LF & _
  85. "+===========================================================" & @LF)
  86. EndFunc ;==>_DebugPrint
Add Comment
Please, Sign In to add comment