SetDefault() and Copy To Questions/Issues

This forum is meant for questions about the Visual FoxPro Language support in X#.

Post Reply
Jeff Stone
Posts: 37
Joined: Fri Jun 07, 2019 4:16 pm

SetDefault() and Copy To Questions/Issues

Post by Jeff Stone »

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)")

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
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:

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 
Finally, I also tried COPY TO test DELIMITED but got the following error:
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...
I've attached the deallist.DBF file to help determine why the COPY command failed.

Regards,

Jeff
Attachments
deallist.zip
(2.02 KiB) Downloaded 45 times
User avatar
Chris
Posts: 4898
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

SetDefault() and Copy To Questions/Issues

Post by Chris »

Hi Jeff,

Thanks for your reports! All are confirmed and will log them to be fixed:

1 - COPY TO should indeed create the file in the directory set with SetDefault(), this is a bug

2 - Indeed, COPY TO ... CSV is not implemented, but I think it was just forgotten to add include the command, so it shold be easy to do that. COPY TO ... SDF already works.

3 - This is also a bug, something goes wrong when trying to emit the date fields. I think this will also be not difficult to fix.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
Post Reply