asp.net for vb:請教陣列與控制項
請教一下,我有三個文字框,我希望輸入三筆數字後,
會幫我做加總。
雖然我已經設計出來,但我覺得語法冗長,很笨的寫法
請問是否可以讓我的語法更精簡呢?
是否可以寫一個函數,就可以幫我檢查所有的textbox欄位是否為數字呢?
謝謝!
附上原始語法如下:
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"" rel="nofollow">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Dim b As Integer = 0
Dim c As Integer = 0
Dim FirstArray(3) As Integer
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
If IsNumeric(TextBox1.Text) = False Then
MsgBox("請輸入整數")
TextBox1.Focus()
Exit Sub
Else
FirstArray(0) = Int(TextBox1.Text)
End If
If IsNumeric(TextBox2.Text) = False Then
MsgBox("請輸入整數")
TextBox2.Focus()
Exit Sub
Else
FirstArray(1) = Int(TextBox2.Text)
End If
If IsNumeric(TextBox3.Text) = False Then
MsgBox("請輸入整數")
TextBox3.Focus()
Exit Sub
Else
FirstArray(2) = Int(TextBox3.Text)
End If
For c = 0 To 2
b += FirstArray(c)
Next
Label3.Text = b
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>未命名頁面</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="請輸入3個人成績"></asp:Label>
:<br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br />
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Button" />
<br />
<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label></div>
</form>
</body>
</html>
--
┌─────◆KKCITY◆─────┐ ● KKCITY 市民小常識 ●
│ bbs.kkcity.com.tw │ Q:文章標題前有#符號是代表什麼意思?
└──《From:140.109.139.91 》──┘ A:被作者加密了,需輸入密碼才能閱讀
--
→
04/30 12:40, , 1F
04/30 12:40, 1F
Programming 近期熱門文章
PTT數位生活區 即時熱門文章