hi guzs im trying to read a file and open it when click on the button when i run.I don't know why the file didn't show up on my screen.here the code
Public Partial Class MainForm
'structure of products
Structure products
Public nameproduct As String
Public catalogcode As String
Public wholesade as Integer
Public saleprice As Integer
End Structure
Dim listproduct(100) As products
Public Sub New()
' The Me.InitializeComponent call is required for Windows Forms designer support.
Me.InitializeComponent()
'
' TODO : Add constructor code after InitializeComponents
'
End Sub
Sub Button5Click(ByVal sender As Object,ByVal e As system.EventArgs)
me.Close()
End Sub
Private Sub ShowproductClick(ByVal sender As system.Object,ByVal e As system.EventArgs)
Dim srestreamreader As IO.StreamReader
Dim strline As String
Dim stringfield(3) As String 'strore extra field value in the code
Dim numrecord As Integer 'number of record
Dim stringrecord As String
Dim result As DialogResult 'what did the user choose in the open dialog (open or cancel)
dim record as String
Try
'then print the file if file exist
If IO.File.Exists("E:/products.txt ") Then
srestreamreader = io.File.OpenText("E:/products.txt ")
Else
messagebox.Show("File does not exist","Message file ",messageboxbuttons.OK,messageboxicon.Information)
End If
'read value that indicate the # of record in the file
strline = srestreamreader.ReadLine()
numrecord = convert.toint32(strline)
Dim countnum As Integer
For countnum = 0 To numrecord - 1 Step 1
strline = srestreamreader.ReadLine()
stringfield =stringrecord .Split(",") 'fields seperated by commas
'now i will store into listproduct
listproduct(numrecord).nameproduct = stringfield(0)
listproduct(numrecord).catalogcode = stringfield(1)
listproduct(numrecord).wholesade = stringfield(2)
listproduct(numrecord).saleprice = stringfield(3)
Next
'close the streamreader
srestreamreader.close()
Catch ex As Exception
'handle any error in the designe
messagebox.Show(ex.Message,"Error loading the file.",messageboxbuttons.ok,messageboxicon.information)
End Try
End Sub
End Class