------------------------------------------------------------------------------------------------------------------------------

โปรแกรม VB

เรื่อง...การคำนวณเกรด

------------------------------------------------------------------------------------------------------------------------------

โปรแกรมที่ 1


Public Class Form1
Dim Score As Integer
Dim GRAD As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnOK.Click
LbGrad.Text = "เกรด ::"
Score = Val(TxtScore.Text)
If Score < 0 Then
MsgBox("ป้อนคะแนนที่มากว่าหรือเท่ากับ 0")
TxtScore.Clear()
TxtScore.Focus()
ElseIf Score > 100 Then
MsgBox("ป้อนคะแนนที่มากว่าหรือเท่ากับ 100")
TxtScore.Clear()
TxtScore.Focus()
ElseIf Not IsNumeric(TxtScore.Text) Then
MsgBox("กรุณาป้อนค่าที่เป็นตัวเลข")
TxtScore.Clear()
TxtScore.Focus()
Else
If Score >= 80 Then
GRAD = "A"
ElseIf Score >= 75 Then
GRAD = "B+"
ElseIf Score >= 70 Then
GRAD = "B"
ElseIf Score >= 65 Then
GRAD = "C+"
ElseIf Score >= 60 Then
GRAD = "C"
ElseIf Score >= 55 Then
GRAD = "D+"
ElseIf Score >= 50 Then
GRAD = "D"
Else
GRAD = "F"
End If
LbGrad.Text &= GRAD
End If
End Sub

Private Sub BtnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCancel.Click

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub
End Class

ตัวอย่าง Form 1

 

-------------------------------------------------------------------------------------------------------------------------

โปรแกรมที่ 2

Public Class Form2

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.CenterToScreen()
TextBox1.Text = "50641207006-8"
TextBox2.Text = "นางสาวศิริประภา เรือนฝายกาศ"
TextBox3.Text = 40
TextBox4.Text = 35
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim m, f, t As Single
Dim g As String
If TextBox3.Text = "" Then
MessageBox.Show("กรุณาป้อนคะแนน", "เดือน", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
TextBox3.Focus()
Exit Sub
ElseIf TextBox4.Text = "" Then
MessageBox.Show("กรุณาป้อนคะแนน", "เดือน", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
TextBox4.Focus()
Exit Sub
End If
m = Val(TextBox3.Text)
f = Val(TextBox4.Text)
t = m + f
Label5.Text = Format(t, "##0")
If t < 49.5 Then
g = "F"
ElseIf t <= 59.5 Then
g = "D"
ElseIf t <= 69.5 Then
g = "C"
ElseIf t <= 79.5 Then
g = "B"
Else
g = "A"
End If
Label6.Text = g

End Sub
End Class

ตัวอย่าง Form 2

 

-------------------------------------------------------------------------------------------------------------------------

โปรแกรมที่ 3

Public Class Form3

Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.CenterToScreen()
Dim sex(3) As String
sex(0) = "นาย"
sex(1) = "นางสาว"
sex(2) = "นาง"
Dim i As Integer
For i = 0 To 2
ComboBox1.Items.Add(sex(i))
Next
ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList
ComboBox1.SelectedIndex = 1
RadioButton1.Text = "โสด"
RadioButton2.Text = "สมรส"
RadioButton3.Text = "หย่าร้าง"
RadioButton2.Checked = True
TextBox1.Text = "50641207006-8"
TextBox2.Text = "นางสาวศิริประภา เรือนฝายกาศ"
TextBox3.Text = 45
TextBox4.Text = 35
Button1.Text = "คำนวณ"
Button2.Text = "ล้างค่า"

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Fname As String
Fname = TextBox1.Text & " " & ComboBox1.Text & TextBox2.Text
Label6.Text = Fname
Dim t As Integer
Dim g As String
t = Val(TextBox3.Text) + Val(TextBox4.Text)
Label8.Text = t
Select Case t
Case 0 To 49
g = "F"
Case 50 To 59
g = "D"
Case 60 To 69
g = "C"
Case 70 To 79
g = "B"
Case 80 To 100
g = "A"
End Select
Label9.Text = "เกรด=" & g

Dim a As String
If RadioButton1.Checked = True Then
Label7.Text = RadioButton1.Text
End If
If RadioButton2.Checked = True Then
Label7.Text = RadioButton2.Text
End If
If RadioButton3.Checked = True Then
Label7.Text = RadioButton3.Text
End If

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
TextBox1.Enabled = True
TextBox2.Enabled = True
TextBox3.Enabled = True
TextBox4.Enabled = True
Button1.Enabled = True
Button2.Enabled = False
Label2.Text = ""
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""

End Sub
End Class

ตัวอย่าง Form 3

 

------------------------------------------------------------------------------------------------------------------------------

กลับหน้าหลัก

 

Free Web Hosting