SetDefault() and Copy To Questions/Issues
Posted: Wed Aug 19, 2020 3:44 pm
I am continuing to do simple testing using XIDE to start. I ran the following code and observed that while SetDefault() works for opening a .DBF file, it did not control where the COPY TO outputted file was created -- it went to C:XIDEProjectsTestBinDebug rather than F:XSharp. Is this the expected behavior? (FWIW, in VFP users can set the default directory to be the directory from which VFP is called by setting Tools|Options|File Locations|Default Directory to be "(Not Used)")
I also tried changing the COPY TO test command to COPY TO test CSV which did not compile. I'm assuming that this functionality may not have been created yet? If not, the following code that I wrote for Harbour may be useful (I'm not particularly familiar with #command, etc., so this probably can be done better:
Finally, I also tried COPY TO test DELIMITED but got the following error:
Regards,
Jeff
Code: Select all
FUNCTION Start( ) AS VOID
TRY
SetDefault("f:xsharp")
FoxProMessage = "Hello VFP!"
? FoxProMessage
USE deallist
? dealname
SKIP
? dealname
COPY TO test
Use
CATCH e AS Exception
? e:ToString()
END TRY
WAIT
RETURN
Code: Select all
**routine to create a csv file for HBR
procedure make_csv()
parameter csvfilename
local x, xhdr, xtemp, WshShell
xtemp = "temp1.dat"
xhdr = ""
FOR x := 1 to FCOUNT()
xhdr = xhdr + '"'+rtrim(FieldName(x))+'",'
NEXT
fhandle = fcreate(xtemp, 0)
if fhandle < 0
eti_msgbox("Error creating error file: "+ xtemp)
wait
quit
endif
writelen = fwrite(fhandle, xhdr)
if writelen <> len(xhdr)
eti_msgbox("Error writing to "+ xtemp)
quit
endif
fclose(fhandle)
copy to temp2.dat delimited
WshShell = win_OleCreateObject("WScript.Shell")
run_command = 'copy temp1.dat + temp2.dat '+csvfilename+' & del temp1.dat & del temp2.dat & exit'
WshShell:Run("cmd /K "+run_command, 0, 1)
return
I've attached the deallist.DBF file to help determine why the COPY command failed.System.ArgumentOutOfRangeException: Year, Month, and Day parameters describe an un-representable DateTime.
at System.DateTime.DateToTicks(Int32 year, Int32 month, Int32 day)
at XSharp.RDD.TEXTRDD._getFieldString(RddFieldInfo oField, Object oValue)
at XSharp.RDD.DELIM._writeRecord()
at XSharp.RDD.TEXTRDD.GoCold()
at XSharp.RDD.TEXTRDD.Append(Boolean lReleaseLock)
at XSharp.RDD.Workarea.TransRec(DbTransInfo info)
at XSharp.RDD.DBF.TransRec(DbTransInfo info)
at XSharp.RDD.Workarea.Trans(DbTransInfo info)
at XSharp.CoreDb.<>c__DisplayClass107_0.<Trans>b__0()
at XSharp.CoreDb.Do[T](Func`1 action)
at XSharp.RT.Functions.DbTrans(__Usual[] Xs$Args)
at XSharp.RT.Functions.DbCopyDelim(__Usual[] Xs$Args)
at XSharpFoxPro1.Exe.Functions.Start() in f:xsharptestappPrgStart.prg:line 11
Press any key to continue...
Regards,
Jeff