【发布时间】:2025-12-09 17:35:02
【问题描述】:
我有这个函数来搜索一个值是否通过数组存在。这是我的功能:
Function in_array(iCountryID, iCountryArray)
in_array = False
For i=0 To Ubound(iCountryArray)
If iCountryArray(i) = iCountryID Then
in_array = True
Exit Function
End If
Next
End Function
ThisCountry = iCountryID
CountryArray = Array(99,115,218,305)
If in_array(ThisCountry, CountryArray) Then
Response.Write ThisCountry & " is in the array"
Else
Response.Write ThisCountry & " is not in the array"
End If
这很好用。我的问题是我的数组 (99,115,218,305) 中的值是动态的。我有一个通过查询创建该值的变量。
iCountryArray 是我的变量,它存储值 99,115,218,305。因此,我需要动态添加它们,而不是手动将这些值输入到我的数组中。
这不起作用:
CountryArray = Array(" & iCountryArray & ")
【问题讨论】:
-
这是 Visual Basic 吗?
-
iCountryArray到底是什么?是字符串吗? -
@melpomene
response.write的出现和函数中缺少类型表明我们正处于经典 ASP 中。而 iCountryArray 是一个数字数组。 -
@VanquiishedWombat 我不知道 ASP 是什么。我只是在寻找更好的标签。 :-)
-
哦,好的。那么 VBScript 和 asp-classic 是合适的。数组是边界,if 语句不合适。
标签: arrays vbscript asp-classic