iOS Question B4i text file handling

vikingivesterled

Member
Licensed User
I can't find a textreader/writer in B4i. There is a Write/ReadLine function in both B4a, B4j, and Microsoft's VS express (for winphone development).

The pure Input/OutputStream is not really a replacement and has very limited options. With ReadBytes it seems you need to know the string length beforehand. Is there a way of reading all characters until next CR.

I store the app's data in multi-line files with a certain info in each line, and are trying to find the easiest way to convert the code from B4a to B4i. Also use files for temporary storing the data returned from HttpJob requests.
Maybe someone can point me to a file reading/writing sample. It's early days and not that many B4i samples in the forum, compared to what you can find on B4a topics.
 

vikingivesterled

Member
Licensed User
Use File.ReadList. It will return a list with all the lines.
Will I then not need to read the whole file in one go into a listview and therefore need to know how many lines the file contains to dimension the receiving array beforehand.
I write the number of lines in a file to the first line of the file, so I can dimension the receiving array based on how large the file is. This won't work if I can't read a file line by line. The first app I'm converting from b4a to b4i is a messenger, and both stored data files and data returned from http requests consists of varying numbers of lines.
I also use version numbering in the first line of settings files, so I can in later versions ad more data to the end of files, but keep the compatibility to read earlier versions during/after app upgrades. Also depends on being able to read a file one line at a time.
 
Upvote 0

vikingivesterled

Member
Licensed User
The File.Readlist/File.WriteList will do the job, but it has moved from a simple b4a to b4i port, to a complete rewrite.

Is there a technical ios reason there is no WriteLine/ReadLine option in b4i? In case, could it not have been handled by a built in background, via list, process/lib. Like: read file to list, add 1 item to list, write list to file. I know it would not be optimal use of resources, but it would aid compatibility with code already written for b4a and b4j.
 
Upvote 0

vikingivesterled

Member
Licensed User
Thank's for your replies.
I understand the principle of using ReadList, and have the first part module working after rewrite.
However I have 2 years worth of development in b4a = 13 apps to convert to b4i (long awaited - thank you for supplying), with several modules using this functionality multiple times in each. So it was a bit of a surprise to discover that something that converted so easy from b4a to b4j (and to VS Express) was no longer there.
I will write a ReadLine sub myself for now, imitating the ReadLine functionality using ReadList.
 
Upvote 0

stevel05

Expert
Licensed User
When you first posted, I searched the IOS documentation for a native IOS readline from file call, it doesn't exist. This solution is simpler than those proposed by programmers using XCode and IOS natively.
 
Upvote 0

vikingivesterled

Member
Licensed User
If I'm now to use list, what happened to the ListView object from the b4a Designer.
Is the solution for b4i for a view where one can select a line from a viewed list, to use Picker instead? (a view that isn't listed in b4a)
Or is there another more suitable (simpler ported) View.

I understand there is significant differences between android and ios, but is it not important to make b4i as compatible with b4a as possible so they who have developed lots of stuff in b4a can easily port it to b4i?
 
Upvote 0

johan vetsuypens

Member
Licensed User
Is it possible that File.ReadList has a limit on the file size of the ascii file I want to read ?

When I try to read a large ASCII file I get an error. When I try with a smaller file, it seems to be OK.
Attached the ASCII file

Dim oList As List = File.ReadList(File.DirDocuments,"AD_Stocks_DB.txt")


Error occurred on line: 3793 (main)
Error reading file. Incorrect encoding
Stack Trace: (
CoreFoundation <redacted> + 150
libobjc.A.dylib objc_exception_throw + 38
CoreFoundation <redacted> + 0
iStock -[B4IFile ReadString2:::] + 524
iStock -[B4IFile ReadString::] + 86
iStock -[B4IFile ReadList::] + 70
CoreFoundation <redacted> + 68
CoreFoundation <redacted> + 300
iStock +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1928
iStock -[B4IShell runMethod:] + 496
iStock -[B4IShell raiseEventImpl:method:args::] + 1846
iStock -[B4IShellBI raiseEvent:event:params:] + 1316
iStock __50-[B4I raiseEventFromDifferentThread:event:params:]_block_invoke + 74
libdispatch.dylib <redacted> + 10
libdispatch.dylib <redacted> + 22
libdispatch.dylib _dispatch_main_queue_callback_4CF + 718
CoreFoundation <redacted> + 8
CoreFoundation <redacted> + 1512
CoreFoundation CFRunLoopRunSpecific + 476
CoreFoundation CFRunLoopRunInMode + 106
GraphicsServices GSEventRunModal + 136
UIKit UIApplicationMain + 1440
iStock main + 116
libdyld.dylib <redacted> + 2
)


Can I use another function to read line by line from an ASCII file ?
 

Attachments

  • AD_Stocks_DB.txt
    18.4 KB · Views: 155
Upvote 0

stevel05

Expert
Licensed User
Error reading file. Incorrect encoding
Have you checked the encoding of the files? Are they the same? If you open them in something like programmers notepad, you can find the encoding under the file menu.
 
Upvote 0
Top