First web app questions. Issue #1 I create a csv file from a webListbox for download which works except row 1 is empty. All the row data is there it just begins in row 2. Seems simple to fix but I just get outOfBounds errors. Code is below. Where should I look?
[code] if MyList.RowCount>0 Then
for i=0 to MyList.RowCount-1
s=s+chr(13)
for j=0 to MyList.ColumnCount-1
s=s+MyList.Cell(i,j)+ ","
next
tos.WriteLine s.Left(s.len-1)
next
end if
tos.Close[/code]
Issue #2 The download works fine (well, except for the row problem above) when running the webApp on the desktop. File is downloaded to the downloads folder where I can then use it as I wish like - upload it to another site or email it etc. . I would like it to do a similar thing when using an iPad. The file just opens in another window and the webApp disappears. I guess it works differently in this case. Do I need to download the file to the server first or can it be saved to the iPad? Any links to how this works on an iPad would be great. Thanks.
What is s to start with? You are adding s = s + chr(13), i.e. if s is empty to start, you just added an empty line.
Also, 2 notes:
You don’t need your outer If statement. If RowCount = -1, then your loop will be For i = 0 To -1 which will never execute.
You may want to give up appending to s all the time. Strings are immutable, it’s expensive. It is less memory and time if you were to do something like:
Dim lines() As String
For i As Integer = 0 To MyList.RowCount - 1
Dim cols() As String
For j As Integer = 0 To MyList.ColumnCount - 1
cols.Append MyList.Cell(i, j)
Next
lines.Append Join(cols, ",")
Next
tos = OpenCodeHere
tos.Write Join(lines, EndOfLine)
tos.Close
The above also initializes loop variables only within the scope they are used, which is also a good practice (in most cases).
Thank you both for such quick help. Great tips and things are working better now. So Norman, one would need to have a csv capable app installed then route the file to that app somehow?
If you “download” a file in Safari, you’ll get a screen asking if you want to open the file in an app. I see this all the time when downloading PDF files.
On my iPad, I get 3 choices: AirDrop (to share with another user), Open in Zoom and Open in DropBox.
Thanks to all for the help. Jeremy, if you’re still out there? ( or anyone else) Your code is nice and fast thanks again. One question, where and how within that code would I put code that would escape any “,” within a string? My feeble attempt mucked things up.
The line cols.Append MyList.Cell(i, j) is where the string data is being inserted into the array that will later be joined by a ,. I would assume you need to place quotations around the strings. So something like:
cols.Append """" + MyList.Cell(i, j) + """"
Now, that only solves one problem, because now you have to escape the quotes inside the quoted string, and that begins to look convoluted because of the way Xojo handles nested quotes. i.e. Print """" would print a single ". Another example, Print "John ""McHenry"" Donald" would print: John “McHenry” Donald.