我怎么能做嵌套“如果“在Vbscript中? [英] How Can I Do Nested " If " In Vbscript ?

查看:64
本文介绍了我怎么能做嵌套“如果“在Vbscript中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

'a'是数组。我的数组是[0,1,0,0,1,0,0,0,0,1,0,1,0,1]



代码给出错误。我该怎么办呢?它的逻辑是否正确?逻辑:如果在
中为0和1,则写入x然后循环将在1之后继续。如果0和0因此,它写入y然后循环将在第一个0之后继续。





Hello
'a' is array. my array is [0,1,0,0,1,0,0,0,0,1,0,1,0,1]

code gives error. how can i fix it? And is its logic correct? logic: If 0 and 1 in
consequently, it writes x then loop will continue after 1. If 0 and 0 in consequently , it writes y then loop will continue after first 0.









<html>
<body>

<%


For Each x In a
If a(x) = 0 And  a(x+1)=1 Then


    Response.Write("x")
    x=x+1
    ElseIf a(x) = 0 And a(x+1) = 0 Then
    Response.Write("y")


    END IF

Next
%>

</body>
</html>

推荐答案

您的控件结构错误。您需要使用其索引位置来遍历数组,该位置在VBScript中从1开始。



Your control structure is wrong. You need to walk the array using its index position, which in VBScript starts at 1.

For i = 1 To UBound(a)
	If a(i) = 0 And i <> UBound(a) Then
		f = i + 1
		If a(f) = 0 Then
			Response.Write("x")
		Else
			Response.Write("y")
		End If
	End If
Next


这篇关于我怎么能做嵌套“如果“在Vbscript中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆