Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You've already found a <a href="https://stackoverflow.com/a/17786308/249624">valid solution</a>, but I want to explain what's going on here.</p> <p>The keys of a <code>Dictionary</code> object can be of any type except arrays (see the <a href="http://msdn.microsoft.com/en-us/library/x4k5wbx4%28v=vs.84%29.aspx" rel="nofollow noreferrer">docs</a>). Since you used the <code>Set</code> statement, the variable <code>uacResult</code> is an object reference (more on that later). When you call the <code>Item</code> method on the <code>Dictionary</code>, it is actually looking for key that matches the object reference, instead of searching for the string as you expected. <code>CStr()</code> corrects that by explicitly converting the object reference to a string.</p> <p>Since you used the <code>Set</code> keyword in its assignment, <code>uacResult</code> ends up containing a reference to a <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms677568%28v=vs.85%29.aspx" rel="nofollow noreferrer"><code>Field</code></a> object, since the default property of the <code>Recordset</code> object is the <code>Fields</code> collection. When you call <code>CStr(uacResult)</code>, this is converting the object to a string by calling the default property of the <code>Field</code> object, which is the <code>Value</code> property. You could achieve the same effect in a few different ways:</p> <pre class="lang-vb prettyprint-override"><code>' method 1 - from accepted answer (https://stackoverflow.com/a/17786308/249624) set uacResult = objRS("userAccountControl") Response.Write uac.Item(CStr(uacResult)) ' method 2 - explicitly using the Value property set uacResult = objRS("userAccountControl") Response.Write uac.Item(uacResult.Value) ' method 3 - make uacResult a string instead of a Field object uacResult = objRS("userAccountControl") Response.Write uac.Item(uacResult) ' method 4 - same as method 3, but explicitly use the Value property uacResult = objRS("userAccountControl").Value Response.Write uac.Item(uacResult) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload