PDA

View Full Version : export.field - date field problem


ABC123

Mike Vance
05-21-2009, 04:10 AM
The following xbasic code works perfectly except for the paydate field which is in English 22/05/09 format in all the table records.

After the export the csv file shows it in the American version 05/22/09 which has to be loaded into Excel, cell format changed manually, then csv file re-saved.

When I try to use format_data(tbl.paydate,"7/") I get an error message and I am not sure why that is.

Can anyone help please? Mike


dim tbl as P
tbl = table.open("SagePay")
filename = ui_get_file("Destination File", "EXCEL(*.XLS)", "SagePayFile.xls","N")
if filename = "" then
end
end if
response = ui_get_radio("Export Fieldnames To File? ",1,"Yes","No")
if response = "Yes" then
export_sagepay = .T.
else
export_sagepay = .F.
end if

export.file = filename
export.type = 4
export.sagepay = export_sagepay
export.options = "T" 'strip trailing blanks
export.field_sep = ","
export.rec_sep = "<CR><LF>"
export.fields = 8

export.field1 = "acct_no"
export.field2 = "not_used1"
export.field3 = "not_used2"
export.field4 = "Notes"
export.field5 = "paydate"
'export.field5 = format_data(tbl.paydate,"7/")
export.field6 = "not_used3"
export.field7 = "debit"
export.field8 = "credit"
tbl.export()
tbl.close()

Tim Kiebert
05-21-2009, 06:00 AM
In the same way that paydate is quoted in this line



export.field5 = "paydate"
your expression should also be quoted. Like



"format_data(paydate,\"7/\")"The double quotes in the expression need to be escaped with the back slashes

Mike Vance
05-21-2009, 07:16 AM
Thanks very much Tim. I see where I went wrong. I should have known better.

Mike