3

我有一个经典的 ASP 页面,它在该部分中包含一个服务器端

<!--#include file="../includes/DataTransferFunctions.asp"-->

在这个函数中,我在库文件的顶部有以下内容,

  Dim wsDataToXferArray()

然后,在库中的一个函数中,它确实

 redim preserve wsDataToXferArray(3,pSub).

这不起作用,因为我在 redim 语句上得到类型不匹配。但是,如果我在主 ASP 的顶部而不是在包含库的顶部有 Dim 语句,它就可以工作。

我需要能够在全局范围内声明变量,以便库中的多个函数都可以使用它,但要让它在库代码中定义,以便它是自包含的。我觉得好像我错过了一些明显的东西。

谢谢。

这是显示问题的缩减版本。我已经包含了主要的 ASP 和显示“2 Dim”语句位置的相关库。

谢谢。

<%@ 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>

这是 KHDataTransferFunctions.asp 库。

<%
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

%>

我已经解决了这个问题。这是由包含文件在 ASP 页面中的位置引起的。

这是修改后的代码(嗯,它的一部分......)。

<%@ 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
%>
4

1 回答 1

1

问题是由服务器端包含文件的位置引起的。这些需要在主 ASP 代码执行之前进行,以便足够早地声明任何全局变量。

请参阅原始帖子中带有修改代码的块以获取解决方案。

于 2012-10-22T08:50:18.077 回答