Page 1 of 1

Problem with csv.ahk code

Posted: 20 Jul 2018, 20:40
by omar
I'm using the code from here:

https://github.com/hi5/CSV/blob/master/csv.ahk

It works really well.
I have a small problem though with searching for matches.

I have a file of IP numbers - each IP being one a new line

I read the CSV and need to find out if the current IP is in the list.
All is well and it works 99.5% of the time.

PROBLEM:

123.12.108.12
is considered to be the same as: 123.12.108.120

I search using this function call: CSV_Search("myIPCSV", myIP)
(so, i've already read in the CSV file and stored the current IP in the variable above - these parts are definitely working)

Can anyone suggest what I might be doing wrong?
Could it be the periods in the IP number are causing problems?
If so, how do I overcome?

EDIT: I've tried using this function: CSV_MatchCell("myIPCSV", myIP)
this doesn't work. i'm guessing the period are causing problems?
it DOES work - for other searches that aren't IP numbers.

Thanks.

Re: Problem with csv.ahk code

Posted: 21 Jul 2018, 01:12
by Guest
CSV_Search uses IfInString to it uses a partial match but CSV_MatchCell should work as shown in this test script. My guess your MyIp variable is not what you think it is or should be

Code: Select all

FileDelete,testdata.csv
FileAppend,
(join`r`n
a,b,c
123.12.108.120,e,f
), testdata.csv


CSV_Load("testdata.csv", "data")

ip=123.12.108.12
MsgBox % CSV_MatchCell("data",ip) ; shows 0 so it can't find it which is correct

ip=123.12.108.120
MsgBox % CSV_MatchCell("data",ip) ; shows 2,1 so it can find it which is correct

ExitApp

Re: Problem with csv.ahk code

Posted: 21 Jul 2018, 01:25
by Xtra
Can anyone suggest what I might be doing wrong?
You arent doing anything wrong the function is using IfInString.

This line in the csv_search() function is the problem.
IfInString, CurrentString, %SearchText%

Which should/could be changed to: if (CurrentString = SearchText)


HTH

Re: Problem with csv.ahk code

Posted: 05 Aug 2018, 19:36
by omar
thanks for the replies guys.
i'll make the change suggested and give it a go.

EDIT: so the author of the code should make change accordingly?

Re: Problem with csv.ahk code

Posted: 06 Aug 2018, 02:01
by Guest
No, CSV_Search and CSV_MatchCell work as intended, if you where to apply the "fix" by Xtra CSV_Search and CSV_MatchCell would be the same function and you wouldn't be able to search for cells containing certain data.

Re: Problem with csv.ahk code

Posted: 08 Aug 2018, 09:47
by omar
guys
thanks for the replies

one think i did say was:

EDIT: I've tried using this function: CSV_MatchCell("myIPCSV", myIP)
this doesn't work. i'm guessing the period are causing problems?
it DOES work - for other searches that aren't IP numbers.


so... i'm guessing i still have problems?

the if call they have in the CSV_MatchCell() function is: IfEqual, CurrentString, %SearchText%
which is the same thing as what you guys suggest (i read up, it matches without being case sensitive)

trying now anyway the suggested

Re: Problem with csv.ahk code

Posted: 08 Aug 2018, 10:01
by Guest
As the demo code above shows it works. If it doesn't work for you it could be because of two reasons:

1. myIP doesn't have the value you think it has, perhaps it is a trailing space or newline character check with MsgBox % ">" myIP "<" perhaps you see something (you could try trim(myIP) to explicitly trim spaces and/or other chars, read the trim docs

2. your csv data (cell) doesn't match because the value in there isn't correct, again it may have "some character" which cause the IfInstring or IfEqual to fail. Check with a msgbox similar to the one above.

99.99999999999% sure it is one or both of these reasons. So check your data.

Re: Problem with csv.ahk code

Posted: 31 Oct 2018, 12:26
by frd
Please, someone can help me?

https://raw.github.com/JnLlnd/ObjCSV/ma ... eatles.txt

I'm loading this file as a CSV (saved it and changed the extension)

Code: Select all

F1::
CSV_Load("TheBeatles.csv", "Data")
MsgBox % CSV_ReadCell("Data", 31, 1)
Return
This works fine! =D

Code: Select all

F2::
CSV_Load("TheBeatles.csv", "Data")
MsgBox % CSV_MatchCell("Data",love)
Return
This second doesn't work!
Thanks in advance!!!

Re: Problem with csv.ahk code

Posted: 31 Oct 2018, 12:59
by ahk7
Unless love is a variable you need to quote it

MsgBox % CSV_MatchCell("Data","love")

Re: Problem with csv.ahk code

Posted: 01 Nov 2018, 07:33
by frd
Thanks so much!!! :)


:bravo: :bravo: :bravo: :bravo: