Columns instead of Rows?

Hello
I have a question for anyone willing to help. I am trying to populate a list box with information from a text file. I already have made the program so it will take the lists of data (many rows, 4 columns per file) and input them into a listbox. Where I am having trouble is that I have multiple files, and the addrow feature is simply adding them down the first 4 columns. Is there any way to populate the listbox, such that, the data is across the columns. In better terms, have one file populate down x rows and 4 columns(from columns 0 to 3), then have the next file populate down x rows, but start on the 5th column( from columns 4 to 7).
This is designed to be cross-platform software, but I am creating it on windows.

I could supply code if anyone would like to take a look, especially on the addrow column.
Thanks,
Reid

you need to use CELL(), LISTINDEX and LISTCOUNT

Treat the listbox as if it were an array… adding rows only if you need to, but insert the data into the CELLS as required

As for displaying the files?
I have this for the add row (shown is extra code for reference)

For g as integer = 0 to dlg.count-1
  myFile = dlg.item(g)
  Dim rowFromFile1, oneCell1 As String
  If myFile <> Nil And myFile.Exists Then
    Dim p As integer
    Dim tab As String = ChrB(9)
    texin = TextInputStream.Open(myFile)
    texin.Encoding = Encodings.MacRoman //strings are MacRoman
    While Not texin.EOF
      rowFromFile1 = texin.ReadLine
      
      // Set
      If ListBox1.ColumnCount < CountFields(rowFromFile1, tab) Then
        ListBox1.ColumnCount = CountFields(rowFromFile1, tab)
      End If
      
      ListBox1.AddRow("")
      For p = 1 To CountFields(rowFromFile1, tab)
        oneCell1 = NthField(rowFromFile1, tab, p)
        ListBox1.Cell(ListBox1.ListCount-1, p-1) = oneCell1

Not sure where I would stick another code to have the extra code populate the columns instead of rows.
Thanks for the quick reply Dave,
Reid

Ok… I have no idea what you want to do , since this code DOES populate columns

For p = 1 To CountFields(rowFromFile1, tab)
oneCell1 = NthField(rowFromFile1, tab, p)
ListBox1.Cell(ListBox1.ListCount-1, p-1) = oneCell1
next p

So i have 4 files that need to be read. I have it set up right now so that they enter the listbox, but they only populate the first 4 columns and the addrow function, obviously as it states, just adds a row at the bottom of each file coming in. What I would like to do instead is to populate across the columns. so instead of just having one long list of all 4 files, i would like the first file to populate the first 4 columns, the second file to populate the next 4 columns and so on. This would make it so all of the files data are in a line across the columns, instead of in a long line down the first 4 columns. I hope this makes sense.
Right now it looks like this
file1 file1 file1 file1
file1 file1 file1 file1
file2 file2 file2 file2
file2 file2 file2 file2
file3 file3 file3 file3
file3 file3 file3 file3
file4 file4 file4 file4
file4 file4 file4 file4

I want it to look like this
file1 file1 file1 file1 file2 file2 file2 file2 file3 file3 file3 file3 file4 file4 file4 file4
file1 file1 file1 file1 file2 file2 file2 file2 file3 file3 file3 file3 file4 file4 file4 file4

Hopefully this odd diagram clarifies that i want to tell the data to be put into new columns instead of rows.
Thanks,
Reid

off the top of my head

dim i as integer
dim j as integer
dim filename as string
dim f as folderitem
dim txt_in as textinputstream
dim v() as string
listbox1.deleteallrows
for i=1 to 4
   filename="myfile"+str(i)+".txt" // change this to get REAL file name(s)
   f=getfolder("").child(filename) // you may have to adjust this as well
  txt_in=textinputstream.open(f)
  s=txt_in.readall
  txt_in.close
  v=split(s,endofline) // we now have an array will all of file #i
  for j=0 to v.ubound
      if j>listbox1.listcount then listbox1.addrow("")
      listbox1.cell(i,j)=v(j)
  next j
 next i

Thank you Dave,
I am going to try and do this code today and hopefully I can get it to work.
Thanks again,
Reid

This is how I’d write it (in a flash). I don’t use Dialogs and so the ShowModal isn’t handled right. Also it assumes each file has 4 and only 4 columns.

[code] dim dlg As OpenDialog, texin As TextInputStream
dim f As FolderItem, lines() As String, row, p As integer
dim tab As String = ChrB(9)
//--------------------------------
dlg = new OpenDialog
dlg.MultiSelect = true
call dlg.ShowModalWithin(self)

dim files() As FolderItem
For g as integer = 0 to dlg.count-1 //collect files
f = dlg.Item(g)
if f <> nil and f.Exists then files.Append f
next

Listbox1.DeleteAllRows //init listbox
Listbox1.ColumnCount = (files.Ubound + 1) * 4

for g As integer = 0 to files.Ubound //process files
texin = TextInputStream.Open(files(g))
lines = texin.ReadAll.Split(EndOfLine)
texin.Close

row = 0
for i As integer = 0 to lines.Ubound
  if row >= Listbox1.ListCount then Listbox1.AddRow("")
  for p = 0 to 3                     
    Listbox1.Cell(row, g*4+p) = lines(i).NthField(tab, p+1)
  next
  row = row + 1
next

next[/code]

Will,
Thanks for the idea, but the files.Ubound seems to not work because the folderitem does not identify as an array.

It’s declared as an array …

dim files() As FolderItem

Maybe you have something else named files that’s getting picked up?
I’ve run my code to confirm it works so I’m not sure.

Will,
I played around with your way of writing it again, and this time was able to do exactly what I wanted. Thank you for helping me. I am completely new and this helped a ton.
Reid

I wrote this code to covert tab-delimited rows to columns:

[code]Function getTransposeRowsAndColumnsWAD(rowsAndColumns As String) As String
Dim tempInt, tempInt2, tempInt3, tempInt4 As Integer 'columnCount
Dim tempReturn, tempString, tempLine As String = “”

rowsAndColumns = ReplaceLineEndings(rowsAndColumns, EndOfLine)

'saves a lot of wasted time if it is blank
if rowsAndColumns = “” then Return “”

'If there is only one row then turns tabs to returns, speeds things up
if instr(0, rowsAndColumns, EndOfLine) = 0 then Return ReplaceAll(rowsAndColumns, chr(9), EndOfLine)

tempInt2 = commonStrings.getTextColumnCountWAD(rowsAndColumns)
tempInt4 = CountFields(rowsAndColumns, EndOfLine)
for tempInt = 1 to tempInt2
tempLine = “”
for tempInt3 = 1 to tempInt4
tempString = NthField(rowsAndColumns, EndOfLine, tempInt3)
tempLine = tempLine + chr(9) + NthField(tempString, chr(9), tempInt)
next
if left(tempLine, 1) = chr(9) then tempLine = mid(tempLine, 2) 'remove the leading tab
tempReturn = tempReturn + tempLine + EndOfLine
next
if right(tempReturn, len(EndOfLine)) = EndOfLine then tempReturn = left(tempReturn, len(tempReturn) - len(EndOfLine)) 'Remove the trailing return

tempReturn = commonStrings.getRemoveWAD(tempReturn, “Trailing”, “Tabs”)

Return tempReturn

End Function
[/code]