STACK OPERATION USING CLASS MODULE



 AIM
          To perform stack operation using class module.

PROCEDURE

       Step 1: Create standard exe project.
           
       Step 2: Design the form with command buttons for each purpose
                    needed
            
       Step 3: Add a new class module to the project and write all the
                    functions, push, pop and display and declare it as public
        
       Step4: In the form code the functions from the class module are called
                    using the class variable

       Step 5: On the click event of the book  button the push function of the
                   class module is called.thus the user can enter an item  and its
                   count is displayed.this process is continued until the stack
                   becomes full.

      Step 6: On the click event of the delete button the pop function of the
                  class module is called.here the item will be deleted from the
                   tack until the stack becomes empty.

      Step 7: On the click event of  the exit button end the program.


SOURCE CODE:

Dim STACK As New Collection
Dim SIZE, items, a, i, q
Private Sub CLASS_INTIALIZE()
Set STACK = New Collection
End Sub
Private Sub CLASS_TERMINATE()
Set STACK = Nothing
End Sub

Public Sub PUSH()
SIZE = 5
If STACK.Count < SIZE - 0 Then
items = InputBox("Enter the Items")
STACK.Add (items)

Form1.List1.Clear
For i = STACK.Count To 1 Step -1
a = STACK.Item(i)
Form1.List1.AddItem (a)
Next i

Else
MsgBox ("The Stack is Full"), vbInformation
End If
End Sub
Public Sub pop()
If STACK.Count < 1 Then
MsgBox ("No Element to Display,Stack is Empty"), vbInformation
Else
i = STACK.Count
STACK.Remove (STACK.Count)
End If
Form1.List1.Clear
For i = STACK.Count To 1 Step -1
a = STACK.Item(i)
Form1.List1.AddItem (a)
Next i

End Sub
Public Sub display()
Form1.List1.Clear
For i = STACK.Count To 1 Step -1
a = STACK.Item(i)
Form1.List1.AddItem (a)
Next i
If STACK.Count < 1 Then
MsgBox ("No Element to Display,Stack is Empty"), vbInformation
End If
End Sub
Public Sub ex()
End
End Sub
SCREEN LAYOUT:


0 comments: