我正在使用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"
我感谢任何帮助。
答案 0 :(得分:3)
ReadNumber
的返回类型(或更准确地说,k
变量的类型)可能不是Integer
。当编译器想要推断mt
的类型时,它会失败,因为k
指定为循环绑定有一种类型(可能类似Double
)和循环步骤(隐含地,整数常量1)具有类型Integer
。由于两者不匹配,编译器不会自动采用mt
的类型。
For mt As Integer = 1 To k
NewUserEntry()
Next