Announcement

Collapse
No announcement yet.

CSV File Search

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • CSV File Search

    I'm a bit rusty with Autoplay as I haven't had the need to create a new project in years but I am working on a new project and have hit a bit of a road block.

    A little background of what I am trying to accomplish. I have a CSV file on an FTP that contains 2 fields of data on each line like so:
    "123","abc.lic"
    "456","efg.lic"

    What I am trying to do is to read in the CSV file, search based on data in the first field. If a match is found, I need to capture the data in the second field so I can use it further on in the script. I have the button setup to download the file locally.

    What I have tried so far is:
    Code:
    -- Read contents of file to a string
    contents = TextFile.ReadToString("C:\\faircomlic.txt");
    
    -- Search string for sentinel number that is in registry
    sentfound = String.Find(contents, registrysent, 1, false);
    This searches the string and finds a match, but how do I pull the data from the second field?? Additionally, this only captures the position, not necessarily a line number.

    I'm thinking that I need to read the text file into a table, but I don't see how I can search the table. Any help or guidance would be greatly appreciated.
    Matt Leach
    GalacTek Corp.
    www.galactek.com

  • #2
    Have a look at the attachment. I created a file without quotes, this should be easy enough to adapt if a change is required.

    Ulrich
    Attached Files

    Comment


    • #3
      Hello Urlich,

      Thank you for the example. Unfortunately it appears as though there may be an issue with the search. Using your example, I edited the code to point to a csv file on the c: drive.
      I then inputted a search string that I know is in the file, however the results say not found. I verified that it is in fact in the file.

      In the project I am working on, everything will be controlled by a single button. Once clicked, it will download the file. The search string is actually pulled from a registry value so there would be no input required for the search. I took your code from the sample file and applied it to the button I have setup. I set a temporary search string that is a hard-coded value for testing purposes (a value I know is in the file) and am getting an error - Attempt to call global 'DelimitedStringToTable' (a nil value)

      I've attached a copy of the project as well as a copy of the csv file. I am by no means expecting you to edit the file, but perhaps it may help to see if I am doing something wrong.

      Again I greatly appreciate the assistance.
      Attached Files
      Matt Leach
      GalacTek Corp.
      www.galactek.com

      Comment


      • #4
        You did not add the DelimitedStringFunctions Lua script to your project. Also, you do not have the Input object where my code displayed the output.

        Click image for larger version

Name:	SCRN-2017-02-16-01.png
Views:	26
Size:	4.2 KB
ID:	297601

        Ulrich

        Comment


        • #5
          Completely overlooked adding the lua script. My apologies.

          Everything is now working.

          The reason I don't have an input object is because I will not be inputting the search criteria, it will be pulled from the registry. Added the lua script and everything is now working.

          Thank you very much for the assistance!
          Matt Leach
          GalacTek Corp.
          www.galactek.com

          Comment

          Working...
          X