Visual Basic 中学校 掲示板 投稿の管理
タグのない投稿を抽出
統計
RSS
Visual Basic 中学校
投稿一覧
FormatPercent関数とSelect Case
この投稿へのリンク
https://keijiban.umayadia.com/ThreadDetail.aspx?ThreadId=10579#CommentId22125
この投稿の削除
削除パスワード
削除する
コメント本文
投稿者
もも
 (学生)
投稿日時
2011/11/19 13:18:33
コード忘れてました。 使用するものはテキストボックス8個とラベル1個とボタン1個です。
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Declare i, Item(Socores),Grade Total, Totalpossiblepoint, and FinalGrade
Dim Item() As Integer = {Textbox1.Text, Textbox2.Text, Textbox3.Text, Textbox4.Text, Textbox5.Text, Textbox6.Text, MidExam.Text, FinalExam.Text}
Dim Grade As Decimal
Dim Total As Integer
Dim Totalpossiblepoint As Integer = 800
Dim FinalGrade As String
Dim i As Integer
'Culculate the Scores
For i = 0 To 7
Total += Item(i)
Next
Grade = (Total / Totalpossiblepoint)
' Convert to Percentage
Dim percentage As Integer
percentage = FormatPercent(Grade, 0)
MsgBox(percentage)
'Define the Final Grade
Select Case percentage
Case Is >= 90%
FinalGrade = "A"
PassAtoC()
Case 80% To 89%
FinalGrade = "B"
PassAtoC()
Case 70% To 79%
FinalGrade = "C"
PassAtoC()
Case 60% To 69%
FinalGrade = "D"
PassD()
Case Else
FinalGrade = "F"
Failed()
End Select
Gradelbl.Text = FinalGrade
End Sub
Private Sub PassAtoC()
'If FinalGrade is A to C, color is Green
Gradelbl.ForeColor = Color.Green
End Sub
Private Sub PassD()
'If FinalGrade is D, color is Orenge
Gradelbl.ForeColor = Color.Orange
End Sub
Private Sub Failed()
'If FinalGrade is F, color is red
Gradelbl.ForeColor = Color.Red
End Sub