---
title: "En Class som skapar en stack"
type: "forum-thread"
url: "https://www.webforum.nu/amne/asp/126260-en-class-som-skapar-en-stack"
topic: "ASP"
topic_url: "https://www.webforum.nu/amne/asp"
author: "Fraggel"
published: "2005-04-12T19:38:15.000Z"
updated: "2005-05-19T17:24:41.000Z"
replies: 5
views: 5364
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/asp/126260-en-class-som-skapar-en-stack"
---

# En Class som skapar en stack

## #1 — Fraggel, 2005-04-12T19:38Z

Om ni vill ha så bjuder jag på min dags förhöjare, detta räddade iallafall min dag. Skrev den på bussen på vägen hem efter att ha upptäkt ett behov av att ha en stack.

Vist är det kul att bli nöjd över så lite

```
Class cls_Stack
  Dim oStore
  Dim iStoreCount
  Public Property Get count()
     ' Antalet poster i stacken
    count = iStoreCount
  End Property
  
  Private Sub Initialize()
    ' Skapar en Dictionary
    Set oStore = Server.CreateObject("Scripting.Dictionary")
  End Sub

  Private Sub Terminate()
    ' Terminerar Dictionary
    oStore = Nothing
  End Sub
  
  Public Sub push(value)
    ' Lägger till överst i stacken
    If iStoreCount=0 Then
      Initialize()
    End If
    iStoreCount = iStoreCount + 1
    oStore(iStoreCount) = value
  End Sub
  
  Public Function pop()
    If iStoreCount<1 Then
      pop = "#Error# Stack is empty!"
      Exit Function
    End If
    pop = oStore(iStoreCount)
    oStore.Remove(iStoreCount)
    iStoreCount = iStoreCount -1
    If iStoreCount < 1 Then
      Terminate()
    End If
  End Function
End Class
```

Permalänk: https://www.webforum.nu/p/126260

## #2 — syclonen, 2005-04-12T19:47Z

Synd man inte begriper \*S\*

Permalänk: https://www.webforum.nu/p/1591063

## #3 — Fraggel, 2005-04-12T19:49Z

En stack!
Sist in först ut...

Push läger till i stacken
Pop hämtar ut och raderar värdet i stacken...

```
  Dim myClass
  Set myClass = New cls_Stack
  
  myClass.Push("Test")
  myClass.Push("Test1")
  myClass.Push("Test2")
  myClass.Push("Test3")
  myClass.Push("Test4")
  myClass.Push("Test5")
  myClass.Push("Test6")
  Response.Write myClass.count & "<br>"
  Response.Write myClass.Pop & "<br>"
  Response.Write myClass.count & "<br>"  
  Response.Write myClass.Pop & "<br>"
  Response.Write myClass.count & "<br>"
  Response.Write myClass.Pop & "<br>"
  Response.Write myClass.count & "<br>"
  Response.Write myClass.Pop & "<br>"
  Response.Write myClass.count & "<br>"
```

Permalänk: https://www.webforum.nu/p/1591067

## #4 — OveRRidE, 2005-04-13T06:05Z

Flyttas från ASP.

Permalänk: https://www.webforum.nu/p/1591175

## #5 — Fraggel, 2005-04-13T21:21Z

```
Class cls_Stack
  '
  ' 
  ' Property:
  '   SizeOfStack  ; Returns number of items in stack
  ' Methods:
  '   Push()       ; Adds new value to stack
  ' Events:
  '   Pop          ; Retrives value from stack
  '   Kill         ; Kills and resets stack 
  '
  
  Dim oStore
  Dim iStoreCount
  
  Public Property Get SizeOfStack()
    If iStoreCount<1 Then
      SizeOfStack = 0
    Else
      SizeOfStack = iStoreCount
    End If
  End Property
  
  Private Sub Initialize()
    Set oStore = Server.CreateObject("Scripting.Dictionary")
  End Sub

  Private Sub Terminate()
    If oStore Is Nothing Then
      Exit Sub
    Else
      iStoreCount = 0
      Set oStore = Nothing
    End IF
  End Sub
  
  Public Sub push(value)
    If iStoreCount="" Then
      Initialize()
    End If
    iStoreCount = iStoreCount + 1
    oStore(iStoreCount) = value
  End Sub
  
  Public Sub Kill()
    iStoreCount = ""
    Terminate()
  End Sub
  
  Public Function pop()
    If iStoreCount<1 Then
      pop = "#Error# Stack is empty!"
      Exit Function
    End If
    pop = oStore(iStoreCount)
    oStore.Remove(iStoreCount)
    iStoreCount = iStoreCount -1
    If iStoreCount<1 Then
      Terminate()
    End If
  End Function
End Class
```

Lite bättre
Krachar inte när man popar en tom stack mer än en gång

Permalänk: https://www.webforum.nu/p/1591672

## #6 — Compusa, 2005-05-19T17:24Z

\*

Permalänk: https://www.webforum.nu/p/1614557

---

Tråden på webben: https://www.webforum.nu/amne/asp/126260-en-class-som-skapar-en-stack
