因为循环是模棱两可的

时间:2010-01-25 19:49:08

标签: loops for-loop

我正在使用Visual Basic 2008EE,我对此循环有疑问:

If x = CType("new", Primitive) Then
        TextWindow.Write("How many new users would you like to add?     ")
        k = TextWindow.ReadNumber()
        For mt = 1 To k
            NewUserEntry()
        Next

我收到此错误:

"type of 'mt' is ambigious because the loop bounds and the step clause do not convert to the same type"

我感谢任何帮助。

1 个答案:

答案 0 :(得分:3)

ReadNumber的返回类型(或更准确地说,k变量的类型)可能不是Integer。当编译器想要推断mt的类型时,它会失败,因为k指定为循环绑定有一种类型(可能类似Double)和循环步骤(隐含地,整数常量1)具有类型Integer。由于两者不匹配,编译器不会自动采用mt的类型。

For mt As Integer = 1 To k
     NewUserEntry()
Next