Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
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.


VB



XML
<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>
Posted

1 solution

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

VB
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900