Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
1.5 KiB

  1. On Error Resume Next
  2. Set context = CreateObject("WbemScripting.SWbemNamedValueSet")
  3. 'Try to add a null
  4. context.Add "J", null
  5. Set namedValue = context.Add("fred", 23)
  6. context("fred").Value = 12
  7. context.Add "Hah", true
  8. context.Add "Whoah", "Freddy the frog"
  9. context.Add "Bam", Array(3456, 10, 12)
  10. 'Test collection behavior
  11. for each value in context
  12. if (IsNull (value)) Then
  13. WScript.Echo value.Name, "NULL"
  14. else
  15. if (IsArray (value)) Then
  16. Dim str
  17. str = value.Name & " {"
  18. V = value.Value
  19. for x=LBound(value) to UBound(value)
  20. if x <> LBound(value) Then
  21. str = str & ", "
  22. End If
  23. str2 = V(x)
  24. str = str & str2
  25. Next
  26. str = str & "}"
  27. WScript.Echo str
  28. Else
  29. WScript.Echo value.Name, value
  30. End if
  31. end if
  32. next
  33. if Err <> 0 Then
  34. WScript.Echo Err.Description
  35. Err.Clear
  36. End if
  37. 'Test Count property
  38. WScript.Echo "There are", context.Count, "elements in the context"
  39. 'Test Removal
  40. context.Remove("hah")
  41. WScript.Echo "There are", context.Count, "elements in the context"
  42. 'Test Removal when element not present (NB: context names are case-insensitive)
  43. context.Remove("Hah")
  44. WScript.Echo "There are", context.Count, "elements in the context"
  45. 'Iterate through the names
  46. WScript.Echo ""
  47. WScript.Echo "Here are the names:"
  48. WScript.Echo "=================="
  49. for each value in context
  50. WScript.Echo value.Name
  51. Next
  52. 'Test array access and default property of NamedValue
  53. WScript.Echo ""
  54. WScript.Echo "Whoah element of context = ", context("Whoah")