Sample Program 1


Description


This bit of code was developed for the purpose of testing the input/output capabilities of eccoext LUA programming. Once as a CSV file the collected data can be imported to other files for other purposes. The intent is to extract job costing information which could then be used for creating invoices and time records for payroll.

Program Code



  1. function DataExtract()
  2. NumberItems=get_select_items()
  3. MaxItems=table.maxn(NumberItems)
  4. msgbox(MaxItems .. " items selected","")
  5. if MaxItems >0 then
  6. filename="c:\\test.txt"
  7. io.output(filename, "w+")
  8. for i=1,MaxItems do
  9. y=tostring(i)..", "..get_item_text(NumberItems[i]).."\n"
  10. msgbox(y,"")
  11. io.write(y)
  12. end
  13. io.close()
  14. else
  15. msgbox("no selected items","")
  16. end
  17. end

Code Lines Description

  1. Name of the function mandatory for all functions
  2. Sets a variable NumberItems to the total number of selected items. Please note that the intent is to select all items in a notepad after they have been filtered and sorted in this way there is no need to do the filtering after the fact. It is possible though to import the data into a data base and then do further manipulation to suit specific needs.
  3. This is a LUA programming function that sets MaxItems to the size of the vector created in line 1.
  4. This is a redundant piece of code but useful in testing as it displays MaxItems.
  5. This conditional statement tests to see if the MaxItems is greater than zero. If it is then data is extracted, if not then a warning message is displayed and the program does nothing.
  6. A filename is set, in this case it is set to test.txt in the root of drive c. Any name or location will work. In this case, for testing it was a simple name and convenient location.
  7. Another LUA programming function that opens a file for output using the filename in line 5 and the "w+" indicating to clear the file before writing to it.
  8. A for loop from one to MaxItems
  9. Set a string value based on the data contained in the selected items and store as variable y.
  10. Another redundant message box but again useful in testing and seeing that something is happening.
  11. The LUA programming function that writes the data to the file opened for output.
  12. The end of the for loop after all of the selected items have been worked upon with the appropriate data extracted and stored in the CSV file.
  13. The LUA programming function that closes the file.
  14. This is the else statement from the if MsgBox > 0.
  15. The message that there were items selected.
  16. The end of the iff statement
  17. The end of the function

References


See the LUA programming Manual and eccomagic forum for more details.