
Patrick B. answered 10/21/20
Math and computer tutor/teacher
Here are some snippets of code.
Please email me so we can get you all of the project file involved.
I am using the MS Flex grid control, so you may need to download
a copy of MSFLXGRD.ocx, add it to the toolbox, and drag it on the form.
=======================================================================
Module Module1
Structure DataRec
Public EmployeeId As String
Public LastName As String
Public FirstName As String
Public AnnualIncome As Double
Public IncomeTax As Double
End Structure
Public DataRecCount As Integer
Public A(5000) As DataRec
Public Sub Parse(inbuff As String, ByRef dataRec As DataRec)
Dim tokens() As String
tokens = inbuff.Split(" ")
dataRec.EmployeeId = tokens(0)
dataRec.LastName = tokens(1)
dataRec.FirstName = tokens(2)
dataRec.AnnualIncome = Val(tokens(3))
dataRec.IncomeTax = dataRec.AnnualIncome * 0.05
End Sub
Public Sub ReadFile()
Dim fileReader As System.IO.StreamReader
fileReader = My.Computer.FileSystem.OpenTextFileReader("E:\\IncomeRecord.txt")
Dim inbuff As String
inbuff = "?"
DataRecCount = 0
While Not fileReader.EndOfStream
inbuff = fileReader.ReadLine()
MsgBox(inbuff)
Parse(inbuff, A(DataRecCount))
DataRecCount = DataRecCount + 1
End While
fileReader.Close()
End Sub
End Module
'********************************************************************************
Option Explicit On
Public Class FormMain
Sub Data2Grid()
Dim iRow As Integer
myGrid.Row = 0
myGrid.Col = 0 : myGrid.Text = "Employee Id#"
myGrid.Col = 1 : myGrid.Text = "Last Name"
myGrid.Col = 2 : myGrid.Text = "First Name"
myGrid.Col = 3 : myGrid.Text = "Annual Income"
myGrid.Col = 4 : myGrid.Text = "Income Tax"
myGrid.Rows = DataRecCount + 1
For iRow = 0 To DataRecCount - 1
myGrid.Row = iRow + 1
myGrid.Col = 0 : myGrid.Text = A(iRow).EmployeeId
myGrid.Col = 1 : myGrid.Text = A(iRow).LastName
myGrid.Col = 2 : myGrid.Text = A(iRow).FirstName
myGrid.Col = 3 : myGrid.Text = A(iRow).AnnualIncome
myGrid.Col = 4 : myGrid.Text = A(iRow).IncomeTax
Next
End Sub
Private Sub FormMain_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
ReadFile()
Data2Grid()
End Sub
End Class
Nehal R.
Are sure that the answers are correct for the above coding11/01/20