About through the VBS class processing template to achieve code and interface separation procedures, recommended into the essence for future reference. Have a demo

Source: Internet
Author: User
Tags array variables reference
Program | essence | Template Article title: VBS class processing template implementation code and interface separation
' Author: Yanek
' Email:aspboy@263.net

This program through the VBS class processing template to achieve code and interface separation of the program, mainly the following file composition
Index.asp,parse_cls.asp,template.html
Here is the code

1. Index.asp call the VBS class process template

<%
' Author: Yanek
' Email:aspboy@263.net

'---  ---
' Index.asp
'------  ----
' (c) James Q. Stansfield (james.stansfield@iridani.com)
' This code was free for use by anyone. It is meant as a learning tool and can are passed along in any format.
Option Explicit
%>
<!--#INCLUDE file= "parse_cls.asp"-->
<%
' Declare Our variables
Dim G_opagegen
' Cerate the Class object
Set G_opagegen = New Parsetmpl
' Set the template file
G_opagegen.templatefile = "Template.html"
' Add Some custom tags to the dictionary
G_opagegen.addtoken "title", "Template Example"
G_opagegen.addtoken "Copyright", "This is mine! All mine! "
G_opagegen.addtoken "Quote", "" "" Tell Jabba I ' ve got his money! "" <br>--han Solo, Star Wars 1977 "
G_opagegen.addtoken "Menu", "Home page<br>news page<br>link Page"
G_opagegen.addtoken "Content", "Welcome to my home Page ... yadda yadda yadda! "
' Generate the page
G_opagegen.generatehtml
' Destroy our objects
Set G_opagegen = Nothing
%>



2. Parse_cls.asp Processing template class files

<%
' Author: Yanek
' Email:aspboy@263.net

'---  ---
' Parse_cls.asp
' This code was free for use by anyone. It is meant as a learning tool and can are passed along in any format.
Class Parsetmpl
' Dimension variables
Private G_stmplfile
Private G_odict
Private G_bfile

Private Sub Class_Initialize
' Create the Scripting.Dictionary Object,
' Set the Compare mode to 1 ' It's case insensitive.
' Also flag A Boolean file so we know whether our file are there or not.
Set g_odict = CreateObject ("Scripting.Dictionary")
G_odict.comparemode = 1
G_bfile = FALSE
End Sub

Private Sub Class_Terminate
' Destroy our object.
Set g_odict = Nothing
End Sub

Public Property Let TemplateFile (InFile)
' A file & path must is specified for the routine to work.
G_stmplfile = Server.MapPath (inFile)
End Property

Private Property Get TemplateFile ()
TemplateFile = G_stmplfile
End Property

Public Sub Addtoken (Intoken, Invalue)
' This property allows us to set our tokens.
G_odict.add Intoken, Invalue
End Sub

Public Sub Generatehtml
' This is the ' main, and only public method of the class.
' This method would check whether we ' ve specified a file or not.
' Check for the ' files existance if we have specified it.
' If the file exists we'll open it and dumps it ' contents into an array.
' The array is split on VbCrLf to make it more manageable.
If Len (g_stmplfile) > 0 Then
Dim L_ofso, L_ofile, L_arrfile
Set L_ofso = CreateObject ("Scriptin



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.