U
ukgrl_yr79
hi
fairly new to vb.net . I have created a filesystem where a manager
and co workers hve limted access.
the manager can read members files. i have used streamreader to get
the details from a text file on my c drive into relevent text boxes eg
name, address by using arrays.
what i need to know is , how do i make it possible for the manager to
add a new record on the same page that will be appended to the same
text file on my c drive. and them read bak from it.
I also need to know how make my array bigger so say if there where
more records added.
any help gratfull- this is driving me mad
this is my code.
Public Class Form2
Public BookArray As Book() 'Class file
Public NumRex As Integer
Dim Current As Integer
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim datafile As String = "C:\BooksFile.txt"
Dim oRead As New System.IO.StreamReader(datafile) ' Should
check that the file exists
Dim i As Integer = 0
Dim linein As String
Dim arr As String()
'Find out how many lines we've got
While oRead.Peek <> -1
linein = oRead.ReadLine()
i = i + 1
'MsgBox(linein & " i = " & i)
End While
NumRex = i - 1
'Redim ItemArray so it'll hold all the items
ReDim BookArray(NumRex)
oRead.Close()
oRead = New System.IO.StreamReader(datafile)
For i = 0 To CastArray.Length - 1
'Grab a line
linein = oRead.ReadLine()
' Split the line at the commas and feed it into the arr
array
arr = linein.Split(",")
'Now feed the elements of arr into the fields of
ItemArray(i)
BookArray(i) = New Book
BookArray(i).BookId = Int(arr(0))
BookArray(i).Title = arr(1)
BookArray(i).Author = arr(2)
BookArray(i).Publisher = arr(3)
BookArray(i).Datepublished = arr(4)
Next i
oRead.Close()
txtBookId.Text = BookArray(0).BookId
txtTitle.Text = BookArray(0).Title
txtAuthor.Text = BookArray(0).Author
txtPublisher.Text = BookArray(0).Publisher
txtDatePublished.Text = BookArray(0).Datepublished
Current = 0
Private Sub btnLastRecord_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles btnLastRecord.Click
txtBookId.Text = BookArray(NumRex).BookId
txtTitle.Text = BookArray(NumRex).Title
txtAuthor.Text = BookArray(NumRex).Author
txtPublisher.Text = BookArray(NumRex).Publisher
txtDatePublished.Text = BookArray(NumRex).Datepublished
Current = NumRex
Private Sub btnNextRecord_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles btnNextRecord.Click
If Current < NumRex Then
Current = Current + 1
txtBookId.Text = BookArray(Current).BookId
txtTitle.Text = BookArray(Current).Title
txtAuthor.Text = BookArray(Current).Author
txtPublisher.Text = BookArray(Current).Publisher
txtDatePublished.Text = BookArray(Current).Datepublished
End If
End Sub
fairly new to vb.net . I have created a filesystem where a manager
and co workers hve limted access.
the manager can read members files. i have used streamreader to get
the details from a text file on my c drive into relevent text boxes eg
name, address by using arrays.
what i need to know is , how do i make it possible for the manager to
add a new record on the same page that will be appended to the same
text file on my c drive. and them read bak from it.
I also need to know how make my array bigger so say if there where
more records added.
any help gratfull- this is driving me mad
this is my code.
Public Class Form2
Public BookArray As Book() 'Class file
Public NumRex As Integer
Dim Current As Integer
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim datafile As String = "C:\BooksFile.txt"
Dim oRead As New System.IO.StreamReader(datafile) ' Should
check that the file exists
Dim i As Integer = 0
Dim linein As String
Dim arr As String()
'Find out how many lines we've got
While oRead.Peek <> -1
linein = oRead.ReadLine()
i = i + 1
'MsgBox(linein & " i = " & i)
End While
NumRex = i - 1
'Redim ItemArray so it'll hold all the items
ReDim BookArray(NumRex)
oRead.Close()
oRead = New System.IO.StreamReader(datafile)
For i = 0 To CastArray.Length - 1
'Grab a line
linein = oRead.ReadLine()
' Split the line at the commas and feed it into the arr
array
arr = linein.Split(",")
'Now feed the elements of arr into the fields of
ItemArray(i)
BookArray(i) = New Book
BookArray(i).BookId = Int(arr(0))
BookArray(i).Title = arr(1)
BookArray(i).Author = arr(2)
BookArray(i).Publisher = arr(3)
BookArray(i).Datepublished = arr(4)
Next i
oRead.Close()
txtBookId.Text = BookArray(0).BookId
txtTitle.Text = BookArray(0).Title
txtAuthor.Text = BookArray(0).Author
txtPublisher.Text = BookArray(0).Publisher
txtDatePublished.Text = BookArray(0).Datepublished
Current = 0
Private Sub btnLastRecord_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles btnLastRecord.Click
txtBookId.Text = BookArray(NumRex).BookId
txtTitle.Text = BookArray(NumRex).Title
txtAuthor.Text = BookArray(NumRex).Author
txtPublisher.Text = BookArray(NumRex).Publisher
txtDatePublished.Text = BookArray(NumRex).Datepublished
Current = NumRex
Private Sub btnNextRecord_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles btnNextRecord.Click
If Current < NumRex Then
Current = Current + 1
txtBookId.Text = BookArray(Current).BookId
txtTitle.Text = BookArray(Current).Title
txtAuthor.Text = BookArray(Current).Author
txtPublisher.Text = BookArray(Current).Publisher
txtDatePublished.Text = BookArray(Current).Datepublished
End If
End Sub