iT邦幫忙

0

asp 比對資料

想請問變數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

%>

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

2 個回答

0
kyoe
iT邦新手 5 級 ‧ 2017-11-30 15:33:26
最佳解答
<%
'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
%>
0
海綿寶寶
iT邦大神 1 級 ‧ 2017-11-30 12:14:23

你自己都說他是「陣列」了
就不該使用 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
%>

我要發表回答

立即登入回答