Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5232
  • Last Modified:

Cannot create dynamic column in datawindow

Hello Everyone,

I am trying to create a new column in a datawindow, but it doesn't seem to work.

There are no errors (that I see).

Here is my code:

*****
//dw_1.Modify("create column(1)")
dw_1.Modify("create column(band=detail id=1 name=1)")
//dw_original.modify('create column(name=new_column visible="1" band=detail id=' + s_id + ' x=.........')
dw_1.modify('create column(name=1 visible="1" band=detail')


dw_1.Modify("create column(2)")
dw_1.Modify("create column(3)")
dw_1.Modify("create column(4)")
dw_1.Modify("create column(5)")
dw_1.Modify("create column(6)")
*****

It runs, I pull up the datawindow, but I don't see the column.

Thanks!!!

PEM
0
pemurray
Asked:
pemurray
  • 4
  • 2
2 Solutions
 
diasroshanCommented:
Hi,

i dont think u can add columns using modify... there are various ways to achieve what u want... i mean, i need to know exactly what u want to do... what i understand is u want to create a dynamic DW...

just check this PB example from the Help...

string error_syntaxfromSQL, error_create
string new_sql, new_syntax

new_sql = 'SELECT emp_data.emp_id, ' &
        + 'emp_data.emp_name ' &
        + 'from emp_data ' &
        + 'WHERE emp_data.emp_salary>45000'

new_syntax = SQLCA.SyntaxFromSQL(new_sql, &
        'Style(Type=Grid)', error_syntaxfromSQL)

IF Len(error_syntaxfromSQL) > 0 THEN
        // Display errors
        mle_sfs.Text = error_syntaxfromSQL
ELSE
        // Generate new DataWindow
        dw_new.Create(new_syntax, error_create)
        IF Len(error_create) > 0 THEN
            mle_create.Text = error_create
        END IF
END IF

dw_new.SetTransObject(SQLCA)
dw_new.Retrieve()

//Check the above example and tell me what u want exactly... will help u achieve what u want...

Cheers,
Rosh
0
 
sandeep_patelCommented:
hi,

Are you creating datawindow dynamically or creating in column dynamically in existing datawindow ?

If datawindow is already there and all required columns are selected in it's syntax but not painted in datawindow, then what you need is Modify function. And best is first place one column in datawindow and designtime, check the datasource of that datawindow, copy the syntax of that column, remove column from datawindow and use modify function runtime to create column.

e.g.

dw_1.Modify('create column(band=detail id=1 alignment="0" tabsequence=32766 border="0" color="0" x="17595" y="36" height="76" width="512" format="[general]" html.valueishtml="0"  name=trans_no visible="0" edit.limit=0 edit.case=any edit.autoselect=yes edit.imemode=0  font.face="Arial" font.height="-12" font.weight="400"  font.family="2" font.pitch="2" font.charset="0" background.mode="2" background.color="12632256" )')

here in this syntax id is important it refers to the actual column that you have selected in your query.

Regards,
Sandeep
0
 
sandeep_patelCommented:
Hi,

also to see column in datawindow following properties are more importance

width, height, band, x, y, border, background.color, color

also check return value when you call modify funciton

ll_return  = dw_1.modify('.......')
Messagebox('',ll_return)

Regards,
Sandeep
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
pemurrayAuthor Commented:
To: Diasroshan

Unfortunately, the data does not exist in the database the way that I need it and I do not think it is possible to use SyntaxFromSQL.  I have to many functions that loop through all of the tables and do special logic.

Sandeep,

Thanks for your note.  I think this is arduous, but I understand where you are headed.  Can I put that code in a for next loop and add the columns interatively?  Or do I have to assembe one giant string and then write it out once?

I will try adding your code into a for next loop for now as I want to work with smaller chuncks of the string.

Thank you, gentlemen.

Paul
0
 
pemurrayAuthor Commented:
All,

Okay, here is what I have and what I did.

I created a datawindows with one column.

I deleted the column.

I added 48 computed columns.

Ideally, I would simply make the expression in the each of the computed columns: gridarray(getcolumn(),getrow())

Then I would be done.  But I cannot figure out how to do that so now I am trying to add columns dynamically with the values in my array.

Sandeep, I added your code and ran the program.  I put in a messagebox to see the string that dwModify returned.  The string was null.

Then I looked at the datawindow, but I did not see any NEW columns.  I am perplexed.

Here is the code:

STRING SANDEEP
SANDEEP = dw_1.Modify('create column(band=detail id=1 alignment="0" tabsequence=32766 border="0" color="0" x="17595" y="36" height="76" width="512" format="[general]" html.valueishtml="0"  name=trans_no visible="0" edit.limit=0 edit.case=any edit.autoselect=yes edit.imemode=0  font.face="Arial" font.height="-12" font.weight="400"  font.family="2" font.pitch="2" font.charset="0" background.mode="2" background.color="12632256" )')

messagebox("Sandeep Response",SANDEEP)

Again, the messagebox popped up, but did not display anything.

Also, if I AM successful in creating a dynamic column which property do use to define the NAME of the column?  I added name="NewColumn"

Thanks for all of your help.

Paul


0
 
pemurrayAuthor Commented:
ONE MORE THING...

When I create the column, I want to automatically increment the column name or id (whichever one it is that I will need to refer to it later.

So if I need to create 20 columns, I want them to be named/numbered/id'd 1 through 20 so I can REFER to it and do the following later:

***CHANGE THE NAME OF EACH COLUMN

string dwmodreturncode
for i = 1 to countyarraylength
      
      dw_mod_string = 'Object.' + "t" + string(i) + ".Text=" +"'"+ countyarray[i] + "'"
      dwmodreturncode = dw_1.modify(dw_mod_string)

next

***INSERT NEW ROWS AND CHANGE THE VALUE OF EACH ROW IN EACH COLUMN
***IN THE CODE BELOW, I JUST WANT TO WRITE OUT THE TIME (E.G., 14:15:00) IN THE FIRST COLUMN

//NOW INSERT THE ROWS INTO DW_1 - 48 rows = 12 hours

for i = 1 to 48
      newrow = dw_1.insertrow(0)
      setitemresult = dw_1.setitem(newrow,1,currenttimebucket)
      pu_time_bucket = time(currenttimebucket)
      pu_time_bucket = Relativetime(pu_time_bucket, 900)
      currenttimebucket = string(pu_time_bucket)
next
0
 
pemurrayAuthor Commented:
Gentlemen,

I am closing this out.

I came across Bhatti's suggestion to use an External Datawindow in grid format that allows you to simply make invisible the fields that you don't want.

I am hoping that I won't run into any roadblocks, but I have already tried it out a bit and it seems to be a clean way to do it.

Both of your answers could work, so I am splitting the points.

Thank you,

Paul
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now