Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

one column into diffrent rows

Posted on 2003-11-25
2
Medium Priority
?
249 Views
Last Modified: 2010-05-03
Hi,
I have a "file1.csv" that has 1 column which has 10 values (rows).Now I want a VB prg to read file1.csv and make the 10 rows as 1 row and 10 columns(transposing).I need thi sin loop as I have to do transposing for 5000 CSV files.
Pls help asap,
Maha
0
Comment
Question by:mahalakshmi_s
2 Comments
 
LVL 28

Expert Comment

by:vinnyd79
ID: 9820149
If you add a FileListbox you can loop through it and write each file to a new file.This will create a new file with the prefix "new" in front of each filename:

Private Sub Form_Load()
File1.Pattern = "*.csv"
File1.Path = "C:\Somefolder"
End Sub

Private Sub Command1_Click()
Dim i As Integer, ff As Integer, tf As Integer
Dim Ln As String, TmpStr As String
Dim origFile As String, newFile As String
For i = 0 To File1.ListCount - 1

If Right$(App.Path, 1) <> "\" Then
    origFile = File1.Path & "\" & File1.FileName
    newFile = File1.Path & "\new" & File1.FileName
Else
    origFile = File1.Path & File1.FileName
    newFile = File1.Path & "new" & File1.FileName
End If

ff = FreeFile
Open origFile For Input As #ff
tf = FreeFile
Open newFile For Output As #tf
Do Until EOF(ff)
Line Input #ff, Ln
If i = 0 Then
    TmpStr = Ln
Else
    TmpStr = TmpStr & "," & Ln
End If
Loop
Print #tf, TmpStr
Close #ff
Close #tf
Next i

End Sub
0
 
LVL 2

Accepted Solution

by:
rekhasri earned 200 total points
ID: 9822937
Hi,

ive just copied the file to a 2d array and written it back after transposing.

change the hardcodes acc to ur need

here is the code:
------------------------------------

Private Sub Form_Load()

Dim fso     As FileSystemObject
Dim f       As File
Dim ts      As TextStream
Dim sIp     As String
Dim txt()   As String
Dim tempArr() As String
Dim i       As Integer
Dim j       As Integer
Dim k       As Integer
Dim l       As Integer
Dim sOp     As String

Set fso = New FileSystemObject
Set f = fso.GetFile("F:\trials\New Folder\ip.csv")

Set ts = f.OpenAsTextStream(ForReading, TristateUseDefault)

i = 0
ReDim txt(10, i) As String
While Not ts.AtEndOfStream
    sIp = ts.ReadLine
    tempArr = Split(sIp, ",", , vbTextCompare)
    For j = LBound(tempArr) To UBound(tempArr)
        txt(j, i) = tempArr(j)
    Next j
    i = i + 1
    ReDim Preserve txt(10, i) As String
Wend

Set ts = f.OpenAsTextStream(ForWriting, TristateUseDefault)

For k = 0 To 9
    sOp = vbNullString
    For l = 0 To i - 1
        sOp = sOp & txt(k, l) & ","
    Next
    sOp = Mid$(sOp, 1, Len(sOp) - 1)
    ts.WriteLine (sOp)
Next

End Sub
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

824 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