Dear all:
I made a simple assignment and I face in a problem,How to save struct array in file and How to read it again, please help me! I attached all my project
in Entry form I have textboxes and all textbox saved to struct array and in Report form by searching option you can retrieve each element.
I need to save my struct array in file and read struct array in report form
Imports System.IO
Imports System.Runtime.Serialization.Formatters.Binary
Public Class Entry
Public Sub clear()
For Each control As Control In Me.Controls
If TypeOf (control) Is System.Windows.Forms.TextBox Then
control.Text = ""
End If
Next
End Sub
Public total As Integer = 0
<Serializable()> Public Structure student
Friend idno As Integer
Friend name As String
Friend lastname As String
Friend fathername As String
Friend mobile As Long
Friend add As String
Friend remarks As String
End Structure
Public s1(50) As student
Dim s2 As student
Public Sub stdsave_Click(sender As Object, e As EventArgs) Handles stdsave.Click
s1(total).idno = id_no.Text
s1(total).name = s_name.Text
s1(total).lastname = last_name.Text
s1(total).fathername = father_name.Text
s1(total).mobile = s_mobile.Text
s1(total).add = s_add.Text
s1(total).remarks = s_remarks.Text
total += 1
MsgBox("Record Successfully added to database", MsgBoxStyle.Information, "Operation")
clear()
End Sub
Private Sub Entry_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub id_no_TextChanged(sender As Object, e As EventArgs) Handles id_no.TextChanged
End Sub
Private Sub PictureBox2_Click(sender As Object, e As EventArgs) Handles PictureBox2.Click
MainP.Show()
Me.Hide()
End Sub
End Class
*******************************
My report code
Public Class Report
Public ssearch As Entry.student
Public Sub clearrport()
For Each control As Control In Me.Controls
If TypeOf (control) Is System.Windows.Forms.Label Then
ridno.Text = " "
rname.Text = ""
rlstname.Text = ""
rfname.Text = ""
rmobile.Text = ""
radd.Text = ""
rremarks.Text = ""
' control.Text = ""
End If
Next
End Sub
Private Sub Report_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click
End Sub
Private Sub btnsrch_Click(sender As Object, e As EventArgs) Handles btnsrch.Click
For Each Me.ssearch In Entry.s1
If txtsrch.Text = ssearch.idno Then
ridno.Text = ssearch.idno
rname.Text = ssearch.name
rlstname.Text = ssearch.lastname
rfname.Text = ssearch.fathername
rmobile.Text = ssearch.mobile
radd.Text = ssearch.add
rremarks.Text = ssearch.remarks
Exit Sub
End If
Next
If txtsrch.Text <> 0 Then
MsgBox("value is not in database", MsgBoxStyle.Critical, "search failed")
clearrport()
End If
Exit Sub
End Sub
Private Sub txtsrch_TextChanged(sender As Object, e As EventArgs) Handles txtsrch.TextChanged
End Sub
Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
MainP.Show()
Me.Hide()
End Sub
Private Sub buttonprint_Click(sender As Object, e As EventArgs)
End Sub
Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs)
End Sub
Private Sub PictureBox2_Click(sender As Object, e As EventArgs) Handles PictureBox2.Click
PrintForm1.Print()
End Sub
End Class
I made a simple assignment and I face in a problem,How to save struct array in file and How to read it again, please help me! I attached all my project
in Entry form I have textboxes and all textbox saved to struct array and in Report form by searching option you can retrieve each element.
I need to save my struct array in file and read struct array in report form
Imports System.IO
Imports System.Runtime.Serialization.Formatters.Binary
Public Class Entry
Public Sub clear()
For Each control As Control In Me.Controls
If TypeOf (control) Is System.Windows.Forms.TextBox Then
control.Text = ""
End If
Next
End Sub
Public total As Integer = 0
<Serializable()> Public Structure student
Friend idno As Integer
Friend name As String
Friend lastname As String
Friend fathername As String
Friend mobile As Long
Friend add As String
Friend remarks As String
End Structure
Public s1(50) As student
Dim s2 As student
Public Sub stdsave_Click(sender As Object, e As EventArgs) Handles stdsave.Click
s1(total).idno = id_no.Text
s1(total).name = s_name.Text
s1(total).lastname = last_name.Text
s1(total).fathername = father_name.Text
s1(total).mobile = s_mobile.Text
s1(total).add = s_add.Text
s1(total).remarks = s_remarks.Text
total += 1
MsgBox("Record Successfully added to database", MsgBoxStyle.Information, "Operation")
clear()
End Sub
Private Sub Entry_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub id_no_TextChanged(sender As Object, e As EventArgs) Handles id_no.TextChanged
End Sub
Private Sub PictureBox2_Click(sender As Object, e As EventArgs) Handles PictureBox2.Click
MainP.Show()
Me.Hide()
End Sub
End Class
*******************************
My report code
Public Class Report
Public ssearch As Entry.student
Public Sub clearrport()
For Each control As Control In Me.Controls
If TypeOf (control) Is System.Windows.Forms.Label Then
ridno.Text = " "
rname.Text = ""
rlstname.Text = ""
rfname.Text = ""
rmobile.Text = ""
radd.Text = ""
rremarks.Text = ""
' control.Text = ""
End If
Next
End Sub
Private Sub Report_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click
End Sub
Private Sub btnsrch_Click(sender As Object, e As EventArgs) Handles btnsrch.Click
For Each Me.ssearch In Entry.s1
If txtsrch.Text = ssearch.idno Then
ridno.Text = ssearch.idno
rname.Text = ssearch.name
rlstname.Text = ssearch.lastname
rfname.Text = ssearch.fathername
rmobile.Text = ssearch.mobile
radd.Text = ssearch.add
rremarks.Text = ssearch.remarks
Exit Sub
End If
Next
If txtsrch.Text <> 0 Then
MsgBox("value is not in database", MsgBoxStyle.Critical, "search failed")
clearrport()
End If
Exit Sub
End Sub
Private Sub txtsrch_TextChanged(sender As Object, e As EventArgs) Handles txtsrch.TextChanged
End Sub
Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
MainP.Show()
Me.Hide()
End Sub
Private Sub buttonprint_Click(sender As Object, e As EventArgs)
End Sub
Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs)
End Sub
Private Sub PictureBox2_Click(sender As Object, e As EventArgs) Handles PictureBox2.Click
PrintForm1.Print()
End Sub
End Class