Visual Basic Help: Formatting Text File

  • Thread starter neutrik
  • Start date
  • Tags
    Visual
In summary: Visual Basic that will format a given text file. He has some experience with opening and reading text files, but is struggling with writing a function to properly format the data. He is hoping to find someone who can assist him with this task before Friday, as he tends to procrastinate and is feeling overwhelmed. He can be contacted at neutrik007@yahoo.com for any help. In summary, Rahul is seeking help to format a text file in Visual Basic and can be reached at neutrik007@yahoo.com. He has some experience with opening and reading text files, but needs assistance with writing a function to properly format the data before Friday.
  • #1
neutrik
1
0
Hi,

I no very little about visual basic yet I need to write a program that will format some text. A simple enough task that shouldn't take long to complete...

Basically I'm given a text file with something like

Code:
Smith John  HIS  GEO  ENG  MUS  GST 06/03/85
Blake Nathan  MAT  HIS  MUS
Hunter Matt  GER  PHY  12/12/86

and I need to write a function that will format the line so it writes a new text file as shown below.

Code:
FIRST NAME   SURNAME       DOB          AS1    AS2    AS3    AS4    AS5   
John         Smith         06/03/85     HIS    GEO    ENG    MUS    GST
Nathan       Blake                      MAT    HIS    MUS
Matt         Hunter        12/12/86     GER    PHY

I can show someone what I've done so far (it will open and read the text file) but I just don't know how to write the function since my ability to write in VB is limited and I need to have this completed by Friday. I tend to leave things till the last minute, yes I'm an idiot.

If someone could help me out at bit it would be cool if you could email me at neutrik007@yahoo.com
 
Technology news on Phys.org
  • #2
Ok use the
Space (20 ) or

' The Tab function can be used with the Print # statement.
Open "TESTFILE" For Output As #1 ' Open file for output.
' The second word prints at column 20.
Print #1, "Hello"; Tab(20); "World."
' If the argument is omitted, cursor is moved to the next print zone.
Print #1, "Hello"; Tab; "World"
Close #1 ' Close file

Rahul
 
  • #3


Thanks

Hello,

Formatting a text file in Visual Basic can seem daunting, but with some guidance, it can be accomplished with relative ease. The first step is to create a function that reads the text file and stores the information in an array. This can be done using the "Open" and "Input" commands. Once the data is stored in an array, you can use the "Split" function to separate the data into different variables for first name, last name, date of birth, and academic subjects.

Next, you can use the "Format" function to create a formatted string that will display the data in the desired format. This string can then be written to a new text file using the "Print" command. It may also be helpful to use a loop to iterate through each line of the original text file and perform the formatting and writing process for each line.

If you need further assistance with the code, I would suggest reaching out to a Visual Basic expert or joining online forums and communities dedicated to programming. Good luck with completing your task by Friday. Remember to plan ahead in the future to avoid last-minute stress.
 

1. How do I format a text file in Visual Basic?

To format a text file in Visual Basic, you can use the Format function. This function allows you to specify the format of the data that you want to write to the text file. You can also use the WriteLine method to add line breaks and other formatting options.

2. Can I change the font and color of text in a text file using Visual Basic?

Yes, you can change the font and color of text in a text file using Visual Basic. You can use the Font and Color properties of the StreamWriter class to specify the font and color for the text that you want to write to the file.

3. How do I add headers and footers to a text file in Visual Basic?

To add headers and footers to a text file in Visual Basic, you can use the WriteLine method to write the header and footer text to the file. You can also use the WriteLine method to add blank lines or other formatting options between the header and footer and the main text of the file.

4. Can I create a table in a text file using Visual Basic?

Yes, you can create a table in a text file using Visual Basic. You can use the WriteLine method to write each row of the table to the file, separating the columns with tabs or other delimiters. You can also use the WriteLine method to add additional rows or columns as needed.

5. How do I save a text file in a specific format using Visual Basic?

To save a text file in a specific format using Visual Basic, you can use the SaveFileDialog class to prompt the user for a file name and location. Then, you can use the StreamWriter class to write the formatted text to the file in the desired format, such as .txt or .csv.

Similar threads

  • Programming and Computer Science
Replies
1
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
27
Views
23K
Back
Top