This is making my brain hurt, so maybe someone else has done this and can help me along. Basically I have 2, one dimensional arrays that are sorted alphabetically. The arrays contain print driver names from servers, which I want to compare what drivers are loaded on serverA and serverB. The output will be in a table in an HTA and basically want it to look something like
SERVERA SERVERB
HP LaserJet 100 --- ' printer only exists on Server B
--- HP LaserJet 150 ' printer only exists on Server A
HP LaserJet 250 HP LaserJet 250 ' printer exists on both servers
I've found plenty of scripts (loops) that find a match, but nothing like what I'm trying to do above. I saw another post from RMueller to use Scripting.Dictionary, but I've never used it for anything. So, any ideas or assistance would be appreciated
Comparison Scripting
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Comparison Scripting
This is making my brain hurt, so maybe someone else has done this and can help me along. Basically I have 2, one dimensional arrays that are sorted alphabetically. The arrays contain print driver names from servers, which I want to compare what drivers are loaded on serverA and serverB. The output will be in a table in an HTA and basically want it to look something like
SERVERA SERVERB
HP LaserJet 100 --- ' printer only exists on Server B
--- HP LaserJet 150 ' printer only exists on Server A
HP LaserJet 250 HP LaserJet 250 ' printer exists on both servers
I've found plenty of scripts (loops) that find a match, but nothing like what I'm trying to do above. I saw another post from RMueller to use Scripting.Dictionary, but I've never used it for anything. So, any ideas or assistance would be appreciated
SERVERA SERVERB
HP LaserJet 100 --- ' printer only exists on Server B
--- HP LaserJet 150 ' printer only exists on Server A
HP LaserJet 250 HP LaserJet 250 ' printer exists on both servers
I've found plenty of scripts (loops) that find a match, but nothing like what I'm trying to do above. I saw another post from RMueller to use Scripting.Dictionary, but I've never used it for anything. So, any ideas or assistance would be appreciated
Comparison Scripting
Please look at my code as it demos the sorting.
The dictioanry is always sorted on teh key.
for each k in dct
WScript.Echo k
next
should print a sorted list of keys.
NO there is no sort method.
The dictioanry is always sorted on teh key.
for each k in dct
WScript.Echo k
next
should print a sorted list of keys.
NO there is no sort method.
Comparison Scripting
In your first FOR you add all of the dictionary objects for Server1 and then either add the printer if the key doesn't exist from Server1:
dct.Add element, "Server2"
or append the second second server to the key:
dct(element) = dct(element) & ",Server2"
So, any printers that were added would be on the bottom of the key list. I'm just wondering if there is a 'not complicated' way of sorting them alphabetically. rasimmer2009-02-18 13:18:18
dct.Add element, "Server2"
or append the second second server to the key:
dct(element) = dct(element) & ",Server2"
So, any printers that were added would be on the bottom of the key list. I'm just wondering if there is a 'not complicated' way of sorting them alphabetically. rasimmer2009-02-18 13:18:18
Comparison Scripting
Sorry - I am thinking of another area of dictionaries not in VBscript.
You are correct. Dictionaries are not sorted which has alwayts been a problem with VBScript.
use the following method.
keys = Sort(dct.Keys)
for each k in keys
WScript.Echo k, dct(k)
next
This will give you a sorted result.
You are correct. Dictionaries are not sorted which has alwayts been a problem with VBScript.
use the following method.
keys = Sort(dct.Keys)
for each k in keys
WScript.Echo k, dct(k)
next
This will give you a sorted result.
Comparison Scripting
Here is a complete sort solution.
Code: Select all
a = Array("J","I","H","G","F","E","D","C","B","A")Set dct = CreateObject("Scripting.Dictionary")For Each x In a ' WScript.Echo x dct.add x,0Next
For Each k In sort(dct.keys, dct.Count) WScript.Echo kNext
Function Sort(keys, cnt)
Dim oArrayList, i Set oArrayList = CreateObject("System.Collections.ArrayList" ) For i = 0 To cnt - 1 oArrayList.Add keys(i) Next
oArrayList.Sort set Sort = oArrayList
End Function
[code]
Comparison Scripting
And a yet again easier way to derive a sorted list.
We will use a - of all things - "SortedList" object. This object maintains a "Dictionary" like structure that is always sorted. I believe we can alter the sort method and even reverse the sort.
This will work on any system with NET Framework 1.1 or later installed.
Too often we forget that the NET framework was opened to COM at version 1.1 and MSCORLIB is automatically installed and registered. MSCORLIB contains numerous classes and collecion classes accessible from script languages.
We will use a - of all things - "SortedList" object. This object maintains a "Dictionary" like structure that is always sorted. I believe we can alter the sort method and even reverse the sort.
Code: Select all
a = Array("J","I","H","G","F","E","D","C","B","A")
Set sortedList = CreateObject("System.Collections.SortedList" )
' add the array contents
For Each x In a
sortedList.Add x, 0
Next
' now print the array and it will be in order.
For i = 0 To sortedList.count
WScript.Echo sortedList.GetKey(i)
Next
This will work on any system with NET Framework 1.1 or later installed.
Too often we forget that the NET framework was opened to COM at version 1.1 and MSCORLIB is automatically installed and registered. MSCORLIB contains numerous classes and collecion classes accessible from script languages.
Comparison Scripting
That's the deal. VERY COOL.
Post teh HTML and I will show you a very quick and easy way to generate the table without using string catenation.
What did you end up using for the sort?
Post teh HTML and I will show you a very quick and easy way to generate the table without using string catenation.
What did you end up using for the sort?
Comparison Scripting
Have you ever implemented the 'onclick' attribute using the dynamic table generation. I have tried several things:
img.onclick = vbScript:Test()
img.onclick = "vbScript:Test()"
img.onclick = Test()
img.onclick = "Test()"
img.onclick = Test
img.onclick = "Test"
img.onclick = vbScript:Test()
img.onclick = "vbScript:Test()"
img.onclick = Test()
img.onclick = "Test()"
img.onclick = Test
img.onclick = "Test"