【问题标题】:For loop is ambiguousFor循环不明确
【发布时间】:2010-01-25 19:49:07
【问题描述】:

我使用的是 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"

感谢您的帮助。

【问题讨论】:

  • 你确定这是 VB 而不是 SmallBasic?

标签: loops for-loop


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2021-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多