Code Examples
  Home arrow Code Examples arrow Page 2 - Adding Methods to Custom Class Objects in ...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
CODE EXAMPLES

Adding Methods to Custom Class Objects in VBScript
By: Nilpo
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 2
    2009-03-17

    Table of Contents:
  • Adding Methods to Custom Class Objects in VBScript
  • Adding methods to a class
  • Completing the class
  • Implementing our new class

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Adding Methods to Custom Class Objects in VBScript - Adding methods to a class


    (Page 2 of 4 )

    As you can see, methods inside of a class are no different from the functions and subroutines you write in your scripts every day.  Here’s the full list of methods used by the CompressedFolder class.

       Public Sub Open(strFile)

           FullName = strFile

       End Sub

     

       Public Sub Create(strFile)

           If objFso.FileExists(strFile) Then objFso.DeleteFile(strFile)

           FullName = strFile

           NewCompressedFolder FullName

       End Sub

     

       Private Sub NewCompressedFolder(strPath)

           Const adTypeBinary = 1

           Const adTypeText = 2

           Const adWriteChar = 0

           Const adSaveCreateNotExist = 1

           Const adSaveCreateOverwrite = 2

     

           With CreateObject("ADODB.Stream")

              .Open

              .Type = adTypeText

              .WriteText ChrB(&h50) & ChrB(&h4B) & ChrB(&h5) & ChrB(&h6)

              For i = 1 To 18

                  .WriteText ChrB(&h0)

              Next

              .SaveToFile strPath, adSaveCreateNotExist

              .Close

              .Open

              .Type = adTypeBinary

              .LoadFromFile strPath

              .Position = 2

              arrBytes = .Read

              .Position = 0

              .SetEOS

              .Write arrBytes

              .SaveToFile strPath, adSaveCreateOverwrite

              .Close

           End With

       End Sub

     

       Public Sub Add(strFile, blnKeepOriginal)

           AddFile FullName, strFile, blnKeepOriginal

       End Sub

     

       Private Function AddFile(strFolder, strFile, blnKeepOriginal)

           Set objFolder = objShell.NameSpace(strFolder)

           intCount = objFolder.Items.Count

           Select Case CBool(blnKeepOriginal)

              Case True

                  objFolder.CopyHere strFile, 1548

              Case False

                  objFolder.MoveHere strFile, 1548

           End Select

           Do Until objFolder.Items.Count = intCount + 1

              Sleep 200

              If Not ShellBusy Then Exit Do

           Loop

       End Function

     

       Public Sub AddMultiple(varSource, blnKeepOriginal)

           AddFiles FullName, varSource, blnKeepOriginal

       End Sub

     

       Private Function AddFiles(strFolder, varSource, blnKeepOriginal)

           If IsArray(varSource) Then

              For Each strPath In varSource

                  AddFile strFolder, strPath, blnKeepOriginal

              Next

           Else

              Set colItems = objShell.NameSpace(strSource).Items

              intCount = .Items.Count

              Select Case CBool(blnKeepOriginal)

                  Case True

                     objShell.NameSpace(strFolder).CopyHere colItems, 1548

                  Case False

                     objShell.NameSpace(strFolder).MoveHere colItems, 1548

              End Select

              Do Until objShell.NameSpace(strFolder).Items.Count = intCount + colItems.Count

                  Sleep 200

                  If Not ShellBusy Then Exit Do

              Loop

           End If

       End Function

     

       Public Sub Extract(strFolder)

           ExtractAll FullName, strFolder

       End Sub

     

       Private Function ExtractAll(strZipFile, strFolder)

           If Not objFso.FolderExists(strFolder) Then objFso.CreateFolder(strFolder)

           intCount = objShell.NameSpace(strFolder).Items.Count

           Set colItems = objShell.NameSpace(strZipFile).Items

           objShell.NameSpace(strFolder).CopyHere colItems, 1548

           Do Until objShell.NameSpace(strFolder).Items.Count = intCount + colItems.Count

              Sleep 200

              If Not ShellBusy Then Exit Do

           Loop

       End Function

     

       Private Function GetItemCount(strZipFile)

           GetItemCount = objShell.NameSpace(strZipFile).Items.Count

       End Function

     

       Private Function ShellBusy()

           intStartSize = objFso.GetFile(FullName).Size

           Sleep 500

           ShellBusy = objFso.GetFile(FullName).Size > intStartSize

       End Function

     

       Private Sub Sleep(intDuration)

           'You must provide an applicable sleep routine for use in ASP.

           WScript.Sleep intDuration

       End Sub

    Take the time to see which ones are Private and which are Public.  Do you see how they relate to each other?  I’m using the exposed (Public) methods to call the internal (Private) methods.  For a further explanation of the inner workings of these functions, stayed tuned for my Understanding the CompressedFolder class series.

    More Code Examples Articles
    More By Nilpo


     

    CODE EXAMPLES ARTICLES

    - Bipartite Graphs
    - Connectivity in Graphs
    - The Ford-Fulkerson Algorithm
    - Critical Paths
    - The Bellman-Ford and Roy-Floyd Algorithms
    - Shortest Path Algorithms in Graphs
    - Minimum Spanning Tree
    - Articulation Edges and Vertexes
    - Circles and Connectivity in Graphs
    - Depth-First Search in Graphs
    - Breadth-First Search in Graphs
    - The Prufer Code and the Floyd-Warshall Algor...
    - An Insight into Graphs
    - Coding a Custom Object with WSC
    - Creating a Custom Object with WSC





    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek