------------------------------------------------------------------------------------------------------------------------------
โปรแกรม VB
เรื่อง...การทำโปรแกรมฟังก์ชั่นเพื่อคำนวณ
------------------------------------------------------------------------------------------------------------------------------
โค้ด Form 1
Public Class Form1
Private Sub GroupBox1_Enter(ByVal sender As
System.Object, ByVal e As System.EventArgs)
Handles GroupBox1.Enter
Me.CenterToScreen()
TextBox1.Text = 5
TextBox2.Text = 2
Label3.Text = ""
End Sub
Private Sub GroupBox2_Enter(ByVal sender As
System.Object, ByVal e As System.EventArgs)
Handles GroupBox2.Enter
Dim b, ee, i As Integer
Dim r As Long
b = CInt(TextBox1.Text)
ee = CInt(TextBox2.Text)
i = 1
r = 1
Do While i <= ee
r = r * b
i = i + 1
Loop
Label3.Text = r
End Sub
End Class
ตัวอย่าง Form 1
------------------------------------------------------------------------------------------------------------------------------
โค้ดForm 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 = 5
TextBox2.Text = 2
Label3.Text = ""
End Sub
Private Sub Button1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
Label3.Text = expoment(TextBox1.Text, TextBox2.Text)
End Sub
Function expoment(ByVal txt_b As
String, ByVal txt_e As String) As Long
Dim b, ee, i As Integer
Dim r As Long
b = CInt(txt_b)
ee = CInt(txt_e)
i = 1
r = 1
Do While i <= ee
r = r * b
i = i + 1
Loop
Return r
End Function
End Clas
ตัวอย่าง Form 2
------------------------------------------------------------------------------------------------------------------------------
โค้ดForm 3 วงรอบเลขยกกำลัง,โมดู
Public Class Form3
Private Sub Label1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs)
Handles Label1.Click
Me.CenterToScreen()
TextBox1.Text = 5
TextBox2.Text = 3
Label3.Text = ""
End Sub
Private Sub Button1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
Dim r As Long
r = m_expoment(TextBox1.Text, TextBox2.Text)
Label3.Text = r
End Sub
End Class
ตัวอย่าง Form 3 วงรอบเลขยกกำลัง,โมดู
------------------------------------------------------------------------------------------------------------------------------
โค้ดForm 4 ฟังก์ชัน,โมดู,วงรอบ
Public Class Form4
Private Sub Form4_Load(ByVal sender As
System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load
Me.CenterToScreen()
Me.CenterToScreen()
TextBox1.Text = 5
TextBox2.Text = 3
End Sub
Private Sub Button1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
Dim i As Byte = 1
Dim ee As Integer = CInt(TextBox2.Text)
Dim r As Long
Do While i <= ee
r = m_expoment(TextBox1.Text, i)
ListBox1.Items.Add(TextBox1.Text & "^" & i & "=" & r)
i = i + 1
Loop
Button1.Enabled = True
Button2.Enabled = False
End Sub
Private Sub Button2_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs)
Handles Button2.Click
ListBox1.Items.Clear()
TextBox1.Text = ""
TextBox2.Text = ""
ListBox1.Items.Clear()
Button1.Enabled = True
Button2.Enabled = False
End Sub
End Class
ตัวอย่าง Form 4 ฟังก์ชัน,โมดู,วงรอบ
------------------------------------------------------------------------------------------------------------------------------
กลับหน้าหลัก |