Login | |
|
 |
RE: Comparing 2 dictionary objects - 10/16/2006 1:32:06 AM
|
|
 |
|
| |
ebgreen
Posts: 5246
Score: 31
Joined: 7/12/2005
Status: online
|
First, I would be suprised if this: If dctRealVals.Exists(actualstrTbs) ever evaluates to true, because you do this: actualstrTbs = trim(actualstrTbsName) So essentially if the key exists in the dictionary with white space, you are looking for it to exist in the dictionary without white space. If you think the keys are the same and the script does not, the script is never wrong. Try this code and verify that the keys really are the same: For Each strKey In dctRealVals.Keys() WScript.Echo "|" & Trim(strKey) & "|" Next For Each strKey In dctRealVals.Keys() WScript.Echo "|" & strKey & "|" Next
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: Comparing 2 dictionary objects - 10/16/2006 11:20:36 PM
|
|
 |
|
| |
ebgreen
Posts: 5246
Score: 31
Joined: 7/12/2005
Status: online
|
It does indeed appear that the trim is not working. Lets see what those strings are really made of. Run this code to see what characters are really comprising the strings: For Each strKey In dctRealVals.Keys() WScript.Echo "|" & Trim(strKey) & "|" For i = 1 To Len(strKey) WScript.Echo vbTab & Asc((Mid(strKey, i, 1)) Next Next For Each strKey In dctRealVals.Keys() WScript.Echo "|" & strKey & "|" For i = 1 To Len(strKey) WScript.Echo vbTab & Asc((Mid(strKey, i, 1)) Next Next
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: Comparing 2 dictionary objects - 10/17/2006 12:08:57 AM
|
|
 |
|
| |
ebgreen
Posts: 5246
Score: 31
Joined: 7/12/2005
Status: online
|
It means that the white space is tabs. Trim does not remove tabs, but we can remove them explicitly. Instead of using Trim to remove the whitespace, use Replace. actualstrTbs = Replace(actualstrTbsName, vbTab, "")
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: Comparing 2 dictionary objects - 10/17/2006 1:15:29 AM
|
|
 |
|
| |
chucksk
Posts: 13
Score: 0
Joined: 10/13/2006
Status: offline
|
Hi there, Am getting there now, however now the code fails to resolve the value after i pass the key: actualcolkeys = dctRealVals.Keys For Each actualstrTbsName in actualcolkeys actualstrTbs = Replace(actualstrTbsName, vbTab, "") actualstrTbs = Trim(actualstrTbs) 'WScript.Echo "|" & actualstrTbs & "|" 'WScript.Echo "dctRealVals.Exists(" & actualstrTbs & ")" WScript.Echo dctRealVals.Exists(actualstrTbs) If dctThresholds.Exists(actualstrTbs) Then WScript.Echo "Do i get here?" defaultcolvals = dctThresholds.Item(actualstrTbs) actualcolvals = dctRealVals.Item(actualstrTbs) WScript.Echo "dctRealVals.Item(" & actualstrTbs & ")" WScript.Echo "dctThresholds.Item(" & actualstrTbs & ")" WScript.Echo "The threshold is " & defaultcolvals WScript.Echo "The real value is " & actualcolvals WScript.Echo actualstrTbs & " " & defaultcolvals & " " & actualcolvals End If Next Sample output: Do i get here? dctRealVals.Item(DRSYS) dctThresholds.Item(DRSYS) The threshold is25 The real value is DRSYS 25 0 So the real value is missing? Now is that because of tabs as well? Cause i did this when i am actually entering the key/values into the dict obj: Do Until objExec.StdOut.atEndOfStream strNextLine = objExec.StdOut.ReadLine arrValueList = Split(strNextLine , ",") For i = 1 to Ubound(arrValueList) 'WScript.Echo Ubound(arrValueList) dctRealVals.Add Replace(arrValueList(0), vbTab, ""), Replace(arrValueList(i), vbTab, "") 'WScript.Echo "Adding" & trim(arrValueList(0)) & "," & arrValueList(i) Next Loop Is this the wrong place to do it? Thanks in advance
|
|
| |
|
|
|
 |
RE: Comparing 2 dictionary objects - 10/17/2006 1:21:50 AM
|
|
 |
|
| |
ebgreen
Posts: 5246
Score: 31
Joined: 7/12/2005
Status: online
|
I thnk we need to regroup. I'm having a hard time keeping the goal in sight. Please tell us exactly what you want the outcome to be and what the input to the script is.
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: Comparing 2 dictionary objects - 10/17/2006 1:35:58 AM
|
|
 |
|
| |
chucksk
Posts: 13
Score: 0
Joined: 10/13/2006
Status: offline
|
Hi, Sorry to confuse u! Have a set of tablespace names and values which are thresholds. These are in a text file: DRSYS , 25 EXAMPLE , 25 SYSTEM , 25 TEMP , 25 TOOLS , 25 UNDOTBS1 , 25 USERS , 25 Then i run a sql query to get the output from a db giving me the tablepsace name and the % used for each: DRSYS 24 EXAMPLE 4 SYSTEM 76 TEMP 8 TOOLS 100 UNDOTBS1 3 USERS 0 The set of thresholds and actual results are stored in 2 separate dictionary objects. Now i use the tablespace name as the key and the idea is that because the keys are the same on each dictionary, i can obtain the values thus enabling me to check if the pct used is over the threshold! Now we verified that the output from the sql had tabs in it and thats why it was not recognising the keys. After using the Replace function i can see that it is actually chopping the tabs of and getting the the thesold from the thresholds dict. However it is not getting the actual result so i have nothing to compare! Here is the code in full: If WScript.Arguments.Count = 0 Then WScript.Echo "Oracle Username and Password not specified" WScript.Echo "Usage: cscript scriptname SID username password" errLevel = 1 WScript.Quit(errLevel) End If strSID = Wscript.Arguments.Item(0) strUsername = Wscript.Arguments.Item(1) strPassword = Wscript.Arguments.Item(2) strTbsThresholds = Wscript.Arguments.Item(3) Const ForReading = 1 strOSCommandText = "cmd /c sqlplus -s " & strUsername & "/" & strPassword & "@" & strSID & " @sqltest" WScript.Echo strOSCommandText Set WshShell = CreateObject("WScript.Shell") Set objFSO = CreateObject("Scripting.FileSystemObject") Set dctThresholds = CreateObject("Scripting.Dictionary") dctThresholds.CompareMode = TextMode Set dctRealVals = CreateObject("Scripting.Dictionary") dctRealVals.CompareMode = TextMode 'Retrieve the default thresholds and put them in a hash array Set objTbsThresholds = objFSO.OpenTextFile(strTbsThresholds, ForReading) Do While objTbsThresholds.AtEndofStream <> True strText = objTbsThresholds.ReadLine 'WScript.Echo strText 'Split the string and put contents in an array strTextArray = Split(strText, ",") 'Add the key/value pairs into a hash array For x = 1 to Ubound(strTextArray) dctThresholds.Add Trim(strTextArray(0)), Trim(strTextArray(x)) Next Loop Set objExec = WshShell.Exec(strOSCommandText) ' Retrieve the actual tablespace usage and put it into another hash array Do Until objExec.StdOut.atEndOfStream strNextLine = objExec.StdOut.ReadLine arrValueList = Split(strNextLine , ",") For i = 1 to Ubound(arrValueList) 'WScript.Echo Ubound(arrValueList) dctRealVals.Add Replace(arrValueList(0), vbTab, ""), Replace(arrValueList(i), vbTab, "") 'WScript.Echo "Adding" & trim(arrValueList(0)) & "," & arrValueList(i) Next Loop 'Loop through the default key/value pairs defaultcolkeys = dctThresholds.Keys For Each strTbsName in defaultcolKeys defaultcolvals = dctThresholds.Item(strTbsName) lenstrTbsName = len(strTbsName) Wscript.Echo "|" & strTbsName & "|" & defaultcolvals & " " & lenstrTbsName Next 'Loop through the actual results actualcolkeys = dctRealVals.Keys For Each actualstrTbsName in actualcolkeys actualcolvals = dctRealVals.Item(actualstrTbsName) WScript.Echo actualstrTbsName & " " & actualcolvals Next actualcolkeys = dctRealVals.Keys For Each actualstrTbsName in actualcolkeys actualstrTbs = Replace(actualstrTbsName, vbTab, "") actualstrTbs = Trim(actualstrTbs) WScript.Echo dctRealVals.Exists(actualstrTbs) If dctThresholds.Exists(actualstrTbs) Then WScript.Echo "Do i get here?" defaultcolvals = dctThresholds.Item(actualstrTbs) actualcolvals = dctRealVals.Item(actualstrTbs) WScript.Echo "dctRealVals.Item(" & actualstrTbs & ")" WScript.Echo "dctThresholds.Item(" & actualstrTbs & ")" WScript.Echo "The threshold is " & defaultcolvals WScript.Echo "The real value is " & actualcolvals WScript.Echo actualstrTbs & " " & defaultcolvals & " " & actualcolvals End If Next WScript.Quit(errLevel) I hope this makes it a tad clear. Let me know if it does not! Thanks again
|
|
| |
|
|
|
 |
RE: Comparing 2 dictionary objects - 10/17/2006 7:59:01 PM
|
|
 |
|
| |
chucksk
Posts: 13
Score: 0
Joined: 10/13/2006
Status: offline
|
Hi there, I have taken out the comparemode method. I have also made some progress. I can now pull the tbs name the pct used and the threshold for that particular threshold! However the problem i have now is that i cannot compare the actual pct used with the threshold (i.e <,>). I think this due to the fact that the actual results have some 'invisible' characters in there as well. I edited the last snip of code so that it looks this now: actualcolkeys = dctRealVals.Keys For Each actualstrTbsName in actualcolkeys actualstrTbs = Replace(actualstrTbsName, vbTab, "") actualstrTbs = Trim(actualstrTbs) WScript.Echo dctRealVals.Exists(actualstrTbs) actualcol = dctRealVals.Item(actualstrTbsName) actualcolt = Replace(actualcol, vbTab, "") WScript.Echo "|" & actualcolt & "|" For i = 1 To Len(actualcolt) WScript.Echo vbTab & Asc((Mid(actualcolt, i, 1))) Next If dctThresholds.Exists(actualstrTbs) Then defaultcolvals = dctThresholds.Item(actualstrTbs) WScript.Echo "The tbs is " & actualstrTbs & "The pct used is " & actualcolt & "The threshold is " & defaultcolvals If CInt(actualcolt0) >= CInt(defaultcolvals) Then WScript.Echo "I got here" End If End If Next Notice i have a replace function in there to replace the tabs (as per your suggestion last time around). However it does not seem to make any difference: The tbs is TOOLS The pct used is 100The threshold is 25 0 | 3| 32 32 32 32 32 32 32 32 51 My queston is: Are those tabs in there or something else? As u can see i can now get the tablespace name, the pct used and its threshold. All I need is the compare to work! Thanks in advance, Chucksk
|
|
| |
|
|
|
|
|