[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

CREATE A FIXED WIDTH TEXT FILE from a template or other input method.

Posted on 2004-09-30
7
Medium Priority
?
581 Views
Last Modified: 2008-02-01
What methods are available for creating fixed width text files.  I need to create a text file either by converting an excel template or some other method.  What I'm asking is what methods/functions are available to create a new text file and output/write fixed width data into it.  Thanks!
0
Comment
Question by:mbosch
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 4

Expert Comment

by:srcalc
ID: 12196581
I'm not sure how in depth you plan to get in this, but if you are using a dataset or some similar data handling object, you can use the System.Data.OleDB namespace. Check out this web page:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnclinic/html/scripting03092004.asp
0
 
LVL 3

Expert Comment

by:jazduck
ID: 12197550
Cut/Paste this code, it will create a fixed line-length file from whatever you enter into the textbox.  I dont work with excel, so reading from your spreadsheet/template etc ill leave upto you, but for writing fixed line-length text files, this does the trick.

Imports System.IO

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Button1 = New System.Windows.Forms.Button
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.SuspendLayout()
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(81, 163)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(131, 29)
        Me.Button1.TabIndex = 0
        Me.Button1.Text = "Write File"
        '
        'TextBox1
        '
        Me.TextBox1.AutoSize = False
        Me.TextBox1.Location = New System.Drawing.Point(13, 13)
        Me.TextBox1.Multiline = True
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.Size = New System.Drawing.Size(267, 143)
        Me.TextBox1.TabIndex = 1
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(292, 266)
        Me.Controls.Add(Me.TextBox1)
        Me.Controls.Add(Me.Button1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)

    End Sub

#End Region
    Dim strFixedLength As String
    Dim strTemp As String
    Dim position As Integer
    Dim i As Integer

    Sub WriteFile(ByVal Data As String)
        Dim Stream As FileStream
        Stream = New FileStream("C:\test\test.txt", FileMode.Append)
        Dim Writer As New StreamWriter(Stream)
        Writer.WriteLine(Data)
        Writer.Close()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Writing a file with line length of 10 characters.
        'To adjust length of line you should adjust the
        'Step 10 to Step xx and the 3rd parameter of the
        'Mid expression to match.
        If File.Exists("C:\test\test.txt") Then
            File.Delete("C:\test\test.txt")
        End If

        strTemp = TextBox1.Text
        For i = 1 To Len(TextBox1.Text) Step 10
            strFixedLength = Mid(strTemp, i, 10)
            WriteFile(strFixedLength)
        Next

    End Sub

End Class

Regards
Jaz
0
 
LVL 3

Expert Comment

by:jazduck
ID: 12197824
I just realised i wrote that in VB.NET 2005 Beta1 - The windows form designer code may (or may not) work with previous versions, i have noticed some differences.  In the event that the designer code doesnt work, just delete the designer region, and draw one multiline textbox, and one button onto your form.

Jaz
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 12199617
You can use string padding and StreamWriter to accomplish this.

Bob
0
 
LVL 3

Expert Comment

by:jazduck
ID: 12245685
mbosch,

Could you please explain what was wrong with my answer, or how LearnedOne's assisted more.

Thanks,
Jaz
0
 
LVL 1

Author Comment

by:mbosch
ID: 12250776
Its just the method I used, but I suppose you're answer is still a correct answer.  How do I adjust the points in this thing?
0
 
LVL 3

Expert Comment

by:jazduck
ID: 12255869
It would be a CS request to adjust points, the usual deciding factor in who you give points to is the answer that 'helps you the most'.  If more than one answer did help you then you should split them.  I have no problem with you awarding points to LearnedOne, as his answer is correct, I was just querying how it assisted you more than a full solution.  Please only ask CS to split if my answer did help you, if it didnt, just let LearnedOne have them.

Regards
Jaz
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question