RSS Feed Link       View page in German   View page in Spanish   View page in French   View page in Italian   View page in Portuguese   View page in Japanese   View page in Korean   View page in Simplified Chinese   
Log On   Feedback   Search Site    
 
 
Home eZine Software Scripting Network Admin. SITE UPGRADE IN PROGRESS - CLICK HERE FOR INFO 
 
Ask Vance
Welcome!   Columns   Tweaks   On-Line Courses    

 

Select Area:

Overview
Ask Vance
Peer 2 Peer
Book Reviews
Software Reviews

 
 Ask Vance
 


Vance Hunt

Columnist Vance Hunt has provided home-user help desk style support for his consulting company for over 6 years. Making his home in beautiful Southern California, Vance provides general computer Q&A for users via his weekly column.


Questions or comments for Vance may be sent to AskVance@Dx21.com

Before Editing The Registry.... Click Here.

Yeah! - more Vista "Features"
Column Date: 5/23/2008   (View Current)

Shout-Back
Shout Back As a question Select a Week

Q: I'm running Vista.  I use the MSTSC [Remote Desktop] to administer my servers.  I need to ensure that I attach to the console of the servers and not a terminal session, so I've always used the /console switch.  No issues ever on XP or 2003, and I hadn't any issues for a while on Vista.  But for the last few months, it doesn't work.  I keep the /console switch in and it just connects me to any session it feels like.

A: If you didn't need any other reason to hang your head and groan when it comes to Vista, welcome to Service Pack 1!  SP1 made changes to Vista to help bring it closer in line with the Server 2008 line of products, one of which was changing the (simplified here) the name "console" to "administrative session".  Your immediate realization of this is that when Vista was released, MSTSC accepted the /console switch.  When SP1 was released, MSTSC had the /console switch removed, and the /admin switch added.  Of course, everyone that was using the /console switch never got any errors or notices that it wasn't supported.  So, the end result is that when using Vista SP1 or greater and Windows Server 2008, use the /admin switch to connect to the "administrative session" on Windows Server 2008 as well as the "console" on Windows Server 2003.  You can read more about it here if you care.

Q: When using the dictionary object in VBScript, I know how to search for an item by knowing it's key, but how do I search for a key knowing the item value?

A: For those unfamiliar with the Scripting Dictionary object, you can get a good overview here, and a reference to the different properties and methods here.

Just to ensure that we are always talking about the same thing, the syntax for a Dictionary object is:

object Key, Item

Where the Key is typically a short identifier for the large amount of Item data.

I'm always somewhat surprised when I find people using the Dictionary object.  I have always considered it to be one of those hidden gems that seems to always become forgotten, lost somewhere between arrays, arrays of custom data types, and ADO record sets.  Nevertheless, when you find you need it, it fits the bill exactly.  Although, as you have pointed out, it does make a few assumptions, the most glaring of which is that you as a developer seem to never have a need to find a specific dictionary entry given only the Item data.  A way does exist:

01   Option Explicit
02
03   Dim objDict
04   Dim Index, strTemp
05   Dim vKey, vItem
06
07   'Create and Populate Dictionary object
08   Set objDict = WScript.CreateObject("Scripting.Dictionary")
09   For Index = 1 to 12
10       'Syntax: object.Add Key, Item
11       objDict.Add CStr(Index), MonthName(Index)
12   Next
13
14   'Easy search for Key
15   vKey = InputBox("Enter a Month Number (1 thru 12)","Find Key","5")
16   If objDict.Exists(vKey) Then
17       WScript.Echo objDict.Item(vKey)
18   Else
19       WScript.Echo "Key not Found"
20   End If
21
22   'Search for Item
23   vItem = InputBox("Enter a Month Name","Find Item","May")
24   strTemp = FindKeyFromItem(vItem,objDict)
25   If strTemp = vbNull Then
26       WScript.Echo "Key not found"
27   Else
28       WScript.Echo "Key: " & strTemp
29   End If
30
31   Set objDict = Nothing
32
33   Function FindKeyFromItem(vItem, objDictionary)
34       Dim objItems, objKeys
35       Dim Index
36
37       objItems = objDictionary.Items
38       objKeys = objDictionary.Keys
39
40       For Index = 0 To objDictionary.Count -1
41           If LCase(vItem) = LCase(objItems(Index)) Then
42               FindKeyFromItem = objKeys(Index)
43               Exit Function
44           End If
45       Next
46
47       FindKeyFromItem = vbNull
48   End Function

The function FindKeyFromItem is what does all the work.  It does so by taking the Dictionary's Keys and Items and separating them into two arrays.  It then enumerates the Items array, and if a match is found, it returns the Key value at the same index position as the Item data was found in.  Certainly not the best use of system memory, but one does what they have to do.

[Remove This Ad]

Note: The information posted within the comments section are the opinions of its authors. Such opinions may not be accurate and they are to be used at your own risk. Dx21, LLC cannot verify the validity of the statements made within the posted comments.

Messages that harass, abuse or threaten other members; have obscene or otherwise objectionable content; have spam, commercial or advertising content or links will be removed. Please do not post any private information unless you want it to be available publicly. Never assume that you are completely anonymous and cannot be identified by your posts.

Report abuse to the webmaster using the feedback link at top of page.

 

Comments: (Latest 3)

{No comments posted}


Post Comment:

click here to log in

 
Good Morning
8/20/2008 10:36:04 AM
Copyright © 1997 - 2008 Dx21, LLC. All rights reserved.
Dx21, LLC a Washington Limited Liability Company
  Privacy Policy | Terms of Use
   
Labelled with ICRA   Rated with SafeSurf