In a dynamic crosstab how can one find out the number of columns that where created?
In a dynamic crosstab how can one find out the number of columns that where created?
Hi.
I will provide some code that does what John suggested but doesn't write to a file.
string ls_data, ls_line
integer li_pos, li_counter = 0
ls_data = dw_2.Object.DataWindow.Data
if ls_data <> "" then
ls_line = left(ls_data, pos(ls_data, '~r~n'))
else
return
end if
messagebox("Info:", ls_line)
li_pos = pos(ls_line, "~t")
if li_pos < 1 then return
do while li_pos > 0
li_counter ++
li_pos = pos(ls_line, "~t", li_pos + 1)
loop
// Attention: You have to increment count by 1 because you have tabs = columns count - 1...
messagebox("Columns:", li_counter + 1)
Same example implemented with pfc and using n_cst_string:
string ls_data, ls_parsed_data[], ls_parsed_line[]
n_cst_string lnv_str
ls_data = dw_2.Object.DataWindow.Data
if ls_data = "" then return
lnv_str.of_parsetoarray(ls_data, "~r~n", ls_parsed_data)
messagebox(string(upperbound(ls_parsed_data)), ls_data)
if upperbound(ls_parsed_data) > 0 then
lnv_str.of_parsetoarray(ls_parsed_data[1], "~t", ls_parsed_line)
end if
messagebox(string(upperbound(ls_parsed_line)), ls_parsed_data[1])
Both example may need some adjustments as I did some basic testing.
Andreas.
Just an another way to get the column count from dynamic crosstab.
Long ll_col_count
dw_1.modify('datawindow.crosstab.staticmode=yes')
ll_col_count = Long(dw_1.Describe("DataWindow.Column.Count"))
After looking at the code Andreas posted, it occurred to me that the solution can be obtained in a much simpler manner:
Any la_row
// Place the entire first row of data into a variable of type "Any".
la_row = dw_1.Object.Data[1]
// The "Any" variable now contains an array of Any's.
MessageBox("Crosstab Columns","There are "+String(UpperBound(la_row))+" columns.")
Please note that if the detail band contains any computed field DWObjects (such as a crosstabsum), those DWObject(s) will not be included in the results because they are not data columns.
John
Hi, Reynard -
The following is a little out-of-the-box, but it might work for you (the described technique works, however):
1. Save the crosstab DW contents as a (temporary) CSV file without column headings: dw_1.SaveAs("C:\temp.csv",CSV!,False)
2. Open the CSV file for reading in line mode: li_filenum = FileOpen("C:temp.csv",LineMode!,Read!)
3. Read the first line: ll_numbytes = FileReadEx(li_filenum,ls_csv_line)
4. Count the number of commas and add one (assumes the line does not contain any quoted string value(s) that contain a comma). Code left as an exercise for the reader.
5. Close and delete the temp CSV file.
Best regards, John
Hi Reynard;
AFAIK, there is no direct way to get the Column Count.
I would have expected CrossTabCount(n) to do that but it does not seem to work. :-(
Regards ... Chris