none
學生成績表的問題 RRS feed

  • 問題

  • 大家好,.我是vb新手.我都是個中年人了,但因為一直對vb都很有興趣,所以就去了夜校,但最近有一個項目要做,要做一份簡單的學生成績表計算器

    裹面要包含有,可輸入的名字,3種類別的科目,總分,平均分還有評語...需要老師沒什麼要求,只管做出來就好了..但我發現做是做了,但還有很多解不清楚的問題,因為限制輸入的用法,老師還沒教.在網上看別人的文章,都是有看沒懂.但自己也想明白一下.所以就上來問問各位高人了.

    比如..在inputname0.Text和inputname1.Text裹..我只能輸入數字,輸入其他就會說轉至double無效

    我是想只能輸入中文,而且限制只能輸入2~4個中文字,而要限制字型類別一共有多少種方法?

    還有能幫我看看下面我的寫的..有什麼能改進或有錯的地方嗎?

    ps.亂碼的都為中文字..因為在公司的問題..轉不過來

    Public Class Form1

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

            Dim stdScores(1, 2) As Integer

            Dim stdtotal(0), stdtotal2(1), stdAverages(0) As Single

            Dim a, b, c As Integer

            REM ¤À°tÃC¦â

            totalScore0.BackColor = Color.Yellow

            totalScore1.BackColor = Color.Yellow

            totalScore0.ForeColor = Color.Red

            totalScore1.ForeColor = Color.Red

            AveragesScore0.BackColor = Color.Black

            AveragesScore1.BackColor = Color.Black

            AveragesScore0.ForeColor = Color.Yellow

            AveragesScore1.ForeColor = Color.Yellow

            judgmentOutput0.BackColor = Color.Blue

            judgmentOutput1.BackColor = Color.Blue

            judgmentOutput0.ForeColor = Color.Black

            judgmentOutput1.ForeColor = Color.Black

            REM

            inputname0.Text = inputname0.Text

            inputname1.Text = inputname1.Text

            REM

            stdScores(0, 0) = CInt(PCScore0.Text)

            stdScores(0, 1) = CInt(scienceScore0.Text)

            stdScores(0, 2) = CInt(physicsScore0.Text)

            stdScores(1, 0) = CInt(PCScore1.Text)

            stdScores(1, 1) = CInt(scienceScore1.Text)

            stdScores(1, 2) = CInt(physicsScore1.Text)

            REM

            For a = 0 To 1

                If a = 0 Then

                    For b = 0 To 2

                        stdtotal(0) += stdScores(a, b)

                    Next b

                Else

                    For c = 0 To 2

                        stdtotal2(1) += stdScores(a, c)

                    Next c

                End If

            Next a

            totalScore0.Text = stdtotal(0)

            totalScore1.Text = stdtotal2(1)

     

            REM

            AveragesScore0.Text = CInt(totalScore0.Text / 3)

            AveragesScore1.Text = CInt(totalScore1.Text / 3)

            REM '' case ­Y¦³­pºâ«hµL»Ý¥[ = or ¨ä¥Lªí©ú»yªk

            REM    ­Y¨S³]©w100¤À¥H¤W,«h·|Åã¥Ü¬°75 to 1000

            Dim g, m

            g = totalScore0.Text

            Select Case g

                Case Is >= 101

                    MsgBox("§A¦b¸ê®Æ¤@¤¤§_¿é¤J¿ù»~«H®§,½Ð­«·s¿é¤J")

                    PCScore0.Text = 0

                    scienceScore0.Text = 0

                    physicsScore0.Text = 0

                    totalScore0.Text = " "

                    AveragesScore0.Text = " "

                    judgmentOutput0.Text = " "

                Case Is >= 75 And totalScore0.Text <= 100

                    judgmentOutput0.Text = inputname0.Text & "¡G§A¦Ü¥{"

                Case Is >= 55 And totalScore0.Text <= 74

                    judgmentOutput0.Text = inputname0.Text & "¡G³Â³Â¦a"

                Case Is >= 25 And totalScore0.Text <= 49

                    judgmentOutput0.Text = inputname0.Text & "¡G°I¥ª°Õ"

                Case Is >= 0 And totalScore0.Text <= 24

                    judgmentOutput0.Text = inputname0.Text & "¡GµL¤H°÷§A°I"

            End Select

            m = totalScore1.Text

            Select Case m

                Case Is >= 101

                    MsgBox("§A¦b¸ê®Æ¤G¤¤§_¿é¤J¿ù»~«H®§,½Ð­«·s¿é¤J")

                    PCScore1.Text = 0

                    scienceScore1.Text = 0

                    physicsScore1.Text = 0

                    totalScore1.Text = " "

                    AveragesScore1.Text = " "

                    judgmentOutput1.Text = " "

                Case Is >= 75 And totalScore1.Text <= 100

                    judgmentOutput1.Text = inputname1.Text & "¡G§A¦Ü¥{"

                Case Is >= 55 And totalScore1.Text <= 74

                    judgmentOutput1.Text = inputname1.Text & "¡G³Â³Â¦a"

                Case Is >= 25 And totalScore1.Text <= 49

                    judgmentOutput1.Text = inputname1.Text & "¡G°I¥ª°Õ"

                Case Is >= 0 And totalScore1.Text <= 24

                    judgmentOutput1.Text = inputname1.Text & "¡GµL¤H°÷§A°I"

            End Select

            Call NUMlimit(47)

        End Sub

     

        Public Sub NUMlimit(ByVal KeyAscii As Integer)

            If inputname0.Text = KeyAscii < 47 And KeyAscii > 57 Then

                 MsgBox("¿é¤J¿ù")

                inputname0.Text = ("")

            ElseIf IsNumeric(PCScore0.Text) Then

                MsgBox("½Ð¿é¤J¼Æ¦r")

            End If

        End Sub

    End Class

     

    2010年5月24日 下午 05:18

解答

所有回覆

  • 關於限制輸入中文, http://social.msdn.microsoft.com/Forums/zh-TW/233/thread/400ec935-7101-459b-b2da-bf1ca3efd46d 有類似的討論
    以下是簽名檔, 請勿沒事對號入座
    MSDN 文件庫很重要
    回應幫助你的人是一種禮貌, 良好的禮貌有助於激發大家對你問題回應的熱情
    進步的人會找尋自己程式中的缺點,半桶水則把自己程式的錯誤推到不相干事物的身上
    2010年5月25日 上午 02:23
    版主
  • Hi!

    關於 比如..在inputname0.Text和inputname1.Text裹..我只能輸入數字,輸入其他就會說轉至double無效

    可以參考發問 textbox的輸入判斷

      ' 假如要限制 TextBox 上不使用快速鍵與滑鼠右鍵表單(防止使用者用複製貼上的方式)
      ' 可使用 TextBox.ShortcutsEnabled 屬性 : 取得或設定值,指出是否啟用定義的快速鍵。
      Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        If Char.IsDigit(e.KeyChar) Or Char.IsControl(e.KeyChar) Then
          e.Handled = False
        Else
          MessageBox.Show("只能輸入數字")
          e.Handled = True
        End If
      End Sub

     


    歡迎參觀我的Blog.NET菜鳥自救會

    2010年5月25日 上午 02:56
    版主