Does anyone have a routine that reads CSV files of certain length? Moreover, I 'd like to know what the fastest way is to read these files. Do you have to use SQL?
thnx
Marc
The easiest way is to load the file into a table.
From there you can extract the data you want.
You can also use SQL which is faster for large databases, however I'm yet to learn how to use SQL (maybe some time soon I'll give it a try).
I was wondering whether anyone had a routine which regardless of the parameters (which are read at runtime and passed through) could read a csv file. I am not too familiar with SQL myself, so I hope someone is.....
Marc
You don't need to understand SQL to use the table control.
The table control is very simple to use and will load the CSV file directly into the table cells.
All you then need to do is either filter the table or just extract the desired cells.
Well, I dont need a table actually. i want to store over a few million data in the CSV file to retrieve with a search function matching one or two entries.
Well, I dont need a table actually. i want to store over a few million data in the CSV file to retrieve with a search function matching one or two entries.
You would be best to use SQL, although my understanding is that a table will still be required for SQL to utilise.
My approach is usually to try and understand a few examples of other peoples work and then tailor it to my own needs.
Here is a link to an example that Erel did some time ago, maybe it will help you... http://www.b4x.com/forum/showthread.php?t=843&highlight=SQLite
I want to store a table containing numbers. The program computes the rank of a hand in poker with 7 cards, taken the best 5 out of it (Texas Holdem). Because there are 133784560 combinations with 7 cards out of 52, it takes too long to compute the hands, especially because I want to run simulations with dealing a lot of hands (Monte Carlo simulation) and compute the probability of winning with that certain hand against other random AI-hands. Therefore I want to generate a table and compare the hand to an index (with a unique longinteger) and retrieve the value of the hand.
Marc
I recommend you to use the BinaryFile to store the data in a raw file.
Write with WriteInt64 and read with ReadInt64.
Every number occupies 8 bytes so it is very easy to navigate the file.
I want to store a table containing numbers. The program computes the rank of a hand in poker with 7 cards, taken the best 5 out of it (Texas Holdem). Because there are 133784560 combinations with 7 cards out of 52, it takes too long to compute the hands, especially because I want to run simulations with dealing a lot of hands (Monte Carlo simulation) and compute the probability of winning with that certain hand against other random AI-hands.
You're going to have fun sorting out which hands are valid after you drew the first cards & the subsequent interactions that get you to 7 cards drawn per hand...
I might have the wrong end of the stick - are you simply calculating the probable outcomes for a hand played all the way through, or are you including the role of the evolving shared cards in determining whether you play to the end?
The first part of the program is to caculate the outplayed hand (7 cards). With that I can simulate dealing let's say 200000 hands and calcuate probabilities and distribution. Then for the second part I want to calculate probabilities to reach a certain hand with the ongoing play after dealing the several rounds.
The idea is whether I can create a table with pointers after each card to a next table with remaining possibilities. I haven't got it quite clear yet, but the first idea is to build the "mothertable" of all 133784560 combinations.
Marc
But can I get back to the original question? What is the general format/ routine to read in CSV files. There are a number of CSV files on the net that I can use to train my program. After that I can write my own table in BinaryFile.
thnx
Marc
Open one with Wordpad or Notepad. They are just normal text files.
B4X:
If FileExist ("text.csv") = true Then
FileOpen (c1,"text.csv",cRead ,, cASCII)
r = FileRead (c1)
Do Until r = EOF
fields() = StrSplit(r,",")
Msgbox(fields(0) & " - " & fields (1)) ' do whatever with the fields
r = FileRead (c1)
Loop
FileClose (c1)