为什么说vb中 next没有for

2025-03-23 15:58:16
推荐回答(5个)
回答1:

因为For循环内的if没有end if。

改为:

For i = 1 To 100

If isnarc(a(i)) = True Then

sum = sum + a(i)

end if

Next i

或:

For i = 1 To 100

If isnarc(a(i)) = True Then sum = sum + a(i)

Next i

扩展资料:

注意事项

If与End If是成对出现的(除非写在同一行的就不用End If),如果不成对(比如有4个If,却只有3个End If),就会影响到它外围的其他结构体比如For Next循环。

一、如果是单行的IF,后面不能接END IF,比如说If 5 > 3 Then MsgBox "yes"

如果是多行的就必须要有end if,比如:

if a=3 then

b=2

end if

二、加else跟上面一样,如果是单行的,可以是If 5 > 8 Then MsgBox "yes" Else MsgBox "no"

多行的if then else 类似这种

if a=3 then

b=2

else 

b=1

end if

回答2:

因为For循环内的if没有end if。

改为:

For i = 1 To 100

If isnarc(a(i)) = True Then

sum = sum + a(i)

end if

Next i

或:

For i = 1 To 100

If isnarc(a(i)) = True Then sum = sum + a(i)

Next i

扩展资料:

注意事项

If与end If配对(除非它写在同一行上,否则不使用end If)。如果它没有配对(例如,有四个If,但只有三个endif),它将影响它周围的其他结构,例如for next循环。

1、 如果它是一行If,则结束If,例如,如果5>3,则msgbox“yes”

如果它是多行,则必须有结束符,例如:

if a=3 then

b=2

end if

2、加else跟上面一样,如果是单行的,可以是If 5 > 8 Then MsgBox "yes" Else MsgBox "no"

多行的if then else 类似这种

if a=3 then

b=2

else

b=1

end if

回答3:

If与End If是成对出现的(除非写在同一行的就不用End If),如果不成对(比如有4个If,却只有3个End If),就会影响到它外围的其他结构体比如For ... Next循环
你可以自己算一算,你的代码的If和End If成对吗?
另外,你发的是图片,我没法帮你直接改,你要么自己改,要么再发代码来给我改。

回答4:

for没有next表示for循环结束,没有写next

vb中for语法

For<循环变量>=<初值>To<终值>[Step步长] 
  <循环体> 
  [Exit For] 
  Next<循环变量>

如果只写了for,最后结束时没有写next,就会报for没有next的错误。

回答5:

必须有的,如果没有的话那么next 后面一定要加变量
比如说 for i=1 to 10
next i
不然不成立的。

或者是代码有误,忘记加了。