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

โปรแกรม VB

เรื่อง...Test คำนวณเกรดและใช้ Module

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

โค้ด Form

Public Class Form1

Private Sub Form1_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 = "หย่าร้าง"
RadioButton1.Checked = True
TextBox1.Text = "51691254031-2"
TextBox2.Text = "ณัฐวุฒิ ปาละวงศ์"
TextBox3.Text = 56
TextBox4.Text = 24
Button1.Text = "คำนวณ"
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cold As String
Dim Num As String
Dim Noi As String
cold = TextBox1.Text
Name = ComboBox1.Text & TextBox2.Text
Num = TextBox3.Text
Noi = TextBox4.Text
Label7.Text = cold
Label8.Text = Name
Label10.Text = Num
Label11.Text = Noi
Dim t As Integer
Dim g As String
t = Val(TextBox3.Text) + Val(TextBox4.Text)
Label12.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
Label13.Text = " " & g

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

End Sub
Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox1.Enter

End Sub

End Class

 

โค้ด Module

Module Module1
Function calgrade(ByVal t1 As String) As String

Dim t As String
t = CInt(t1)

Dim g As String
Dim i As Integer
i = CInt(t1)

If t <= 49 Then
g = "F"
ElseIf t <= 59 Then
g = "D"
ElseIf t <= 69 Then
g = "C"
ElseIf t <= 79 Then
g = "B"
ElseIf t <= 100 Then
g = "A"
Else : g = " "
End If

Return g

End Function

End Modul

 

ตัวอย่างโปรแกรมคำนวณ

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

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

 

Free Web Hosting