|
คำแนะนำ
Source Code แสดงการจัดการข้อมูลอย่างง่าย
โดยจำลองให้ listbox เป็นแหล่งเก็บข้อมูล
และมีปุ่มสำหรับ เพิ่ม ลบ แก้ไขข้อมูล ก่อนเรียนระดับต่อไป
|
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
If (ListBox1.SelectedIndex.ToString <> -1) Then
Dim s As String = ListBox1.Items(ListBox1.SelectedIndex.ToString)
Dim ar() As String
ar = Split(s, ",")
TextBox1.Text = ar(0)
TextBox2.Text = ar(1)
TextBox3.Text = ar(2)
TextBox4.Text = CInt(TextBox4.Text) + CInt(ar(2))
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button2.Click
Dim s As String
s = TextBox1.Text + "," + TextBox2.Text + "," + TextBox3.Text
ListBox1.Items.Add(s)
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button3.Click
Dim i As Integer
Dim ar(ListBox1.Items.Count - 1) As String
Dim f() As String
Dim cnt As Integer = 0
For i = 0 To ListBox1.Items.Count - 1
f = Split(ListBox1.Items(i), ",")
If (TextBox1.Text <> f(0)) Then
ar(cnt) = ListBox1.Items(i)
cnt = cnt + 1
End If
Next
ListBox1.Items.Clear()
For i = 0 To cnt - 1
ListBox1.Items.Add(ar(i))
Next
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button4.Click
Dim i As Integer
Dim ar(ListBox1.Items.Count - 1) As String
Dim f() As String
Dim cnt As Integer = 0
For i = 0 To ListBox1.Items.Count - 1
f = Split(ListBox1.Items(i), ",")
If (TextBox1.Text <> f(0)) Then
ar(cnt) = ListBox1.Items(i)
cnt = cnt + 1
Else
ar(cnt) = TextBox1.Text + "," + TextBox2.Text + "," + TextBox3.Text
cnt = cnt + 1
End If
Next
ListBox1.Items.Clear()
For i = 0 To cnt - 1
ListBox1.Items.Add(ar(i))
Next
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button5.Click
Dim i As Integer
Dim s As String = ""
For i = 0 To ListBox1.Items.Count - 1
s &= ListBox1.Items(i) & Chr(10)
Next
MsgBox(s)
End Sub
End Class
|
|