Ok, first - I going to post a solution - a NICE one. The poster will LOVE this.
Next up? Boy - nice to have some egg on our faces.
Man, rummaging around in my closet for a computing science book! (yes, true!! - did not find that book).
Near bringing in NASA, the the Mars lander team - and suggesting high complex solutions?
Yup - guilty!!!
So, here we are running around with white lab coats? Yup?
Suggesting a database system? Yup - guilty!
You what we REALLY should do?
Let's go back 27 posts!!!! - and do 100% what you asked!!!
Lets read a text file into a array or say a list?
Ok, no problem!!!
This works REALLY fine!!!!
Now I am making "some" fun at myself above? But its actually fair!!!
One really big interesting advantage here? Well, that table is 147,000 rows, but it is VERY narrow!
Most csv files - say from Excel will have 20, 30 columns. You have 3 columns!!! (3!!!!).
So, that is 10x LESS then say a typical table of 30 columns.
Now to be fair - my napkin estimates for time some posts back? They are spot on - but I am seen even better times.
I am now running these in release mode
So, we now have this:
And that is 149,000 rows - the posted file. Well, gee, it less then one second!!!
How about a row loop row by row search on 149,000 rows. I have a "random" button in above. It picks between 0-149,000. So, whack a few times untill at least we get a test for over 100k rows. This looks good - 110,000 row - raw loop search:
Well, Bob is your uncle!!! - to raw loop in "basic" code, we find the 110865 position in 0.26 seconds!!!! (2/10th of a second).
so this means we don't need NASA, we don't need my computing science book. And we do not need a database either!!!
Also note, the view table button in above? I dragged in and dropped in a B4xTable.
Now that is taking 7 seconds to load - I'll consider lazy loading it. But hit view table, and you now get this:
And note the search bar!!!! - i did NOT write ONE line of code for all of the above screen to work!
So the "red" text is matching what you search/type into that box!!!
(it called B4Xtable if you wondering - it is a built in feature.).
So in summary:
B4A - it just rocks - it quite much blew both my shirt and pants off!!!
No NASA, no computing science books. No binary data chop search.
No database either!!!
In a brilliant bout of beautiful tasty egg on my face?
I read a text file - in to a list (that's much like a array).
Now, wait - wait - wait for it!!!
The poster 27 posts back?
Can we read a text file into an array or some such?
Why can't I just read a text file?
The answer? yes, you can - and it not all bad of a idea either!!!
Anyone have a Rube Goldberg comic handy?
Hum what should we do? Call NASA? Dig out computing science books?
Perhaps we get the Mars Rover software team involved?
No, what we need to do is read the text file!!!
Now, to be fair? Credit goes to B4A- too much over thinking, too much NASA and computing science being applied here.
Just read a text file into the list. Now you can search it with the first screen, but the B4A table? well, now you can page to next page, type in a search (it's partial match), and it works - and works amazing well!!!
The whole app - including the zipped file is attached. Do remember, you want to run it in release mode - since you find the whole table load, and searching the whole list? Both occur in well under 1 second of time!!!
One little note. You have to include your text file - I did not in the sample posted. Also, your sample has a funny character or who knows what. (but the file was not being seen in B4A correctly. So copy your txt file. I have named it "analperk1.txt" (all lower case).
So, after you un-pack the sample? You have to add the analperk1.txt file to the B4A project. From menu, go windows->files manger.
Then here simply choose add files:
Browse to that newly named file (a copy) of your text file - we assume it is now named this: analperk1.txt
So, after adding to above, you see this:
So, after above, then you should be good to go with the sample project.
In Summary:
B4A is showing more performance then I give it credit for.
Loading/reading 150k rows - not out of the question.
Searching with a raw loop againast that "list" row by row? Not a problem!
And better yet, tossing the whole box, and everyting over to B4XTable?
You get a search system, a system to view, look at data.
As noted, there is a significant delay in opening that large table - but we can work that probem.
Summary #2:
This was a lot of fun, and I learned some new things. Learned that while your table was large? It was "narrow" and that was a HUGE help in working out this problem.
The read code for the file? I used this:
Dim su As StringUtils
ProgressBar1.Visible = True
EditText1.Text = "running"
Sleep(0)
MyList.Initialize
Dim t1 As Long = DateTime.Now
EditText1.Text = "reading text file - wait" & CRLF
Sleep(0)
MyList = su.LoadCSV(File.DirAssets,"analperk1.txt", ",")
EditText1.Text = EditText1.Text & "Done reading - time = " & NumberFormat((t1 - DateTime.Now)/1000,0,2) & CRLF
ProgressBar1.Visible = False
So, using a built in "reading" library was nice - it was fast, and easy to do.
And while arrays() are possible, the "list" is easier to use - and it more dynamic (we don't have a re-dim array() like we do in VB, but with "lists", I tend to never miss that feature - and suggest you adopt a list in place of a array - they are easy to use, similar to a array, but better in most cases.
I don't know how much main memory your phone has. Mine is 2 gig. I think a 1 gig main memory phone would work ok.
And my phone has a older a53 CPU - so it again somewhat lower end. If you phone has better specs then above - then you see even better performance.
So try the sample. Just remember to re-add the text file as the new above name.
Regards,
Albert D. Kallal
Edmonton, Alberta Canada