Jump to content

Recommended Posts

Posted

This is a project I'm currently working on. It really has no use just thought it would be fun.

As you may notice I have a 'create' button that allows me to create a text document. But the thing is every time you load the program you need to create a new text document. I wondering if anyone can help me out with a 'load' button that would load a .txt file.

thanks.

CODE
Dim position As Integer
Structure person
Public ID As Integer
<VBFixedString(15)> Public name As String
<VBFixedString(15)> Public surname As String
End Structure

Dim list(44) As person
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim RecLength As Long, Employee As person
Dim filenum As Integer

filenum = FreeFile()

FileOpen(filenum, TextBox1.Text, OpenMode.Random, , , Len(Employee))

FileClose(filenum)

End Sub
Function FindLastRecordNo() As Integer
Dim temp As person, filenumber As Integer

filenumber = FreeFile()

FileOpen(filenumber, TextBox1.Text, OpenMode.Random, OpenAccess.Read, , Len(temp))
FindLastRecordNo = 1

Do While Not EOF(filenumber)
FileGet(filenumber, temp, )
FindLastRecordNo = FindLastRecordNo + 1
Loop

FileClose(filenumber)
End Function
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim Employee As person, lastrecord As Integer
Dim filenum As Integer

lastrecord = FindLastRecordNo()

filenum = FreeFile()
FileOpen(filenum, TextBox1.Text, OpenMode.Random, , , Len(Employee))
Employee.ID = Val(TextBox2.Text)
Employee.name = TextBox3.Text
Employee.surname = TextBox4.Text

FilePut(filenum, Employee, lastrecord)

FileClose(filenum)

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim filenum As Integer
Dim employee As person, count As Integer, Temp As String
filenum = FreeFile()
FileOpen(filenum, "D:\school\test4.txt", OpenMode.Random, , , Len(employee))
count = 1
ListBox1.Items.Clear()
Do While Not EOF(filenum)

FileGet(filenum, employee, count)
Temp = Str(employee.ID) + " " + employee.name + " " + employee.surname

ListBox1.Items.Add(Temp)
count = count + 1
Loop
FileClose(filenum)
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim filenum As Integer
Dim employee As person
filenum = FreeFile()
FileOpen(filenum, TextBox1.Text, OpenMode.Random, , , Len(employee))
Do While Not EOF(filenum)
FileGet(filenum, employee, )
If employee.ID = Val(TextBox5.Text) Then

position = Loc(filenum)

TextBox5.Enabled = False
TextBox6.Enabled = True
TextBox7.Enabled = True
Button4.Enabled = False
Button5.Enabled = True
Button6.Enabled = True


TextBox6.Text = employee.name
TextBox7.Text = employee.surname
Exit Do
End If
Loop
FileClose(filenum)
End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Dim filenum As Integer
Dim employee As person
filenum = FreeFile()
FileOpen(filenum, TextBox1.Text, OpenMode.Random, , , Len(employee))

Seek(filenum, position)


employee.ID = Val(TextBox5.Text)
employee.name = TextBox6.Text
employee.surname = TextBox7.Text
FilePut(filenum, employee, )
FileClose(filenum)

TextBox5.Enabled = True
TextBox6.Enabled = False
TextBox7.Enabled = False
Button4.Enabled = False
Button5.Enabled = True
Button6.Enabled = False

TextBox5.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""
End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Dim filenum As Integer
Dim employee As person, filenum1, filenum2 As Integer

filenum1 = FreeFile()
FileOpen(filenum1, TextBox1.Text, OpenMode.Random, OpenAccess.Read, , Len(employee))

filenum2 = FreeFile()
FileOpen(filenum2, "temp.text", OpenMode.Random, OpenAccess.Write, , Len(employee))

Do While Not EOF(filenum1)

If (Loc(filenum1) <> position - 1) Then
FileGet(filenum1, employee, )
FilePut(filenum2, employee, )
Else
FileGet(filenum1, employee, )
End If
Loop

FileClose(filenum1)
FileClose(filenum2)

Kill(TextBox1.Text)

Rename("text.txt", TextBox1.Text)


TextBox5.Enabled = True
TextBox6.Enabled = False
TextBox7.Enabled = False
Button4.Enabled = False
Button5.Enabled = True
Button6.Enabled = False

TextBox5.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""

End Sub
Private Sub swap_them(ByRef number1 As person, ByRef number2 As person)
Dim temp As person
temp = number1
number1 = number2
number2 = temp
End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
Dim filenum As Integer
Dim i, j As Integer
Dim employee As person, count, counter As Integer, temp As String
filenum = FreeFile()
FileOpen(filenum, TextBox1.Text, OpenMode.Random, , , Len(employee))

count = 1
ListBox2.Items.Clear()
Do While Not EOF(filenum)
FileGet(filenum, employee, count)

list(count).ID = Val(employee.ID)
list(count).name = employee.name
list(count).surname = employee.surname
count = count + 1
Loop
FileClose(filenum)
For counter = 1 To count
ListBox2.Items.Add(Str(list(counter).ID) + " " + list(counter).name + " " + list(counter).surname)
Next
For i = 1 To count
For j = 2 To count
If list(j).ID < list(j - 1).ID Then swap_them(list(j), list(j - 1))
Next
Next
ListBox2.Items.Add("****Numeric Order****")
For counter = 1 To count
ListBox2.Items.Add(Str(list(counter).ID) + " " + list(counter).name + " " + list(counter).surname)
Next
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()
TextBox6.Clear()
TextBox7.Clear()
End Sub
End Class


Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...