Hello all,
I have a list box with 4 columns. I cannot figure out why all of the data appears in the first column, and is not distributed in each column as it should be.
In one method:
Dim FileNames() As String
if thisExt = FileExtension Then
Dim RecCount As Integer = getRecordCount(thisFile)
FileNames.Append thisName + "," + thisfile.CreationDate.ShortDate + ","+ Cstr(thisFile.Length) + "," + Cstr(RecCount)
end if
Return FileNames()
//return type is String()
In another method:
Dim a() As String = App.ManageFileTransfer.getFileList
For i As Integer = 0 to A.Ubound
frmNotice.FileList.AddRow a(i)
Next i
The data is retrieved, but it always is loaded into the first column only.
Can anyone tell me what I am doing wrong?
A “part” fix:
I found one cause of the problem, I was had not created the array properly. Removing the + “,” + code parts and adding Array(…) is what solved it.
This code fixed it:
Dim s() As String
s = Array(thisName,thisfile.CreationDate.ShortDate,Cstr(thisFile.Length),Cstr(RecCount))
frmNotice.FileList.AddRow(s)
But that only got it half way, since the real problem was that
Sorry, could posted too soon, and then could not edit the post above…
The problem now is that I cannot figure out how to add an array to an array, then pass that back to the calling method.
What is the proper way to add an array to an array?
dim v() as variant
Dim s() As String
s = Array(thisName,thisfile.CreationDate.ShortDate,Cstr(thisFile.Length),Cstr(RecCount))
v.append s()
return v()
then in your other function
Dim a() As variant = App.ManageFileTransfer.getFileList
dim s() as String //this type must match the original array type
For i As Integer = 0 to A.Ubound
s()=a(i)
frmNotice.FileList.AddRow s()
Next i
I’d stick with a comma delimited string and then turn it into an array when you add it to the listbox.
Dim a() As String = App.ManageFileTransfer.getFileList
Dim b() As String
For i As Integer = 0 to A.Ubound
b = split(a(i), ",")
frmNotice.FileList.AddRow b
Next i
What I wound up doing, was to create a class, with n properties. Then I created an array of this class. The array was filled using a tmp version of that same class. Once filled, I returned a pointer to the class/data.
Dim tmpFileListArray As New clsFileListArray
tmpFileListArray.FileLength = thisFile.Length
tmpFileListArray.FileName = thisName
tmpFileListArray.RecordCount = RecCount
tmpFileListArray.ShortDatrStr = thisfile.CreationDate.ShortDate
FileListArray.Append tmpFileListArray
Tim H introduced/showed me how to use these class pointers in another project. They work really well, especially as in this case, where the same data may be used more than once…
Tim
[quote=37229:@Tim Seyfarth]Hello all,
I have a list box with 4 columns. I cannot figure out why all of the data appears in the first column, and is not distributed in each column as it should be.
[/quote]
The docs are your friend.
AddRow doesn’t take a comma separated value, split it and put it in each column. http://documentation.xojo.com/index.php/ListBox.AddRow
Basically your code would turn into
In one method:
Dim FileNames() As String
if thisExt = FileExtension Then
Dim RecCount As Integer = getRecordCount(thisFile)
FileNames.Append thisName + chrb(9) + thisfile.CreationDate.ShortDate + chrb(9) + Cstr(thisFile.Length) + chrb(9) + Cstr(RecCount)
end if
Return FileNames()
//return type is String()
In another method:
Dim a() As String = App.ManageFileTransfer.getFileList
For i As Integer = 0 to A.Ubound
frmNotice.FileList.AddRow ""
frmNotice.FileList.cell( frmNotice.FileList.LastIndex, -1) = a(i)
Next i