Function 功能:输入数组yourArray:"1","2",输出数组:arr1:"1_R","2_R",Function带数组参数,带返回值,我的程序为什么不对?

tata_1980 2003-04-12 04:37:47
<%

function returnarr(myArray())
dim arr(1)
i=0
for each arrEle in myArray
arr(i)=arrEle& "_T"
i=i+1
next
returnarr=arr
end function

dim yourArray(1)
yourArray(0)="1"
yourArray(1)="2"


arr1=returnarr(yourArray)

for each arr2 in arr1
response.Write arr1& "<br>"
next

%>
----------------------
调试时在
returnarr=arr 都过了
可到end function后就错了,奇怪呵


...全文
54 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
youbest 2003-04-13
  • 打赏
  • 举报
回复
dim list1Arr(3)



list1Arr(0)="R-3.00.cgf"

list1Arr(1)="R-3.01.cgf"

list1Arr(2)="R-3.02.cgf"

list1Arr(3)="R-3.03.cgf"

'dim list2Array()

list2Array=convertArray(list1Arr)

for each res in list2Array
Response.Write res & "<br>"
Next



function convertArray(listArray())

dim resultArr()
tgtInx=0

for each SourEle in listArray

tempData=del2Dot(SourEle)

flagCanInsert=1

for each TgtEle in resultArr
if tempData = TgtEle Then
flagCanInsert=0 '1 stands for can insert the source element to target array
End if
Next

if flagCanInsert=1 then
redim Preserve resultArr(tgtInx)
resultArr(tgtInx)=tempData
tgtInx=tgtInx+1
End if
next


convertArray=resultArr

End Function


function del2Dot(strWith2dot) 'del the 2 dot from rear of string
newStr=strWith2dot
for M=1 to 2
dotPosi=inStrRev(newStr,".")
newStr=left(newStr,dotPosi-1)

next
del2Dot=newStr

End Function
tata_1980 2003-04-13
  • 打赏
  • 举报
回复
问题解决:感谢 youbest(冲天飞豹)
原因:
dim list2Array()

list2Array=convertArray(list1Arr)中的dim list2Array()不应该要,我认为是因为这时定义的是一个动态数组,而不能用一个已知的数组直接赋值,youbest(冲天飞豹) ,对吗?

结帖
shanxing 2003-04-13
  • 打赏
  • 举报
回复
学习`~~~
tata_1980 2003-04-12
  • 打赏
  • 举报
回复
有点长,请不要注重细节
tata_1980 2003-04-12
  • 打赏
  • 举报
回复
你运行一下就知道,function convertArray(listArray())在结束之前一句还是对的,可end function以后,就错了.报错:类型不匹配
tata_1980 2003-04-12
  • 打赏
  • 举报
回复
谢谢,再看看这个
--------------

<%


dim list1Arr(3)



list1Arr(0)="R-3.00.cgf"

list1Arr(1)="R-3.01.cgf"

list1Arr(2)="R-3.02.cgf"

list1Arr(3)="R-3.03.cgf"

dim list2Array()

list2Array=convertArray(list1Arr)

for each res in list2Array
Response.Write res & "<br>"
Next



function convertArray(listArray())

dim resultArr()
tgtInx=0

for each SourEle in listArray

tempData=del2Dot(SourEle)

flagCanInsert=1

for each TgtEle in resultArr
if tempData = TgtEle Then
flagCanInsert=0 '1 stands for can insert the source element to target array
End if
Next

if flagCanInsert=1 then
redim Preserve resultArr(tgtInx)
resultArr(tgtInx)=tempData
tgtInx=tgtInx+1
End if
next


convertArray=resultArr

End Function


function del2Dot(strWith2dot) 'del the 2 dot from rear of string
newStr=strWith2dot
for M=1 to 2
dotPosi=inStrRev(newStr,".")
newStr=left(newStr,dotPosi-1)

next
del2Dot=newStr

End Function










%>
tata_1980 2003-04-12
  • 打赏
  • 举报
回复
这个是笔误啦
youbest 2003-04-12
  • 打赏
  • 举报
回复
<%

function returnarr(myArray())
dim arr(1)
i=0
for each arrEle in myArray
arr(i)=arrEle& "_T"
i=i+1
next
returnarr=arr
end function

dim yourArray(1)
yourArray(0)="1"
yourArray(1)="2"


arr1=returnarr(yourArray)

for each arr2 in arr1
response.Write arr2& "<br>"
next

%>
试试
tata_1980 2003-04-12
  • 打赏
  • 举报
回复
错误为:类型不匹配!
高手请指教

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧