I put together a vb.net program that does some string parsing and creates a fixed-width file at the end. When I run it on each of my 2 machines it creates a properly formatted file. When my client downloads the msi file, installs it, and runs it, he gets several extra spaces on each record of the file, and the number of spaces is inconsistent from record to record. Here is the code, although it runs fine on my side, so I am thinking it must have something to do with the compiler maybe??? The spaces are added to the beginning of each record.

'For each T2 record,
    For i = 0 To frmMain.SquirrelDataSet.PayDataExceptions.Rows.Count - 1

        frmMain.ProgressBar1.PerformStep()

        'Join Fname and Lname into FullName.
        Dim FullName As String = frmMain.SquirrelDataSet.PayDataExceptions.Rows(i).Item("Lname") & "," & frmMain.SquirrelDataSet.PayDataExceptions.Rows(i).Item("Fname")

        If FullName = Nothing Then
            FullName = ""
        End If
        'FullName = FullName(FullName.PadLeft(25, " "))
        FullName = FullName.PadLeft(25, " ")

        objWriter.Write(frmMain.SquirrelDataSet.PayDataExceptions.Rows(i).Item(0) & _
                        FullName & _
                        frmMain.SquirrelDataSet.PayDataExceptions.Rows(i).Item(2) & _
                        frmMain.SquirrelDataSet.PayDataExceptions.Rows(i).Item(3) & _
                        frmMain.SquirrelDataSet.PayDataExceptions.Rows(i).Item(4) & _
                        frmMain.SquirrelDataSet.PayDataExceptions.Rows(i).Item(5) & _
                        frmMain.SquirrelDataSet.PayDataExceptions.Rows(i).Item(6) & _
                        frmMain.SquirrelDataSet.PayDataExceptions.Rows(i).Item(7) & _
                        frmMain.SquirrelDataSet.PayDataExceptions.Rows(i).Item(8) & _
                        frmMain.SquirrelDataSet.PayDataExceptions.Rows(i).Item(9) & _
                        frmMain.SquirrelDataSet.PayDataExceptions.Rows(i).Item(10) & _
                        frmMain.SquirrelDataSet.PayDataExceptions.Rows(i).Item(11) & _
                        frmMain.SquirrelDataSet.PayDataExceptions.Rows(i).Item(12) & _
                        frmMain.SquirrelDataSet.PayDataExceptions.Rows(i).Item(13) & _
                        frmMain.SquirrelDataSet.PayDataExceptions.Rows(i).Item(14) & _
                        frmMain.SquirrelDataSet.PayDataExceptions.Rows(i).Item(15) & _
                        frmMain.SquirrelDataSet.PayDataExceptions.Rows(i).Item(16) & _
                        frmMain.SquirrelDataSet.PayDataExceptions.Rows(i).Item(17) & _
                        frmMain.SquirrelDataSet.PayDataExceptions.Rows(i).Item(18) & _
                        frmMain.SquirrelDataSet.PayDataExceptions.Rows(i).Item(19) & _
                        frmMain.SquirrelDataSet.PayDataExceptions.Rows(i).Item(20) & _
                        frmMain.SquirrelDataSet.PayDataExceptions.Rows(i).Item(21) & _
                        frmMain.SquirrelDataSet.PayDataExceptions.Rows(i).Item(22) & vbCrLf)
    Next

The first thing I would check is to test the app on both machines using exactly the same input data. Another possible source of the extra blanks is from the user. Could the user be introducing the blanks on the form? I don't know what data is in the first column. Is it possible that the data is being displayed in a different format because of a different system setting on the user's machine?

I'm going to make a couple of comments and suggestions. You can simplify the output of the data by building the output string in a loop. Also (if this doesn't screw up the data), you might Trim blanks off the ends of each field. Lastly, do you really want to pack all the fields together with no delimiter? Usually, fields are written with comma separators. The code below does this. If you don't want to use a field separator then set SEP to "" or remove it completely.

Dim out As New System.Text.StringBuilder
Const SEP = ","
.
.
.

For i = 0 To frmMain.SquirrelDataSet.PayDataExceptions.Rows.Count - 1

    frmMain.ProgressBar1.PerformStep()

    Dim FullName As String = frmMain.SquirrelDataSet.PayDataExceptions.Rows(i).Item("Lname") & "," & frmMain.SquirrelDataSet.PayDataExceptions.Rows(i).Item("Fname")

    If FullName = Nothing Then
        FullName = ""
    End If

    FullName = FullName.PadLeft(25, " ")

    out = Trim(frmMain.SquirrelDataSet.PayDataExceptions.Rows(i).Item(0)) & SEP & FullName

    For c As Integer = 2 To 22
        out.Append(SEP & Trim(frmMain.SquirrelDataSet.PayDataExceptions.Rows(i).Item(c)))
    Next

    objWriter.Write(out.ToString & vbCrLf)

Next    

Hi, maybe it has to do with the Windowsversion that is being used. I just got a new computer which runs under Windows7, my old one runs under Windows Vista. The applications I build in Vista show up wrong on the Windows7 screen. I found that it is caused by the Fonts, Windows7 has about half the different types than in Vista. Also the Fontsize shows up bigger on the Windows7 screen. I have not tried it, but I think it may have an effect on textfiles as well.

I did a preliminary check on the source file but I will check that again. I can't use the trim function because this is a fixed-length record and contains plenty of spaces which have to be there to retain the integrity of the record. It is somewhere in those spaces that the issue lies...

The font should have no bearing on how the text is stored. The only things that would be affected are display and printing. Are you sure that the app is using exactly the same data source on both machines?

kindofsudden, I see that you couldn't trim after you've formatted everything, but how about before? If you make sure that only your whitespace is going into your format function, it'll give you a better idea where the problem lies.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.