Question

Zander Inc. stores employee IDs and salaries in a sequential access file named Employees.txt. Open the VB2015\Chap10\Zander Solution\Zander Solution (Zander Solution.sln) file. Open the Employees.txt file, which is contained in the project’s bin\Debug folder. The ID and salary information appear on separate lines in the file. Close the Employees.txt window. a. Define a structure named Employee. The structure should contain two member variables:

a String variable to store the ID and a Double variable to store the salary.

b. Declare a class-level array that contains five Employee structure variables.

c. The frmMain_Load procedure should read the IDs and salaries from the Employees.txt file and store them in the class-level array. It should also add the IDs to the list box.

d. When the user selects an employee ID in the list box, the employee’s salary should appear in the lblSalary control.

e. Test the application appropriately.

As of right now this is my code i have 2 errors i will put them in bold. will put in a picture of how it suppose to look.

Option Explicit On
Option Strict On
Option Infer Off

Public Class frmMain
Structure Employee
Public strID As String
Public dblSalary As String
End Structure
Private emp(4) As Employee
Private strfile As String = "Employees.txt"


Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim inFile As IO.StreamReader
Dim strId As String
Dim intSub As Integer = 0

If IO.File.Exists(strfile) Then
inFile = IO.File.OpenText(strfile)
Do Until inFile.Peek = -1
strId = inFile.ReadLine
lstIds.Items.Add(strId)
emp(intSub).strID = strId
emp(intSub).dblSalary = Convert.ToDouble(inFile.ReadLine)
intSub += 1
Loop
inFile.Close()

lstIds.SelectedIndex = 0
Else
MessageBox.Show("Can't find" & strfile & "File", "Employees", MessageBoxButtons.OK)
End If
End Sub
Private Sub lstIds_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lstIds.SelectedIndexChanged
For Each dbElement As Employee In emp
If lstIds.SelectedItem.ToString = dbElement.strID Then
lblSalary.Text = dbElement.dblSalary.ToString("C2")
End If
Next
End Sub


End ClassZander Ing. Employee IDs: Salary $15,460 30 1309 407 1410 1503

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Option Explicit On
Option Strict On
Option Infer Off
Public Class frmMain
Structure Employee
Public strID As String
Public dblSalary As String
End Structure
Private emp(4) As Employee
Private strfile As String = "Employees.txt"

Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim inFile As IO.StreamReader
Dim strId As String
Dim intSub As Integer = 0
If IO.File.Exists(strfile) Then
inFile = IO.File.OpenText(strfile)
Do Until inFile.Peek = -1
strId = inFile.ReadLine
lstIds.Items.Add(strId)
emp(intSub).strID = strId
'Error was coming as you have Option Strict On which doesn't allow the conversion
'PLUS you dont need the conversion sice your dblSalary struct variable is already a string
'So just use it like below
emp(intSub).dblSalary = inFile.ReadLine
intSub += 1
Loop
inFile.Close()
lstIds.SelectedIndex = 0
Else
MessageBox.Show("Can't find" & strfile & "File", "Employees", MessageBoxButtons.OK)
End If
End Sub
Private Sub lstIds_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lstIds.SelectedIndexChanged
For Each dbElement As Employee In emp
If lstIds.SelectedItem.ToString = dbElement.strID Then
'Error was coming as you have Option Strict On which doesn't allow the conversion
'Plus you dont need the conversion since your dblSalary struct variable is already a string
'Also I suppose you are meaning to update the txt box below salary label on selection change
'So instead of lblSalary, use the name of text box below salary, I named it txtSalary, works fine.
txtSalary.Text = dbElement.dblSalary
End If
Next
End Sub

End Class

frmMain Emp IDs Salary 17.440 1309 1407 1410 1503 Exit

Add a comment
Know the answer?
Add Answer to:
Zander Inc. stores employee IDs and salaries in a sequential access file named Employees.txt. Open the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need help with this problem in Visual Basic 2012: Write a program that allows the...

    I need help with this problem in Visual Basic 2012: Write a program that allows the user to specify two numbers and then adds, subtracts, multiplies, or divides them when the user clicks on the appropriate button. The output should give the type of arithmetic performed and the result. Whenever one of the numbers in an input text box is changed, the output text box should be cleared. Also, if the number 0 is entered into the second text box,...

  • Program using visual basic.net You will create a very simple two numbers calculator with save options;...

    Program using visual basic.net You will create a very simple two numbers calculator with save options; here is the specifications for the application. Create a form divided vertically in two halves with right and left panels 1- In the left panel you will create the following control, the label or the value of the control will be in "" and the type of the control will in [] a- "First Number" [textbox] b- "Second number" [texbox] c- "Result" [textbox] -...

  • so im trying to make a grade program and idk what im doing wrong actually if...

    so im trying to make a grade program and idk what im doing wrong actually if someone can help? (heres the lines of code i have so far if its wrong let me know how to fix them Option Strict On Option Explicit On Public Class Form1 Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click Dim lblscore1 As Double Dim lblscore2 As Double Dim lblscore3 As Double lblscore1 = CDbl(Txtscore1.Text) lblscore2 = CDbl(Txtscore2.Text) lblscore3 = CDbl(Txtscore3.Text) lblaverage =...

  • I am new to programming (2 weeks of playing with it) I have written code for...

    I am new to programming (2 weeks of playing with it) I have written code for a timer in Visual Studio 2013. I am wondering if someone can show me how to write code/what the code would look like in a MODULE1.vb. I was thinking that for this timer I could create MsgBox using a DO UNTIL LOOP that would pop up every 20 seconds that says "hurry up!" until 1 minute has passed. As I said I am just...

  • Project 2 – Memory Match Game Purpose This Windows Classic Desktop application plays a simple matching game. The game si...

    Project 2 – Memory Match Game Purpose This Windows Classic Desktop application plays a simple matching game. The game simulates a card game where the cards a placed face down and the player flips over pairs of cards in an attempt to find matching cards.   Program Procedure Display a 4x4 grid of “face down” cards. Assign the letters A through H randomly to the cards in pairs. Allow the user to click on a card to “flip” it over and...

  • WITH THIS CODE, ADD TO THE EXIT BUTTON THAT ALLOWS THE USER TO SEE UPON EXITING,...

    WITH THIS CODE, ADD TO THE EXIT BUTTON THAT ALLOWS THE USER TO SEE UPON EXITING, HOW MANY QUESTIONS THEY GOT RIGHT AND WRONG. Public Class Form1 Dim r As Random = New Random Dim no1, no2 As Integer Private Sub rdbAdd_CheckedChanged(sender As Object, e As EventArgs) Handles rdbAdd.CheckedChanged txtAnswer.Clear() txtAnswer.BackColor = Color.White no1 = randomInt() no2 = randomInt() lblOperation.Text = "+" txtNumber1.Text = no1.ToString() txtNumber2.Text = no2.ToString() End Sub Public Function randomInt() As Integer Return r.Next(20, 120) End Function...

  • Public Class Form1     Private Sub CompleteReport_Click(sender As Object, e As EventArgs) Handles CompleteReport.Click         Dim...

    Public Class Form1     Private Sub CompleteReport_Click(sender As Object, e As EventArgs) Handles CompleteReport.Click         Dim room As Double 'Assigns room as double         Dim rate As Double 'Assigns rate as double         Dim room2 As Double 'Assigns room as double         Dim overallRate As Double 'Assigns overall as double         Dim a As Integer 'Assign a as an integer         For a = 1 To 8 'Assign a as an 1 to 8 for all 8 floors             With...

  • The Murach's Visual Basic 2015 Book And Visual Studio Exercise 7-2 Enhance the Invoice Total application...

    The Murach's Visual Basic 2015 Book And Visual Studio Exercise 7-2 Enhance the Invoice Total application If you did exercise 6-1 in the last chapter, this exercise asks you to add data validation and exception handling to it. 1. Copy the Invoice Total application from your C:\VB 2015\Chapter 06 directory to your Chapter 07 directory. This should be your solution to exercise 6-1 of the last chapter. 2. If your application has both a Sub procedure and a Function procedure...

  • Any way to add a counter?, to count the elements/ # of prime factors outputted to...

    Any way to add a counter?, to count the elements/ # of prime factors outputted to TextBox2.Text. VB Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.click Dim n As Long Dim i As Long Dim k As Long Dim Prime As Boolean n = TextBox1.Text For i = 2 To n If n Mod i = 0 Then k = 2 Prime = False While k <i / 2 If i Mod k = 0...

  • An application contains the Structure statement shown here. Structure MyFriend Public strName As String Public strBirthday...

    An application contains the Structure statement shown here. Structure MyFriend Public strName As String Public strBirthday As String End Structure Create a VB.Net Windows Form application named MyFriend_YourName. Change the name property of your form to frmMain. Add the MyFriend Structure to the public class frmMain. Create 2 text boxes txtName and txtBirthday, and a button with the name property changed to btnExecute and the text property changed to Execute. In the button click event, write a Dim statement that...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT