FUNCTION DoSomething(param1, param2) * code that does something RETURN someValueIt looks like a function. It smells like a function, but it may in fact not be a function.
value1 = 12
value2 = "Hi there"
? DoSomething(value1, value2)
and it will behave like a function. The parameters are passed by value and the return value is display on _SCREEN.value1 = 12 value2 = "Hi there" DO DoSomething WITH value1, value2Here, it's a procedure. The return value is ignored and the parameters are passed by reference.
PROCEDURE DoSomething LPARAMETERS param1, param2 * code that does something RETURN someValue>I haven't used functions before - I have always avoided them - this is my code but it gives errors
>DO xls_import > >FUNCTION xls_import > > >PARAMETERS tcFile >** Replaces VFP Import Command for XLS. VFP Command does not accept xlsx file formats >** First try the standard import. >** If it failes with error code 1661 (Microsoft Excel file format is invalid.) then open Excel and resave with format 39( xlExcel5, xlExcel7 ) >** Try to import again. >** If it succeeds, return the name of the table >** If it still fails, return an empty string. Calling program will check for EMPTY() to determine success > >LOCAL lcReturn,lcNewFile >lcReturn = "" > >TRY > IMPORT FROM ("c:\colin.xlsx") XLS > lcReturn = DBF() >CATCH > =AERROR(abcde) > IF abcde[1] = 1661 > tmpoxl=CREATEOBJECT("excel.application") > tmpoxl.DisplayAlerts = .F. > tmpoxl.Application.WorkBooks.Open(tcFile) > lcNewFile = "c:\tempdl\" + JUSTFNAME(tcfile) > tmpoxl.activeworkbook.saveas(lcnewfile,39) > tmpoxl.quit > tmpoxl= .null. > TRY > IMPORT FROM (lcnewfile) xls > lcReturn = DBF() > CATCH > ENDTRY > DELETE FILE (lcnewfile) > ENDIF >ENDTRY >RETURN lcReturn >