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
- function DataExtract()
- NumberItems=get_select_items()
- MaxItems=table.maxn(NumberItems)
- msgbox(MaxItems .. " items selected","")
- if MaxItems >0 then
- filename="c:\\test.txt"
- io.output(filename, "w+")
- for i=1,MaxItems do
- y=tostring(i)..", "..get_item_text(NumberItems[i]).."\n"
- msgbox(y,"")
- io.write(y)
- end
- io.close()
- else
- msgbox("no selected items","")
- end
- end
Code Lines Description
- Name of the function mandatory for all functions
- 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.
- This is a LUA programming function that sets MaxItems to the size of the vector created in line 1.
- This is a redundant piece of code but useful in testing as it displays MaxItems.
- 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.
- 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.
- 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.
- A for loop from one to MaxItems
- Set a string value based on the data contained in the selected items and store as variable y.
- Another redundant message box but again useful in testing and seeing that something is happening.
- The LUA programming function that writes the data to the file opened for output.
- 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.
- The LUA programming function that closes the file.
- This is the else statement from the if MsgBox > 0.
- The message that there were items selected.
- The end of the iff statement
- The end of the function
References
See the
LUA programming Manual and
eccomagic forum for more details.