What is a Collection object in asp using vbscript?

The collection has something in common with Dictionary in VBScript, but it's not the same thing.

A collection is an object, for example, the Session.Contents property.

A dictionary is an object created using the following code.

Dim dictObj
Set dictObj = CreateObject("Scripting.Dictionary")

I want to find the differences and general information with these two types of objects in order to know how to use them.

I found these useful articles, but still do not clearly understand that the collection is really in asp using VBScript.

Work with collections

Using Dictionary Class in VBA

My questions:

  • Is there a collection data type in VBScript? you can create a dictionary, but you cannot create a collection object.

  • When a loop through a collection uses For Each, what is x, the collection key, or the value of the collection item?

    for each x in Session.Contents
    
  • Why can you use the collection in this way?

    Session("FirstName")
    

    Session.Contents("FirstName")
    
  • ?

    , , this

, , , , . .

+4
1

VBScript?

. . VB, VBScript . VBS, . Scripting.Dictionary, .

For Each, x, ?

For Each . . ( , for-each, , .)

Dim key, val

For Each key In Session.Contents
    val = Session(key)
    Response.Write Server.HtmlEncode(key) & " = " & Server.HtmlEncode(val) & "<br>"
Next

?

Session("FirstName")

Session Contents. Item.

- , , , .

:

Session("FirstName") = "Foo"
Response.Write( Session("FirstName") & "<br>" )

Session.Contents("FirstName") = "Bar"
Response.Write( Session.Contents("FirstName") & "<br>" )

Session.Contents.Item("FirstName") = "Baz"
Response.Write( Session.Contents.Item("FirstName") & "<br>" )

- , , - . Session.Contents , . , .

?

Microsoft , VB 6.0, , . - Office VBA.

IIS, ASP. : ASP.

+7

Source: https://habr.com/ru/post/1677627/


All Articles