Workers List Program

Burke, Brendan J 141 Reputation points
2022-04-14T04:03:09.167+00:00

192894-wk14-c9p-instructions-document.jpg192962-clearer-view-of-bolded-parts.jpg192982-workers-list-code-editor-window.jpg192963-workers-list-designer-window.jpg192925-workerstxt-file.jpg

I just need help with the bolded parts for this Problem. The parts I have bolded in the instructions document and also have on a google docs page so it is more clear for you to read. It is Questions 4, 8, 9 and the part in the overview that is bolded the google docs give the exact part. Thanks Greatly appreciated.

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,637 questions
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 27,836 Reputation points Microsoft Vendor
    2022-04-14T07:17:58.847+00:00

    Hi @Burke, Brendan J ,
    In order to read and write txt files, you need to learn to use StreamReader Class and StreamWriter Class.
    Also learn about Form.FormClosing Event

        Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click  
            ComboBox1.Items.Add(TextBox1.Text)  
        End Sub  
      
        Private Sub btnUpdate_Click(sender As Object, e As EventArgs) Handles btnUpdate.Click  
            Dim sw As System.IO.StreamWriter = New System.IO.StreamWriter("Your file path", False, System.Text.Encoding.UTF8)  
            For Each worker In ComboBox1.Items  
                sw.WriteLine(worker.ToString)  
            Next  
            sw.Close()  
        End Sub  
      
        Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click  
            Me.Close()  
        End Sub  
      
        Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing  
            Dim res = MessageBox.Show("Do you wish to update the worker.txt file?", "Warning", MessageBoxButtons.YesNoCancel)  
            If res = DialogResult.Yes Then  
                Dim sw As System.IO.StreamWriter = New System.IO.StreamWriter("Your file path", False, System.Text.Encoding.UTF8)  
                For Each worker In ComboBox1.Items  
                    sw.WriteLine(worker.ToString)  
                Next  
                sw.Close()  
            ElseIf res = DialogResult.Cancel Then  
                e.Cancel = True  
            End If  
        End Sub  
      
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load  
            Dim sr As System.IO.StreamReader = New System.IO.StreamReader("Your file path", System.Text.Encoding.UTF8)  
            Dim strs() As String = Split(sr.ReadToEnd, vbCrLf)  
            ComboBox1.Items.AddRange(strs)  
            sr.Close()  
        End Sub  
    

    Best Regards.
    Jiachen Li

    ----------

    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful