none
Errors might occur when converting string to 'IFormatProvider' RRS feed

  • Question

  • 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 Me.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("C0")
                End If
            Next
        End Sub
    End Class
    Having this error popup for my code, anyone mind helping?
    Tuesday, April 23, 2019 3:08 AM

Answers

  • Nvm I solved it, just needed to change dblSalary from String to Double.
    • Marked as answer by Godren Tuesday, April 23, 2019 4:46 AM
    Tuesday, April 23, 2019 4:46 AM

All replies

  • Nvm I solved it, just needed to change dblSalary from String to Double.
    • Marked as answer by Godren Tuesday, April 23, 2019 4:46 AM
    Tuesday, April 23, 2019 4:46 AM
  • Hi,

    I am glad you have got your solution, and shared us your solution and mark it as an answer.It will be beneficial to other community.

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, May 7, 2019 6:21 AM