Vb.net 是否有从多位数中获取单个数字的功能?
我想将每个数字与下一个数字进行比较,以确保下一个数字大于最后一个数字,但它会给我一个语法错误:System.MissingMemberException:“找不到类型“Integer”的默认成员。” 模块1Vb.net 是否有从多位数中获取单个数字的功能?,vb.net,Vb.net,我想将每个数字与下一个数字进行比较,以确保下一个数字大于最后一个数字,但它会给我一个语法错误:System.MissingMemberException:“找不到类型“Integer”的默认成员。” 模块1 Sub Main() Dim repeat, chronological As Boolean Dim counter As Double For password = 134792 To 675810 repeat = double_check(pa
Sub Main()
Dim repeat, chronological As Boolean
Dim counter As Double
For password = 134792 To 675810
repeat = double_check(password)
chronological = increasing_check(password)
If chronological = True And repeat = True Then
counter += 1
End If
Next
Console.WriteLine(counter)
Console.ReadLine()
End Sub
Function double_check(num)
Dim check As Boolean = False
For charcter = 0 To 4
If num(charcter) = num(charcter + 1) Then
check = True
End If
Next
Return check
End Function
Function increasing_check(num)
Dim check As Boolean = True
For character = 0 To 4
If num(character) > num(character + 1) Then
check = False
End If
Next
Return check
End Function
您将密码作为整数传递,并尝试从中获取字符,就像它们是字符串一样 它工作的最小变化是:
repeat = double_check(password.ToString)
chronological = increasing_check(password.ToString)
这样,两个函数中的'num'参数都将是一个字符串,您可以从中获取具体索引的字符不,没有。您需要转换为
字符串
并使用字符或进行一些数学运算。数学很简单。将选项设置为Strict
和选项Explicit
都设置为On。请更正并重试。您的函数应定义为函数双_检查(num为整数)为布尔值
。您必须重新评估循环:调试这些方法,看看它们是否检查了应该检查的内容。非常感谢jmcilhinney,尝试了它,效果非常好。Jimi我相信你在编码方面比我高得多,因为我对你的评论了解很少,但我希望随着我的进步,我会回过头来完全理解你的评论,无论如何谢谢,谢谢,看起来像是一种将变量转换成字符串的巧妙方法