VB2005实验中五金商店商品表格
窗口面做出这样的效果,按顺序就行
具体程序如下:
Imports System.IO
Structure hardware
Dim no As Integer
Dim name As String
Dim num As Integer
Dim price As Single
End Structure
Public Class Form1
Dim it As hardware
Dim num As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
it.no = TextBox1.Text
it.name = TextBox2.Text
it.num = TextBox3.Text
it.price = TextBox4.Text
ListBox1.Items.Add(TextBox1.Text + Chr(9) + TextBox2.Text + Chr(9) + TextBox3.Text + Chr(9) +
TextBox4.Text)
FilePut(1, it, it.no)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim fs As New FileStream(Application.StartupPath & "\hardware1.dat", FileMode.OpenOrCreate,
FileAccess.ReadWrite)
Dim Sr As New StreamReader(fs)
Sr = New StreamReader(fs)
ListBox1.Text = Sr.ReadToEnd()
Sr.Close()
fs.Close()
Sr = Nothing
fs = Nothing
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim i As Integer = Val(ListBox1.SelectedItem)
ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
it = Nothing
FilePut(1, it, i)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
FileOpen(1, "d:\hardware.txt", OpenMode.Random, , , Len(it))
Dim i As Integer
it = Nothing
For i = 1 To 100
FilePut(1, it, i)
Next
End Sub
End Class