I have a classic ASP page, which includes a server side in the section
<!--#include file="../includes/DataTransferFunctions.asp"-->
Within this function, I have the following at the top of the library file,
Dim wsDataToXferArray()
and then, within one of the functions in the library, it does
redim preserve wsDataToXferArray(3,pSub).
This doesn’t work as I get a type mismatch on the redim statement. However, if I have the Dim statement at the top of the main ASP instead of at the top of the include library it works.
I need to be able to declare the variable in a global scope so that is it available to more than one function within the library, but have it so that it is defined within the library code so that it is self-contained. I feel as though I’m missing something obvious.
Thanks.
Here are cut-down versions which show the problem. I have included the main ASP and the relevant library which shows the location of the ‘2 Dim’ statements.
Thanks.
<%@ language = vbscript %>
<% Option Explicit %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%
Response.Buffer = true
Response.ContentType = "text/html"
Response.AddHeader "Content-Type", "text/html;charset=ISO-8859-1"
Response.CodePage = 1252
Response.CharSet = "ISO-8859-1"
Dim wsResult,wsDatabase
Dim wsSubX
'
'Dim wsDataToXferArray()
subRoutine()
'
'------------------------------------------------------------------------------------------------
sub subRoutine
'------------------------------------------------------------------------------------------------
wsSubX = 0
'
if wsResult = "" then wsResult = fncEnableSetAndCreateDataTransfer(wsDatabase,"LK-PART","abc","A",wsSubX) : wsSubX = wsSubX + 1
End Sub
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1" />
<title></title>
<%
SubIncludeOtherStyleSheets
SubIncludeJs
%>
<!--Include file containing functions to convert dates and to get sales order status description -->
<!--#include file="../includes/date_convert.asp"-->
<!--#include file="../includes/KHDataTransferFunctions.asp"-->
<!--#include file="../includes/IncludeStyleSheets.asp"-->
<!--#include file="../includes/IncludeJs.asp"-->
</head>
<body>
<form action="KHPartMaintenance.asp" method="post" name="form1" id="form1" >
<table class="tableForm Center Font7pt" width="1000">
<thead>
<tr>
<th colspan="5">Part Maintenance</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="submit" class="submit1" name="submit1" id="btnList" value="Get Part" onclick="javascript:return fncFormOnSubmit('Get');" /></td>
</tr>
</tbody>
</table>
</body>
</html>
This is the KHDataTransferFunctions.asp library.
<%
Dim wsDataToXferArray()
'------------------------------------------------------------------------------------------------
function fncEnableSetAndCreateDataTransfer(pDatabase,pName,pValue,pDataType,pSub)
'------------------------------------------------------------------------------------------------
'
Dim wsPrefix : wsPrefix = left(pName,2)
'
fncEnableSetAndCreateDataTransfer = ""
call subAddFieldToDataTransferArray(wsPrefix,pName,pValue,pDataType,pSub)
end function
'------------------------------------------------------------------------------------------------
sub subAddFieldToDataTransferArray(pPrefix,pName,pValue,pDataType,pSub)
'------------------------------------------------------------------------------------------------
'
' Build the array of the fields for each 'transaction'.
'
redim preserve wsDataToXferArray(3,pSub)
wsDataToXferArray(0,pSub) = pPrefix
wsDataToXferArray(1,pSub) = pName
wsDataToXferArray(2,pSub) = pValue
wsDataToXferArray(3,pSub) = pDataType
'
End Sub
%>
I’ve resolved the problem. It was caused by the position of the include files within the ASP page.
Here’s the revised code (well, part of it ….).
<%@ language = vbscript %>
<% Option Explicit %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%
Response.Buffer = true
Response.ContentType = "text/html"
Response.AddHeader "Content-Type", "text/html;charset=ISO-8859-1"
Response.CodePage = 1252
Response.CharSet = "ISO-8859-1"
%>
<!--Include file containing functions to convert dates and to get sales order status description -->
<!--#include file="../includes/date_convert.asp"-->
<!--#include file="../includes/KHDataTransferFunctions.asp"-->
<!--#include file="../includes/IncludeStyleSheets.asp"-->
<!--#include file="../includes/IncludeJs.asp"-->
<%
Dim wsResult,wsDatabase
Dim wsSubX
'
'Dim wsDataToXferArray()
subRoutine()
'
'------------------------------------------------------------------------------------------------
sub subRoutine
'------------------------------------------------------------------------------------------------
wsSubX = 0
'
if wsResult = "" then wsResult = fncEnableSetAndCreateDataTransfer(wsDatabase,"LK-PART","abc","A",wsSubX) : wsSubX = wsSubX + 1
End Sub
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1" />
<title></title>
<%
SubIncludeOtherStyleSheets
SubIncludeJs
%>
Problem was caused by the location of the server side include files. These need to be before the main ASP code gets executed, so that any global variables are declared early enough.
See the block with the modified code in the original post for the solution.