2012-10-19 64 views
3

範圍我有一個傳統的ASP頁面,其中包括在部分ASP的VBScript REDIM保留類型不匹配 - 變量定義

<!--#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 
%> 
+0

你可以顯示一些代碼,我試圖測試你的設置,並沒有得到任何錯誤.. – SearchAndResQ

+0

你能證明pSub是體面的,如果類型不匹配的錯誤? –

+0

wsSubX = 0 您正在嘗試redim array(3,0) – SearchAndResQ

回答

1

問題是由服務器端包含文件的位置引起的。這些需要在主ASP代碼執行之前完成,以便任何全局變量都足夠早地被聲明。

請參閱解決方案原始文章中修改代碼的塊。