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

โปรแกรม VB

เรื่อง...โปรแกรมการทำงานของ case

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

โค้ด Form

Public Class Form2

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

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text = TextBox1.Text & "1"
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
TextBox1.Text = TextBox1.Text & "2"
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
TextBox1.Text = TextBox1.Text & "3"
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
TextBox1.Text = TextBox1.Text & "4"
End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
TextBox1.Text = TextBox1.Text & "5"
End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
TextBox1.Text = TextBox1.Text & "6"
End Sub

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
TextBox1.Text = TextBox1.Text & "7"
End Sub

Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
TextBox1.Text = TextBox1.Text & "8"
End Sub

Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
TextBox1.Text = TextBox1.Text & "9"
End Sub

Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
TextBox1.Text = ""
TextBox1.Focus()

End Sub

Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
TextBox1.Text = TextBox1.Text & "0"
End Sub

Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click

ListBox1.Items.Add(Now() & " " & "" & cus(TextBox1.Text))
TextBox1.Text = ""

End Sub
End Class

 

โค้ด Module

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

Dim txt1 As String
txt1 = CInt(t1)

Dim n As String
Dim i As Integer
i = CInt(txt1)
Select Case i

 

Case 1006 To 1008
n = "นักวิทยาศาสตร์"
Case 1645 To 1689
n = "ช่างเทคนิค"
Case 8345
n = "ผู้ควบคุมห้องปฏิบัติการ"
Case 9998
n = "นักวิทยาศาสตร์"
Case i
n = "Access Denied"
End Select

Return n
End Function
End Module

 

ตัวอย่างโปรแกรมการทำงานของ Case

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

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

 

Free Web Hosting