f_stringtofile.srf 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. $PBExportHeader$f_stringtofile.srf
  2. global type f_stringtofile from function_object
  3. end type
  4. forward prototypes
  5. global function integer f_stringtofile (string arg_filepathname, string arg_stringdata, ref string arg_msg)
  6. end prototypes
  7. global function integer f_stringtofile (string arg_filepathname, string arg_stringdata, ref string arg_msg);long rslt=1,fend,fend_t
  8. string ls_dtdata, ls_dtdata_p
  9. long li_FileNum,ls_i,ls_jh
  10. string tmpfilepathname
  11. tmpfilepathname=arg_filepathname
  12. ls_dtdata=arg_stringdata
  13. fend=len(ls_dtdata)
  14. if fend<=32765 then
  15. fend_t=1
  16. else
  17. fend_t=fend/32765
  18. if mod(fend,32765)<>0 then
  19. fend_t=fend_t+1
  20. end if
  21. end if
  22. li_FileNum = FileOpen( tmpfilepathname,TextMode!, Write!, LockWrite!, Append!,EncodingUTF16LE!)
  23. if li_FileNum<=0 then
  24. arg_msg="打开文件"+tmpfilepathname+"失败"
  25. rslt=0
  26. fileclose(li_FileNum)
  27. goto ext
  28. end if
  29. for ls_i = 1 to fend_t
  30. ls_dtdata_p=mid(ls_dtdata,1+(ls_i - 1 )*32765,32765)
  31. ls_jh=FileWriteEx(li_FileNum, ls_dtdata_p)
  32. if ls_jh<=0 then
  33. arg_msg="写文件"+tmpfilepathname+"失败"
  34. rslt=0
  35. fileclose(li_FileNum)
  36. goto ext
  37. end if
  38. next
  39. fileclose(li_FileNum)
  40. ext:
  41. return rslt
  42. end function