Toon posts:

[asp] controleren of een item in de collectie staat

Pagina: 1
Acties:

Verwijderd

Topicstarter
Beste tweakers,

Ik heb in een asp pagina een collectie gemaakt;
Mijn vraag is hoe kan ik kijken of een item in de collectie bestaat, voordat ik hem verwijder?

code:
1
2
3
4
If MyCol.item("TestKey") then
   'als hij bestaat dan verwijderen
   MyCol.Remove("TestKey") 
end if


Zoiets wil ik hebben!

Alvast bedankt,

  • faabman
  • Registratie: Januari 2001
  • Laatst online: 08-08-2024
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
Exists Method
See Also
Add Method (Dictionary) | Items Method | Keys Method | Remove Method | RemoveAll Method
Applies To: Dictionary Object
Language
JScript

VBScript

Show All
Returns true if a specified key exists in the Dictionary object, false if it does not.

object.Exists(key)
Arguments
object 
Required. Always the name of a Dictionary object. 
key 
Required. Key value being searched for in the Dictionary object. 
Remarks
The following example illustrates the use of the Exists method. 

[JScript]
function keyExists(k)
{
   var fso, s = "";
   d = new ActiveXObject("Scripting.Dictionary");
   d.Add("a", "Athens");
   d.Add("b", "Belgrade");
   d.Add("c", "Cairo");
   if (d.Exists(k))
      s += "Specified key exists.";
   else 
      s += "Specified key doesn't exist.";
   return(s);
}
[VBScript]
Function KeyExistsDemo
   Dim d, msg   ' Create some variables.
   Set d = CreateObject("Scripting.Dictionary")
   d.Add "a", "Athens"   ' Add some   keys and items.
   d.Add "b", "Belgrade"
   d.Add "c", "Cairo"
   If d.Exists("c") Then
      msg = "Specified key exists."
   Else
      msg = "Specified key doesn't exist."
   End If
   KeyExistsDemo = msg
End Function


bron: windows scripting sdk

http://www.microsoft.com/...4099D7BBB9&displaylang=en

volgens mij bedoel je dit

[ Voor 11% gewijzigd door faabman op 23-08-2004 13:33 ]

Op zoek naar een baan als Coldfusion webdeveloper? Mail me!


  • zneek
  • Registratie: Augustus 2001
  • Laatst online: 08-02-2025
doe anders ff code ipv quote tags

Verwijderd

Topicstarter
Ik probeer het beter uit te leggen:

Ik heb mijn eigen CdagenCol classe waar ik objecten "dag" in stop met een key : datum. Bijv. "20041206"

Nu wil ik kijken of de dag in mijn collectie staat

code:
1
2
3
If dagenCol.Bestaat(datum) Then
     dagenCol.Remove (Datum)
End If


Ik weet niet of dit kan met Scripting.Dictionary , want ik weet niet hoe ik mijn dagenCol aan deze Scripting.Dictionary kan linken.

In visual basic 6 heb ik in mijn collecties altijd deze code staan:
code:
1
2
3
4
5
6
7
8
9
10
Public Function bestaat(vntIndexKey As Variant) As Boolean
On Error GoTo NEIT
    Dim tempItem As Cdag
    
    Set tempItem = mCol(vntIndexKey)
    bestaat = True
Exit Function
NEIT:
    bestaat = False
End Function


Ik wil dus in mijn eigen collectie kijken of het "dag"-object erin staat!

Thnx,

[ Voor 8% gewijzigd door Verwijderd op 23-08-2004 12:33 ]


  • klaasopurk
  • Registratie: Februari 2004
  • Laatst online: 22-05 18:21
wat je kan doen is een loopje maken en al je objecten afgaan

je kan namelijk van elk object het type opvragen en dan kijken of het jou object is
overigs kun je alles dan opvragen van een object (naam, grootte enz)

misschien lukt dit beter

een voorbeeld

foreach (System.Windows.Forms.Control aControl in this.Controls)
{
// Checks to see if the control being considered is a Textbox
// and if it contains an empty string
if (aControl is System.Windows.Forms.TextBox || aControl is System.Windows.Forms.RichTextBox)
{
aControl.BackColor = System.Drawing.SystemColors.Window;
if(aControl.Text.ToString() == "")
{
// If a textbox is found to contain an empty string, it is
// given the focus and the method is exited.
aControl.Focus();
aControl.BackColor = System.Drawing.Color.LightPink;
check = false;
}
}
}

Klaas


  • purge
  • Registratie: November 2000
  • Niet online
ASP:
1
2
3
4
5
6
7
8
9
dim guitars
set guitars=CreateObject("Scripting.Dictionary")
guitars.Add "e", "Epiphone"
guitars.Add "f", "Fender"
guitars.Add "g", "Gibson"
guitars.Add "h", "Harmony"
If guitars.Exists("g") Then
   guitars.Item("g") = "Guild"
End If 
Dan is er ook nog iets met guitars.Remove("g").
Met een beetje spelen met moet het vast wel lukken.

bron: http://www.devguru.com/Te...ef/dictionary_exists.html

[edit]
Hm Faabman schreef eigenlijk ook al zoiets ;)

[ Voor 23% gewijzigd door purge op 23-08-2004 23:43 ]


  • zneek
  • Registratie: Augustus 2001
  • Laatst online: 08-02-2025
purge schreef op 23 augustus 2004 @ 23:38:
ASP:
1
2
3
4
5
6
7
8
9
dim guitars
set guitars=CreateObject("Scripting.Dictionary")
guitars.Add "e", "Epiphone"
guitars.Add "f", "Fender"
guitars.Add "g", "Gibson"
guitars.Add "h", "Harmony"
If guitars.Exists("g") Then
   guitars.Item("g") = "Guild"
End If 
Dan is er ook nog iets met guitars.Remove("g").
Met een beetje spelen met moet het vast wel lukken.

bron: http://www.devguru.com/Te...ef/dictionary_exists.html

[edit]
Hm Faabman schreef eigenlijk ook al zoiets ;)
Daarnaast, www.devguru.com is je vriend, bookmark die site maar.

Verwijderd

ik gebruik altijd de volgende functie in VB, maar je kunt hem makkelijk aanpassen aan VBS

code:
1
2
3
4
5
6
function IsCollectionItem ( c as collection, item as string ) as boolean
  dim Temp as variant
  On Error Resume next
  Set temp = c(item)
  IsCollectionItem = ( err.number = 0)
end function
Pagina: 1