powered by simpleCommunicator - 2.0.59     © 2025 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Visual Basic [игнор отключен] [закрыт для гостей] / Коллекции и структуры в VB Script
6 сообщений из 6, страница 1 из 1
Коллекции и структуры в VB Script
    #33040330
Anton.
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Люди, помогите!!!
Как создать коллекцию в VB Script?

Чтобы можно было делать так:
Код: plaintext
1.
2.
3.
4.
  MyCollection.Add(Element)
  MyCollection.Remove(Element)
  ' и так
  For Each Elm in MyCollection ......

Как создать структуру в VB Script?

Чтобы можно было делать так:
Код: plaintext
1.
2.
3.
  MyStruct.Name = "Vasya"
  MyStruct.Age =  23 
..........

Можно ли сделать что-то подобное?
...
Рейтинг: 0 / 0
Коллекции и структуры в VB Script
    #33040454
Processor
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Единственное, что просматривается: script56.chmDictionary Object
See Also
FileSystemObject Object | TextStream Object
Language
JScript

VBScript

Show All
Object that stores data key, item pairs.

Remarks
A Dictionary object is the equivalent of a PERL associative array. Items can be any form of data, and are stored in the array. Each item is associated with a unique key. The key is used to retrieve an individual item and is usually a integer or a string, but can be anything except an array.

The following code illustrates how to create a Dictionary object:
Dim d ' Create a variable.
Set d = CreateObject("Scripting.Dictionary")
d.Add "a", "Athens" ' Add some keys and items.
d.Add "b", "Belgrade"
d.Add "c", "Cairo"
...
Methods
Add Method (Dictionary) | Exists Method | Items Method | Keys Method | Remove Method | RemoveAll Method
...
Рейтинг: 0 / 0
Коллекции и структуры в VB Script
    #33040528
Anton.
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Спасибо попробую так сделать
...
Рейтинг: 0 / 0
Период между сообщениями больше года.
Коллекции и структуры в VB Script
    #36824983
Katsy
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Processor,

У меня не работает вот такая конструкция:
Код: plaintext
dictClients.Remove ("SomeText")
Справки по методу remove в моем 2007 экселе я не нахожу. Подскажите, пожалуйста, в чем косяк, или выложите справку по методу.

Если быть точнее, то:
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
Dim dictClients
Set dictClients = CreateObject("Scripting.Dictionary")

   ...        
    Application.ScreenUpdating = False
    While AL.Cells(I,  5 ) <> ""
        Application.StatusBar = "Обработка записи " & I
        'Add to dictionary
        dictClients.Add AL.Cells(I,  5 ), I
        X =  7 
        Do While PL.Cells(X,  5 ) <> ""
            If AL.Cells(I,  5 ) = PL.Cells(X,  5 ) Then
                'Remove from dictionary
                [color=red]dictClients.Remove (AL.Cells(I,  5 ))[/color]
                Exit Do
            End If
            X = X +  1 
        Loop
        I = I +  1 
    Wend
    Application.ScreenUpdating = True
...
Рейтинг: 0 / 0
Коллекции и структуры в VB Script
    #36824998
Katsy
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Нашла в тырнете Dictionary.Remove Method (VB6)
Named Arguments
Yes
Syntax
dictionaryobject.Remove key
dictionaryobject
Use: Required
Data Type: Dictionary object
A reference to a Dictionary object.
key
Use: Required
Data Type: String
The key associated with the item to be removed.
Description
Removes both the specified key and its associated data (i.e., its item) from the
dictionary.
Rules at a Glance
If key doesn’t exist, runtime error 32811, “Method ‘Remove’ of object ‘IDictionary’
failed,” occurs.
Теперь у меня:
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
    Application.ScreenUpdating = False
    While AL.Cells(I,  5 ) <> ""
        Application.StatusBar = "Обработка записи " & I
        'Add to dictionary
        dictClients.Add I, AL.Cells(I,  5 )
        X =  7 
        Do While PL.Cells(X,  5 ) <> ""
            If AL.Cells(I,  5 ) = PL.Cells(X,  5 ) Then
                'Remove from dictionary
                dictClients.Remove I
                Exit Do
            End If
            X = X +  1 
        Loop
        I = I +  1 
    Wend
    Application.ScreenUpdating = True
Работает. Остается вопрос. Как показать содержимое словаря?
...
Рейтинг: 0 / 0
Коллекции и структуры в VB Script
    #36825136
Katsy
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Код: plaintext
1.
2.
3.
4.
5.
    Dim vArray As Variant
    vArray = dictClients.Items
    For I =  0  To dictClients.Count -  1 
        MsgBox vArray(I)
    Next I
Вот так вывожу
...
Рейтинг: 0 / 0
6 сообщений из 6, страница 1 из 1
Форумы / Visual Basic [игнор отключен] [закрыт для гостей] / Коллекции и структуры в VB Script
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]