This topic is locked

Where to put custom code in 5.1

6/6/2008 10:29:04 AM
ASPRunnerPro General questions
M
mfred author

A number of my applications need the add form to generate, display and submit an automatic number. In version 4, I used counter code to accomplish this. But version 5.1 code is so different, I am unsure where to put the code or even if the method used in 4 can be done in 5.1. Below is sample code for what I was doing in 4:
All code was inserted in the add.asp.

Just below <%@ Language=VBScript %>, I insert:
<%

' Visit Counter

' FELIXONE 2002 - SB by Felice Di Stefano - www.felixone.it

Dim FX_count

Dim FX_digit

FX_digit = 1

Dim FX_dpath

FX_dpath = Server.MapPath("../FX_DataCounter")

Dim FX_fpath

FX_fpath = Server.MapPath("../FX_DataCounter/counter.txt")

set FX_fso = Server.CreateObject("Scripting.FileSystemObject")

' Check if directory and file exists, if not create it.

If (Not FX_fso.fileExists(FX_fpath)) Then

If (Not FX_fso.folderExists(FX_dpath)) Then

FX_fso.CreateFolder(FX_dpath)

End If

Application.Lock()

set FX_file = FX_fso.OpenTextFile(FX_fpath, 8, true)

FX_file.write(0)

FX_file.Close()

Application.Unlock()

End If

' Read file and update it any time

set FX_fobj = FX_fso.getfile(FX_fpath)

set FX_file = FX_fobj.OpenAsTextStream(1,-2)

FX_count = FX_file.Read(100)

'If (Session("FX_DataCounter") = "") Then

Application.Lock()

set FX_file = FX_fso.CreateTextFile(FX_fpath, 8, false)

FX_file.write(FX_count+1)

FX_file.Close()

Application.Unlock()

set FX_fso = nothing

FX_count = FX_count+1

' Session("FX_DataCounter") = FX_count

'End If

' Add leadings

FX_numlength = Len(cStr(FX_count))

If (FX_numlength < FX_digit) Then

FX_lead = cInt(FX_digit - FX_numlength)

For i=1 To FX_lead

FX_count = "0" & FX_count

Next

End If

%>
Then I replace the ASPRunner code for the number field with:



<span class="style1">Call Ticket Number:</span>

<input name="CallTicketNumber" type="text" id="CallTicketNumber" value="SC<%=FX_count%>">


or
<input name="CallTicketNumber" type="hidden" id="CallTicketNumber" value="SC<%=FX_count%>">
According to whether or not the field needs to be displayed on the form.