作者leicheong (睡魔)
站内Programming
标题Re: 请教vb.net 的侦测
时间Mon Nov 27 10:36:38 2006
※ 引述《[email protected] ( )》之铭言:
: Dim grade() As Integer = New Integer(9) {}
: Dim i, total As Integer
: total = 0
: For i = 0 To 8
: grade(i) = InputBox("请输入" & i + 1 & "学生成绩", "共有九笔")
: 'Console.Write("请输入{0:D2}位学生的成绩:", i + 1)
: 'grade(i) = Console.ReadLine()
: total += grade(i) '计算成绩总合
: Next
: MsgBox("学生总平均为" & total / 9)
: 请教一下,我如何在inputbox这里侦测 如果输入的不是整数 他就不会储存到阵列里呢
: 谢谢
把读进来的string的每一个char用IsNumber loop一下, 不就知道了?
Overloads Public Shared Function IsNumber(String, Integer) As Boolean
Indicates whether the character at the specified position in a specified
string is categorized as a number.
懒一点的话就Try... Catch包着Convert.ToInt32()吧... 再在
Catch时做重新读入吧... (不过Exception的处理cost有点小贵...)
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 202.134.126.84