1. Roland Smith
  2. PowerBuilder
  3. Wednesday, 18 May 2022 16:08 PM UTC

I have a string array that I want to apply to a column so that array item one goes in row one, item two goes in row two, and so on.

I could loop through them and do a SetItem but I was hoping for dot notation that would work in this code:

DWObject ldwo
ls_colname = "col" + String(ll_idx)
ldwo = lds_import.Object.__get_attribute(ls_colname, True)
ldwo.??? = ls_ColumnArray

SetItem requires determining the datatype of the column and converting the data to the correct type which slows it down.

 

Roland Smith Accepted Answer Pending Moderation
  1. Thursday, 19 May 2022 01:44 AM UTC
  2. PowerBuilder
  3. # 1

I finished coding this. I was disappointed to discover that when assigning an array to a column with dot notation, the data type has to match just like the SetItem function. The Any type only works for strings. I had to add code to copy the string array to an array of the correct type.

 

Comment
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Wednesday, 18 May 2022 16:32 PM UTC
  2. PowerBuilder
  3. # 2

Hi, Roland - 

Have you tried something along the lines of:

Long li_startrow = 1, li_endrow = 5, li_colnumber = 3
String ls_values[5] = {"Alpha","Beta","Charlie","Dog","Edward"}

dw_1.Object.Data[li_startrow,li_colnumber,li_endrow,li_colnumber] = ls_values

According to the DW Reference publication/documentation, this should work.

4.2.1.2 Getting and storing the data from a DataWindow data expression
A DataWindow data expression can return a large amount of data.
Data structures for data
Single row and column
When your data expression refers to a single row and column, you can assign the data to a
variable whose data matches the column's datatype. When the expression refers to a single
column but can refer to multiple rows, you must specify an array of the appropriate datatype.

Comment
  1. Roland Smith
  2. Wednesday, 18 May 2022 16:55 PM UTC
Thanks! ImportString allows specifying column but it has to be tab delimited, not array.
  1. Helpful
  1. Roland Smith
  2. Wednesday, 18 May 2022 17:10 PM UTC
I couldn't get that to work but the following does:



ldwo = dw_1.Object.__get_attribute(ls_colname, True)

ldwo.Primary = ls_coldata

  1. Helpful
  1. John Fauss
  2. Thursday, 19 May 2022 01:10 AM UTC
After a careful reading of the documentation, it appears that the syntax I gave you works only with arrays of structures or arrays of user objects.
  1. Helpful
There are no comments made yet.
mike S Accepted Answer Pending Moderation
  1. Wednesday, 18 May 2022 17:04 PM UTC
  2. PowerBuilder
  3. # 3

ldwo.data = ls_ColumnArray[]  should work

 

I used to use that data setting notation for some heavy processing in a report writer (copy from and to datastore/arrays)  .

But it was not compatible with an older version of powerserver so i had to change back to loops.

 

 

use the column number as in john's example ( that way you don't have to use the unsupported __get_attribute )

 

 

Comment
  1. mike S
  2. Thursday, 19 May 2022 13:29 PM UTC
If this is a copy (from excel) / Paste (to dw), you would typically want it to work like the user typing the values in so that the itemchanged event fires.

I use settext to achieve this, which is super slow....



if i import a worksheet from excel, i either use the clipboard copy method (use ole to copy the data to clipboard, then dw.ImportClipboard() to grab the data), or export the spreadsheet to tab delimited and then dw.importfile() to load the data

  1. Helpful
  1. Roland Smith
  2. Thursday, 19 May 2022 14:23 PM UTC
The existing method uses SetItem and triggers events for each one which is terribly slow.

The data is copied to the clipboard manually by the user and then in the PB app they put the cursor in a field and click the 'Paste From Excel' button. The clipboard data is then put into the DataWindow starting at the row of the cursor. The data is either string or decimal which can easily be validated without the expense of triggering itemchanged events.
  1. Helpful
  1. mike S
  2. Thursday, 19 May 2022 15:52 PM UTC
gotcha. my 'paste' functionality is generic and set on all my screens. i need to ensure it goes through itemchanged (with ability of the screen to reject it). lol, your "slow" setitem method is blazing fast compared to my settext! Any paste will work the same way (tab and CR delimited) and is not specific to excel. so the user can copy from one PB screen and paste to another, or really copy from most anything.



i wish pb had this as a native function - i do some text processing to ensure things pretty much work correctly which a native function would run faster. Although maybe i couldn't use this either. i trigger adding new rows in some cases, unless the user is pasting into a 'comment' field which may have CR as part of the text. I also support this in querymode, so that is another wrinkle.







  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.