Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

all my headears are not well aligned can someone help me ? Imports System.IO Pub

ID: 3770257 • Letter: A

Question

all my headears are not well aligned can someone help me ?

Imports System.IO

Public Class Form1
    Dim filename As String
    Dim fmtStr1 As String = "{0,-15}{1,-50}{2,-20}{3,-20}"
    Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
        If OFD.ShowDialog = Windows.Forms.DialogResult.OK Then
            filename = OFD.FileName
        End If
    End Sub

    Private Sub btnProcess_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProcess.Click
        Dim Pro_ID As String = ""
        Dim cost As Decimal = 0
        Dim description As String = ""
        Dim begStock As Integer = 0
        Dim endStock As Integer = 0
        Dim BegStockCost As Decimal = 0
        Dim EndstockCost As Decimal = 0
        Dim avarage As Decimal = 0
        Dim Turnover As Decimal = 0

        If Not filename = "" Then
            lstdata.Items.Add("Product ID" & "Description" & "Avarage" & "Turnover ")
            Try
                ' Open the file using a stream reader.
                Using sr As New StreamReader(filename)
                    sr.ReadLine()
                    sr.ReadLine()
                    Do While sr.Peek() >= 0
                        Pro_ID = sr.ReadLine
                        cost = sr.ReadLine
                        description = sr.ReadLine
                        begStock = sr.ReadLine
                        endStock = sr.ReadLine
                        BegStockCost = cost * begStock
                        EndstockCost = cost * endStock

                        avarage = (BegStockCost + EndstockCost) / 2
                        Turnover = ((begStock - endStock) * cost) / avarage

                        Dim sItemTemp As String
                        sItemTemp = String.Format(fmtStr1, Pro_ID, description, FormatCurrency(avarage), Math.Round(Turnover))
                        lstdata.Items.Add(sItemTemp)
                    Loop


                End Using


            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
        Else
            MessageBox.Show("Please Select File")
        End If
    End Sub
    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        If lstdata.Items.Count = 0 Then
            MessageBox.Show("Please Process Data First")
        Else
            If SFD.ShowDialog = Windows.Forms.DialogResult.OK Then
                Using SW As New IO.StreamWriter(SFD.FileName, True)
                    For Each itm As String In lstdata.Items
                        SW.WriteLine(itm)
                    Next
                End Using

            End If
        End If
    End Sub


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class

Explanation / Answer

Imports System.IO
Public Class Form1
Dim filename As String
Dim fmtStr1 As String = "{0,-15}{1,-50}{2,-20}{3,-20}"
   Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
       If OFD.ShowDialog = Windows.Forms.DialogResult.OK Then
           filename = OFD.FileName
       End If
   End Sub
   Private Sub btnProcess_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProcess.Click
       Dim Pro_ID As String = ""
       Dim cost As Decimal = 0
       Dim description As String = ""
       Dim begStock As Integer = 0
       Dim endStock As Integer = 0
       Dim BegStockCost As Decimal = 0
       Dim EndstockCost As Decimal = 0
       Dim avarage As Decimal = 0
       Dim Turnover As Decimal = 0
       If Not filename = "" Then
           lstdata.Items.Add("Product ID" & "Description" & "Avarage" & "Turnover ")
           Try
               ' Open the file using a stream reader.
               Using sr As New StreamReader(filename)
                   sr.ReadLine()
                   sr.ReadLine()
                   Do While sr.Peek() >= 0
                       Pro_ID = sr.ReadLine
                       cost = sr.ReadLine
                       description = sr.ReadLine
                       begStock = sr.ReadLine
                       endStock = sr.ReadLine
                       BegStockCost = cost * begStock
                       EndstockCost = cost * endStock
                       avarage = (BegStockCost + EndstockCost) / 2
                       Turnover = ((begStock - endStock) * cost) / avarage
                       Dim sItemTemp As String
                       sItemTemp = String.Format(fmtStr1, Pro_ID, description, FormatCurrency(avarage), Math.Round(Turnover))
                       lstdata.Items.Add(sItemTemp)
                   Loop
               End Using

           Catch ex As Exception
               MessageBox.Show(ex.Message)
           End Try
       Else
           MessageBox.Show("Please Select File")
       End If
   End Sub
   Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
       If lstdata.Items.Count = 0 Then
           MessageBox.Show("Please Process Data First")
       Else
           If SFD.ShowDialog = Windows.Forms.DialogResult.OK Then
               Using SW As New IO.StreamWriter(SFD.FileName, True)
                   For Each itm As String In lstdata.Items
                       SW.WriteLine(itm)
                       Next
               End Using
           End If          
       End If
   End Sub

   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
   End Sub
End Class

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote