"Scripting. Dictionary"

 
Napisz nowy temat   Odpowiedz do tematu    Forum Naukowe Koło Chemików Uniwersytetu Gdańskiego Strona Główna -> Imprezy naukowe
Zobacz poprzedni temat :: Zobacz następny temat  
Autor Wiadomość
tods5eshoes
Ununokt



Dołączył: 23 Lut 2011
Posty: 18577
Przeczytał: 0 tematów

Ostrzeżeń: 0/5
Skąd: England

PostWysłany: Sob 10:47, 12 Mar 2011    Temat postu: "Scripting. Dictionary"

[link widoczny dla zalogowanych],[link widoczny dla zalogowanych],[link widoczny dla zalogowanych],article2812,[link widoczny dla zalogowanych],[link widoczny dla zalogowanych],[link widoczny dla zalogowanych]Create_the Thesaurus Thing.... You should Take into account | ANY Computers-and-Technology Write-up
,article2812
Okay, I am going to confess Now i'm a lover with the Assortment. An individual both really like or perhaps dislike a selection. Those who hate the particular Assortment will most likely decide on a Assortment as an alternative. Some other dialects carry out supply a awesome thing referred to as any Thesaurus or perhaps Hash Stand. That is being a Assortment in which acts being a Assortment along with a selection together with several added helpful strategies. VBA won't have this kind of yet VBScript can supply a Thesaurus thing, which can be great, and also we could utilize this thing in your VBA surroundings. To create any thesaurus thing carry out these:
Dim my_dictionary since Object
Set my_dictionary = CreateObject ("Scripting. Dictionary")
Voila! We've any thesaurus. Exactly what do we all carry out from it? We could increase things, search for the particular lifestyle regarding things, go back numerous tips, go back numerous things, established what sort of thesaurus analyzes tips and acquire the particular rely etc. An illustration:
'First generate the particular Thesaurus Object
Dim my_dictionary since Object
Set my_dictionary = CreateObject ("Scripting. Dictionary")
'When incorporating a great thing or perhaps benefit with a thesaurus an individual set the main element initial as well as the genuine benefit or perhaps thing next. The main element will be obligatory and you also can not increase things with out that.
my_dictionary. Increase "Key 1", "Value 1"
my_dictionary. Increase "Key 2", "Value 2"
my_dictionary. Increase "Key 3", "Value 3"
my_dictionary. Increase "Key 4", "Value 4"
So today we now have extra several beliefs for the thesaurus. Why don't we carry out several items we all can not carry out cleanly or perhaps in any way using a Assortment. Point out we should change "Value 3" with all the identify "Zebra". Also effortless!
my_dictionary. Item("Key 3") = "Zebra"
You could hardly accomplish that using a assortment! In the assortment an individual will have to eliminate a single merchandise and also increase one more, hence shedding the particular buy or perhaps the things. ANY thesaurus acts such as an Assortment on this value. Imagine if we all are not positive there was clearly an integral referred to as "Key 3" inside thesaurus and also wished to steer clear of one. Once more, effortless, we all merely utilize the Is out there way of the particular thesaurus thing:
if my_dictionary. Exists("Key 3") then
my_dictionary. Item("Key 3") = "Zebra"
else
my_dictionary. Increase "Key 3", "Zebra"
end if
We should discover how several things come in the particular thesaurus, merely utilize the Rely approach which usually matches usually the one in the assortment.
MsgBox my_dictionary. Count
If you would like to iterate from the things in the thesaurus, you can not utilize a great integer countertop when you would certainly a selection or perhaps Assortment yet you need to use a couple of strategies to take action:
'You can easily merely seize those items from your thesaurus just like thus:
Dim things since Variant
items = my_dictionary. Items
'Iterate from the selection of things. These products may include things aswell.
Dim separate_item since Variant
For Each and every separate_item inside items
MsgBox separate_item
Next separate_item
'Or it is possible to remove the particular tips and also iterate from the things (which will be one more edge more than a Assortment that will not offer you it really is tips or perhaps tell you just what they will are)
Dim tips since Variant
keys = my_dictionary. Keys
'Iterate from the selection of things. These products may include things aswell.
Dim important since Variant
For Each and every type in keys
MsgBox my_dictionary. Item(key)
Next key
Too effortless! To eliminate something or perhaps almost all things you need to use Eliminate and also RemoveAll respectively:
my_dictionary. Remove("Key 2")
Or
my_dictionary. RemoveAll
These will be the essentials. I am going to go through the CompareMode approach inside not minuto. The particular Thesaurus thing can be a genuine edge any time we must develop an accumulation Choices or even a School Assortment. As an example; point out there were to get info about spys and also their particular existing tasks. Typically we all will have to develop a School Thing referred to as Criminal and also keep an exclusive or perhaps Community Assortment inside school to be able to which usually we might increase their particular tasks. A single school way too many (A Assortment can be a Class)! Why don't we work with a Thesaurus as an alternative...
Dim my_dictionary Since Thing Gray tasks Since Assortment Gray spy_name Since Stringed Gray tips, important Since Alternative Established my_dictionary = CreateObject("Scripting. Dictionary")
'Add a few a lot of agents.
Set tasks = Fresh Collection
spy_name = "Alexander Poligraphovich"
missions. Increase "Vladivostok"
missions. Increase "Ukraine"
missions. Increase "Beijing"
my_dictionary. Increase spy_name, missions
spy_name = "Mohammed Ramadan"
Set tasks = Fresh Collection
missions. Increase "Munich"
missions. Increase "Tehran"
missions. Increase "Sydney"
my_dictionary. Increase spy_name, missions
spy_name = "Sri FitzPatrick"
Set tasks = Fresh Collection
missions. Increase "Dublin"
missions. Increase "San Francisco"
my_dictionary. Increase spy_name,article2812, missions
keys = my_dictionary. Keys
For Each and every type in Keys
MsgBox important & vbCrLf & _
my_dictionary(key). item(1) & vbCrLf & _
my_dictionary(key). item(2) & vbCrLf & _
my_dictionary(key). item(3)
Next key
The CompareMode approach allows you to established how a thesaurus analyzes it really is tips any time trying to find replicates and so forth. You can find four-compare methods vbBinaryCompare, vbTextCompare, vbDatabaseCompare (for MILLISECONDS Accessibility only) and also vbUseCompareOption (which makes use of the particular establishing inside the Alternative Examine assertion near the top of any module). How do we all utilize this? Point out we all increase a couple of beliefs with all the Tips regarding goof and also MONKEY' a single in every lowercase as well as the some other in every uppercase.
my_dictionary. Increase "monkey", "Giraffe"
my_dictionary. Increase "MONKEY", "Elephant"
MsgBox my_dictionary. Count
The MsgBox can present something rely regarding a couple of, as the a couple of tips are usually fundamentally diverse. The particular thesaurus will be executing any binary evaluation after the particular tips in order to increase multiple 'monkey' provided that they've got several variation inside persona circumstance. Imagine if we all needed the phrase goof in every regarding it really is varieties being in contrast simply by identify rather than articles? Put simply we all will not need multiple 'monkey' inside the thesaurus. We all utilize CompareMode vbTextCompare:
my_dictionary. CompareMode = vbTextCompare
my_dictionary. Increase "monkey", "Giraffe"
my_dictionary. Increase "MONKEY", "Elephant"
MsgBox my_dictionary. Count
On this kind of illustration we all will not also arrive at the particular Msgbox, as an alternative we all acquire one proclaiming "This Important is connected with some this kind of assortment. inches. This kind of prevents a couple of tips getting extra who have the identical identify. vbBinaryCompare acts the identical approach because the initial illustration can (it could be the default) and also vbDatabaseCompare.... Properly MY PARTNER AND I examine just what that would when rather than were required to bear in mind that once more! You will find information regarding these kinds of, even though extremely to the point, inside MILLISECONDS Aid in Accessibility, or perhaps on top of that Yahoo that.
Hopefully this provides an individual a supplementary application along with the particular Assortment or perhaps Assortment and several tips about upcoming utilize. ANY Thesaurus tends to make program code construction clean plus more humanly clear. This kind of VBScript application can actually pay out payouts.
.topics related articles:


[link widoczny dla zalogowanych]

[link widoczny dla zalogowanych]

[link widoczny dla zalogowanych]


Post został pochwalony 0 razy
Powrót do góry
Zobacz profil autora
Wyświetl posty z ostatnich:   
Napisz nowy temat   Odpowiedz do tematu    Forum Naukowe Koło Chemików Uniwersytetu Gdańskiego Strona Główna -> Imprezy naukowe Wszystkie czasy w strefie EET (Europa)
Strona 1 z 1

 
Skocz do:  
Możesz pisać nowe tematy
Możesz odpowiadać w tematach
Nie możesz zmieniać swoich postów
Nie możesz usuwać swoich postów
Nie możesz głosować w ankietach


Bluetab template design by FF8Jake of FFD
fora.pl - załóż własne forum dyskusyjne za darmo
Powered by phpBB © 2001, 2002 phpBB Group
Regulamin