Re: 請教vb.net 的偵測

看板Programming作者 (睡魔)時間18年前 (2006/11/27 10:29), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/3 (看更多)
※ 引述《jiannrong@kkcity.com.tw ( )》之銘言: : 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
文章代碼(AID): #15QasYuF (Programming)
討論串 (同標題文章)
文章代碼(AID): #15QasYuF (Programming)