Problem with csv.ahk code

Get help with using AutoHotkey and its commands and hotkeys
omar
Posts: 303
Joined: 22 Oct 2015, 17:56

Problem with csv.ahk code

20 Jul 2018, 20:40

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.
Guest

Re: Problem with csv.ahk code

21 Jul 2018, 01:12

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
User avatar
Xtra
Posts: 1269
Joined: 02 Oct 2015, 12:15

Re: Problem with csv.ahk code

21 Jul 2018, 01:25

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
omar
Posts: 303
Joined: 22 Oct 2015, 17:56

Re: Problem with csv.ahk code

05 Aug 2018, 19:36

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?
Guest

Re: Problem with csv.ahk code

06 Aug 2018, 02:01

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.
omar
Posts: 303
Joined: 22 Oct 2015, 17:56

Re: Problem with csv.ahk code

08 Aug 2018, 09:47

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
Guest

Re: Problem with csv.ahk code

08 Aug 2018, 10:01

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.
frd
Posts: 12
Joined: 19 Jul 2018, 10:01

Re: Problem with csv.ahk code

31 Oct 2018, 12:26

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!!!
ahk7
Posts: 124
Joined: 06 Nov 2013, 16:35

Re: Problem with csv.ahk code

31 Oct 2018, 12:59

Unless love is a variable you need to quote it

MsgBox % CSV_MatchCell("Data","love")
frd
Posts: 12
Joined: 19 Jul 2018, 10:01

Re: Problem with csv.ahk code

01 Nov 2018, 07:33

Thanks so much!!! :)


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

Return to “Ask For Help”

Who is online

Users browsing this forum: Hatsuko, kczx3 and 25 guests