Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

VB Formatting Arrays for .dat file

Original Message
Name: acerteng
Date: November 19, 2007 at 07:59:11 Pacific
Subject: VB Formatting Arrays for .dat file
OS: XP
CPU/Ram: 512
Model/Manufacturer: Dell
Comment:
Okay I solved the first part to my problem and now I have run into another situation. I have been trying to resolve this for almost a week and cannot come up with or find anything that works.

I am using VB 2005 Express. I have extracted data from one file and put it into another file. (.dat) My problem is the program that is reading the file needs it to be formatted in a specific way to be able to read it.

the first array is 13 spaces total, the second array is 8 spaces total, the third array is 20 spaces total and the last is 4 spaces total. Meaning with data that array needs to be that amount of spaces.

My problem is the third array, this is where names are inputted and they can vary in length but the space can only accommodate 20 characters&spaces (total). All of the other inputs are pretty much constant.

Here is and example of what the output should look like:

123456 7890 johnjacob jinglehime1234
123456 7890 John Doe 1234

Hopefully that gives you an idea of what I am dealing with. Notice that in the first row the name was cut off...that's okay. In my current code the output looks like this and my program won't read it:

123456 7890 johnjacob jinglehimersmith1234
123456 7890 John Doe1234

Please help...here is what I have so far...some of you may recognize it as you have helped me with it before:

Imports System.IO

Module Mod1
Sub Main()
Dim fIn As StreamReader
Dim fOut As StreamWriter
Dim sArry() As String

'This reads file and creates/overwrites new .dat
fIn = New StreamReader(New FileStream("c:\testfile1.dat", FileMode.Open))
fOut = New StreamWriter(New FileStream("c:\testfile2.dat", FileMode.Create))
'Parse arrays
Do Until (fIn.EndOfStream)
sArry = Split(fIn.ReadLine, ",")
If UBound(sArry) = 8 Then _
fOut.WriteLine(sArry(4) & " " & sArry(2) & " " & sArry(1) & " " & sArry(0) & "TEXT")
Loop
fIn.Close()
fOut.Close()
End Sub

End Module


Report Offensive Message For Removal


Response Number 1
Name: Razor2.3
Date: November 19, 2007 at 19:50:57 Pacific
Subject: VB Formatting Arrays for .dat file
Reply: (edit)
Hey, I remember that code!

Ahem, you'll have to forgive any vagueness or general syntax problems; the box I installed VS2K5 on isn't hooked up at the moment.

What you need to do is combine Space() with Left(), and you'll end up with something like this:
fOut.WriteLine(sArry(4) & " " & sArry(2) & " " & Left(sArry(1) & Space(13), 13) & " " & sArry(0) & "TEXT")


Report Offensive Follow Up For Removal




Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: VB Formatting Arrays for .dat file

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software




how to setup call of duty to joytok

WindowsME / HotMail Problem

Corrupt memory

Convert fat32 to Ntfs

Best WinMo phone of 2008


The information on Computing.Net is the opinions of its users. Such opinions may not be accurate and they are to be used at your own risk. Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE

All content ©1996-2007 Computing.Net, LLC