Save/Export Datawindow or Datastore To Text With Separtor In PowerBuilder
Create function gf_saveasformattedtext(adw_dw(datawindow/datastore), as_filename (string), as_separator(string))
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | /* Function: gf_saveasformattedtext(dw_1, ls_filename, ';') parameters: adw_dw(datawindow/datastore), as_filename (string), as_separator(string) */ Long ll_row, ll_rows, ll_colcount, ll_colindex String ls_colname, ls_coltype, ls_value, ls_lineval Int li_filenum Any la_anyval ll_rows = adw_dw.RowCount() ll_colcount = Long(adw_dw.Describe("DataWindow.Column.Count")) li_filenum = FileOpen(as_filename, LineMode!, Write!, LockWrite!, Append!) If li_filenum = -1 Or IsNull(li_filenum) = True Then Return -1 End If For ll_row = 1 To ll_rows ls_lineval = '' For ll_colindex = 1 To ll_colcount ls_colname = adw_dw.Describe("#" + String(ll_colindex) + ".Name") ls_coltype = adw_dw.Describe ( ls_colname + ".ColType" ) Choose Case Lower ( Left ( ls_coltype , 5 ) ) Case "char(", "char","strin" // CHARACTER DATATYPE la_anyval = adw_dw.GetItemString ( ll_row, ls_colname ) Case "date" // DATE DATATYPE la_anyval = adw_dw.GetItemDate ( ll_row, ls_colname ) Case "datet" // DATETIME DATATYPE la_anyval = adw_dw.GetItemDateTime ( ll_row, ls_colname ) Case "decim" // DECIMAL DATATYPE la_anyval = adw_dw.GetItemDecimal ( ll_row, ls_colname ) Case "numbe", "long", "ulong", "real", "int" // NUMBER DATATYPE la_anyval = adw_dw.GetItemNumber ( ll_row, ls_colname ) Case "time", "times" // TIME DATATYPE la_anyval = adw_dw.GetItemTime ( ll_row, ls_colname ) Case Else SetNull ( la_anyval ) End Choose ls_value = String(la_anyval) If Trim(ls_lineval) = '' Then ls_lineval = ls_value Else ls_lineval += as_separator + ls_value End If Next //columns FileWrite(li_filenum, ls_lineval) Next //rows Return 1 |
Good Luck!