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

โปรแกรม VB

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

โปรแกรมที่ 1


Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.CenterToScreen()
TextBox1.Text = 15
TextBox2.Text = 5
Button1.Text = "คำนวณ"
Label2.Text = ""
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a, b As Integer
Dim r As Single
a = Val(TextBox1.Text)
b = Val(TextBox2.Text)
r = a + b
Label2.Text = Format(r, "###,##0.00")
TextBox1.Enabled = False
TextBox2.Enabled = False
Button1.Enabled = False
Button2.Enabled = True
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
Button1.Enabled = True
Button2.Enabled = False
Label3.Text = ""
TextBox1.Text = ""
TextBox2.Text = ""
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()
Label1.Text = "ป้อนค่า1"
Label2.Text = "ป้อนค่า2"
TextBox1.Text = "15"
TextBox2.Text = "5"
RadioButton1.Text = "บวก"
RadioButton2.Text = "ลบ"
RadioButton3.Text = "คูณ"
RadioButton4.Text = "หาร"
RadioButton1.Checked = True
Button1.Text = "คำนวณ"
Button2.Text = "ล้าง"
Label4.Text = ""
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a, b As Integer
Dim r As Single
a = Val(TextBox1.Text)
b = Val(TextBox2.Text)
If RadioButton1.Checked = True Then
r = a + b
End If
If RadioButton2.Checked = True Then
r = a - b
End If
If RadioButton3.Checked = True Then
r = a * b
End If
If RadioButton4.Checked = True Then
r = a / b
End If
Label4.Text = Format(r, "###,##0.00")
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
Button1.Enabled = True
Button2.Enabled = False
Label4.Text = ""
TextBox1.Text = ""
TextBox2.Text = ""
End Sub
Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox1.Enter
End Sub
End Class

 

ตัวอย่าง Form 2

 

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

โปรแกรมที่ 3


Public Class Form3
Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox1.Enter
ComboBox1.Items.Add("บวก")
ComboBox1.Items.Add("ลบ")
ComboBox1.Items.Add("คูณ")
ComboBox1.Items.Add("หาร")
ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList
TextBox1.Text = 15
TextBox2.Text = 5
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a, b As Integer
Dim r As Single
a = Val(TextBox1.Text)
b = Val(TextBox2.Text)
Select Case ComboBox1.SelectedIndex
Case 0
r = a + b
Case 1
r = a - b
Case 2
r = a * b
Case 3
r = a / b
End Select
Label4.Text = Format(r, "###,##0.00")
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
Button1.Enabled = True
Button2.Enabled = False
Label4.Text = ""
TextBox1.Text = ""
TextBox2.Text = ""
End Sub
End Class

 

ตัวอย่าง Form 3

 

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

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

 

Free Web Hosting