Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 921351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:51:41+00:00 2026-05-15T18:51:41+00:00

In VBScript, some built in objects use an unnamed property. Some Examples: Set Dict

  • 0

In VBScript, some built in objects use an unnamed property. Some Examples:

Set Dict = Server.CreateObject("Scripting.Dictionary")
Set RS = GetEmloyeesRecordSet()

Dict("Beer") = "Tasty"  ' Same as Dict.Item("Beer") = "Tasty"
Dict("Crude Oil") = "Gross" ' Same as Dict.Item("Crude Oil") = "Gross"

Response.Write "The First Employee Is: " & RS("Name") ' Same as RS.Fields("Name")

How can I use this same syntax in my own classes?

UPDATE

Here is a working, stand-alone example of how to do this, a simple wrapper for Scripting.Dictionary. Note the use of “Let” to allow the d(“key”) = “value” syntax. Of course credit goes to Thom for providing the answer.

<%
Class DictWrapper
    Private Dict

    Private Sub Class_Initialize()
        Set Dict = Server.CreateObject("Scripting.Dictionary")
    End Sub 

    Private Sub Class_Terminate()
        Set Dict = Nothing
    End Sub 

    Public Property Get Count
        Count = Dict.Count
    End Property

    Public Default Property Get Item( Key )
        Item = Dict(Key)
    End Property

    Public Property Let Item( Key, Value )
        Dict(Key) = Value
    End Property

    Public Sub Add( Key, Value )
        Dict.Add Key, Value 
    End Sub 

End Class

Dim d : Set d = New DictWrapper
d.Add "Beer", "Good"
Response.Write d("Beer") & "<br>"
d("Beer") = "Bad"
Response.Write d("Beer")
%>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T18:51:42+00:00Added an answer on May 15, 2026 at 6:51 pm

    You need to declare a property of the class as the default property. As an example, here’s part of a String wrapper class I wrote:

    class StringClass
        private finished_
        private data_
        private size_
    
        public function init (val)
            finished_ = cStr(val)
            set init = me
        end function
    
        public default property get value
            if (size_ > 0) then
                finished_ = finished_ & join(data_, vbNullString)
                data_ = empty
                size_ = 0
            end if
            value = finished_
        end property
    
        public property let value (val)
            data_ = empty
            size_ = empty
            init(val)
        end property
    
        public function add (s)
            size_ = size_ + 1
            if (isEmpty(data_)) then
                redim data_(MIN_ARRAY_SIZE)
            elseif (size_ > uBound(data_)) then
                redim preserve data_(Float(uBound(data_) * GRANTED_HEAD_ROOM).ceil)
            end if
            data_(size_ - 1) = cStr(s)
        end function
    end class
    

    Usage:
    dim s: set s = new StringClass
    s()= “Hello, world!” ‘ s.value() = “Hello, world!”
    Response.Write s ‘ Response.Write s.value()

    You can also have a parametrized default property:

    class ListClass
        private size_
        private data_
    
        private sub CLASS_INITIALIZE
            size_ = 0
            data_ = Array()
            resize_array MIN_ARRAY_SIZE
        end sub
    
        public default property get data (index)
            if isObject(data) then
                set data_(index) = data
            else
                data_(index) = data
            end if
        end property
    
        public property let data (index, value)
            data_(index) = value
        end property
    
        public property set data (index, value)
            set data_(index) = value
        end property
    
        public function add(datum)
            size_ = size_ + 1
            if (size_ > uBound(data_) + 1) then expand_array
    
            assign data_(size_ - 1), datum
    
            add = datum
        end function
    end class
    
    dim l: set l = new ListClass
    l.add("Hello, world!")
    l(0) = "Goodbye, world!"
    Response.Write l(0)
    

    This second example is probably what you were looking for, using default properties to implement collections, but it’s worth checking out the first example, using default properties to implement auto-unboxing of wrapper classes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some vbscript code I use to set paths to virtual directories when
Do any browser vendors support the use of any scripting languages besides text/javascript text/vbscript
I came to some VBScript examples, and I saw the statement On Error Resume
I am creating a SQL Server integration package that requires some VBScript. Basically, every
I'm new to vbscript and Stack Overflow, and could really use some help. Currently
I don't have any experience programming with VBScript and I'd like to use some
Currently working on a VBScript to automate some of the dirty PST ingestion work
I am new to vbscript and while reading i found some code as Do
I am fixing a defect in some classic ASP using VBScript and I've come
I really need some quick tips here. I've got this VBScript script which sends

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.