由于我无法将.vb代码隐藏文件添加到我的.aspx页面中,如划定的here,我试图像这样添加方法“inline”(“ConvertSubcategoryIndex”函数是新的代码位):
<%
. . .
If Request.Form.Item("Action") = "Save" Then
. . .
.Parameters.Add("@Subcategory", SqlDbType.NVarChar).Value = ConvertSubcategoryIndex(Category, Subcategory)
. . .
End If 'If Save Action
Function ConvertSubcategoryIndex(_Category As String, _Subcategory As Int32) As String
If _Category = "New"
If _Subcategory = 0
Return "New"
End If
Else If _Subcategory = 1
Return "Assumed"
End If
End If
If _Category = "Existing"
If _Subcategory = 0
Return "Existing"
End If
Else If _Subcategory = 1
Return "Organic"
End If
End If
Return "Unknown"
End Function
%>
字符串
但这行不通,我得到了这个:
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30289: Statement cannot appear within a method body. End of method assumed.
Source Error:
Line 274: End If 'If Save Action
Line 275:
Line 276: Function ConvertSubcategoryIndex(_Category As String, _Subcategory As Int32) As String
Line 277: If _Category = "New"
Line 278: If _Subcategory = 0
Source File: C:\Users\cshannon\Source\Workspaces\CSReports\EnhancedMonthlySalesReporting\customerreportingnet\customerreportingnet\pages\custmaint_entry.aspx Line: 276
型
**注意:**无论我将函数放在上面还是下面,我都会得到这个 *End If 'If保存操作 *
更新
基于某人的别名(Noise),我尝试在顶部添加一个部分,代码如下:
. . .
</head>
<%
Function ConvertSubcategoryIndex(_Category As String, _Subcategory As Int32) As String
If _Category = "New"
If _Subcategory = 0
Return "New"
End If
Else If _Subcategory = 1
Return "Assumed"
End If
End If
If _Category = "Existing"
If _Subcategory = 0
Return "Existing"
End If
Else If _Subcategory = 1
Return "Organic"
End If
End If
Return "Unknown"
End Function
%>
<%
Unit = Request.QueryString.Item("Unit")
. . .
型
.但这没有什么区别;我仍然得到,“语句不能出现在方法体中。假定方法结束。”
更新2
即使使用tgolisch的改进代码:
Function ConvertSubcategoryIndex(_Category As String, _Subcategory As Int32) As String
If _Category = "New" Then 'really need a "Then" for every "If"
If _Subcategory = 0 Then
Return "New"
'End If 'this End If was killing the next line
ElseIf _Subcategory = 1 Then
Return "Assumed"
End If
End If
If _Category = "Existing" Then
If _Subcategory = 0 Then
Return "Existing"
'End If 'this one was causing problems too
ElseIf _Subcategory = 1 Then 'ElseIf can't have a space between Else If
Return "Organic"
End If
End If
Return "Unknown"
End Function
型
.我得到了和以前一样的err msg:
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30289: Statement cannot appear within a method body. End of method assumed.
Source Error:
Line 63: <%
Line 64: 'End Sub
Line 65: Function ConvertSubcategoryIndex(_Category As String, _Subcategory As Int32) As String
Line 66: If _Category = "New" Then 'really need a "Then" for every "If"
Line 67: If _Subcategory = 0 Then
Source File: C:\Users\cshannon\Source\Workspaces\CSReports\EnhancedMonthlySalesReporting\customerreportingnet\customerreportingnet\pages\custmaint_entry.aspx Line: 65
型
更奇怪的是,Visual Studio发现代码的第一行有问题,并提出了一个奇怪的建议,即我在那里添加一个“End Sub”:
x1c 0d1x的数据
我试过了,只是为了好玩,但正如人们所怀疑的那样,这在其他地方也犯了错误。
更新3
基于这两个答案(tgolisch修复了代码本身,Sam Axe展示了如何将其添加到混合中),它现在可以工作了。通过这些修复和对我的逻辑的修复,它的工作状态是:
<script runat="Server">
Function ConvertSubcategoryIndex(_Category As String, _Subcategory As String) As String
If _Category = "New Business" Then
If _Subcategory = "0" Then
Return "New"
ElseIf _Subcategory = "1" Then
Return "Assumed"
End If
End If
If _Category = "Existing Business" Then
If _Subcategory = "0" Then
Return "Existing"
ElseIf _Subcategory = "1" Then
Return "Organic"
End If
End If
Return "Unknown"
End Function
</script>
型
3条答案
按热度按时间az31mfrm1#
我已经很久没有做过WebForms了......但是如果我没记错的话,你需要使用这样的东西:
字符串
nbysray52#
您的VB.NET语法有几个语法错误。请尝试为您的
ConvertSubcategoryIndex()
函数粘贴以下代码:字符串
你可能还需要看看第一个例子顶部的代码质量,我不知道你把
...
放在哪里。qltillow3#
我现在有同样的问题,当我想显示日期值(从UNIX时间戳)与前导零纯VBScript.我定义了我的函数做一些格式化,但也收到BC30289编译器消息.然后我红了完整的编译器输出,喝了一杯咖啡,和.
字符串
这是一个有点丑陋,但它的工作。如果没有,检查你的ASP代码的父在编译器输出,并对齐。