想請問變數mschool,要怎麼跟mschList中的資料四筆資料
我是用陣列將四筆資料寫到mschList,可是會發生錯誤
會出現Microsoft VBScript 執行階段錯誤 錯誤 '800a000d'
型態不符合: 'mschList'
/EELab2018/regist_cmf.asp, 行57
那mschool如果比對"540301", "573301", "553301", "120319"其中一筆
tpay=1600
mschool如果比對"540302"
tpay=1400
mschool 其他
tpay=2000
要怎麼寫語法呢? 謝謝
<%
'mschList="540301"
mschList= Array("540301", "573301", "553301", "120319")
if instr(mschList,mschool) > 0 then
tpay=1600
else
tpay=2000
end if
%>
<%
'mschList="540301"
mschList= Array("540301", "573301", "553301", "120319")
for each mm in mschList
select case mm
case "540301"
tpay=1100
case "540302"
tpay=1400
case else
tpay=2000
end select
next
%>
你自己都說他是「陣列」了
就不該使用 InStr -> InString
而該使用 In Array
ASP 沒有 InArray 函數
就看別人寫的 In Array
<%
'mschList="540301"
mschList= Array("540301", "573301", "553301", "120319")
if in_array(mschool, mschList, false) then
tpay=1600
else
if mschool="540302" then
tpay = 1400
else
tpay=2000
end if
end if
Function in_array(element, arr, performTrim)
Dim i
in_array = False
For i=0 To Ubound(arr)
If performTrim Then '//there are some scenarios where you want to trim
If Trim(arr(i)) = Trim(element) Then
in_array = True
Exit Function
End If
Else '//and other scenarios where you don't
If arr(i) = element Then
in_array = True
Exit Function
End If
End If
Next
End Function
%>