Hi, how do I get some values from CSV and getting the values out.
I am trying to make my application to get my Country Location based on my Ip address
The database of Ip address to location is in CSV
For now I get my ip address but how do I search the CSV for my Ip add and print out the Country name?
CountFields and NthFields are your brothers here.
BTW: thank you for sharing the csv files:
a. OS X Finder have troubles with them and do not display them as any other csv file I saw previously,
b. My application that displays csv (and others), also have troubles (only one column is displayed).
I will send you more data on how to load csv files in a couple of minutes or so
Im back. Follow these steps:
- Add code you will find in OpenDialog,
- Add code you find in TextInputStream,
- Convert the pseudo code below (sorry, I do not have my project handly):
Set a bunch of needed variables
Do not forget to add a FileType (cvs); you need that at step #1)
You have a TextInputReference (TIS) that allows you to read the csv file, one line at a time (.ReadLine).
In the TIS example, delete the line (eventually, you do not need the Encoding line):
TextArea1.Text = t.ReadAll
Now, you will add the code to read one line at a time from the .csv file from here
While Not csvTIS.EOF
// Get one line
One_Line = csvTIS.ReadLine
// Is my IP Address in this line ?
If Instr(OneLine,"") > 0 Then
// You find the line where your IPAddress is.
// You may use CountFields and NthField here.
// Deal with it
// and exit the loop
csvTIS is my name for a TextInputStream (t in the example).
I hope my code is correct, I wrote it from memory, but you get the idea, if I am right.
Ask if this is unclear.
BTW: I now understand why Apple (and me) have troubles with that csv file: the first line is a © line and this is not allowed (as is) in a csv file. The real csv data start from line #2 where we can see the column names (headers) of what is in the file starting at line #3.
Sorry for the code without the tags: I could not change the previous text.
To read the file named “GeoLiteCity-Blocks.csv”, with my project application, I had to:
a. Remove the first line (the copyright line),
b. add surrounding quotes to the three field names in line 2,
c. remove the empty line at the end of the document.
But, I already found strange files
csv files saved with a .txt file type extension (instead of .csv). (and one of my testing file, I replaced \Tab with Comma, does works excepted in one line where I have two commas in a column: I have to investigate