Question

I have a DataWindow which I would like to be able to fill using copy/paste from an excel document. It currently imports everything I want except for a date field. Currently the user manually enters everything from an excel file including a MM/YYYY date, and when they click save, the system adds the day component so it can be passed to the oracle database as a date field.

After implementing Copy/Paste the date field comes from the excel file in MM/YYYY format (e.g 11/2013) and PowerBuilder pops up with a data validation error message (Item '11/2013' does not pass the validation test) as soon as paste has been performed.

If I continue the import all other data is pasted correctly, if I manually change the date in Excel to say 01/11/2013 everything pastes correctly including the date. The excel document comes protected from a third-party and the date format cannot be changed to include a day component.

I am using the dw.ImportClipboard() method to obtain the data from the clipboard and assign it to the correct DW columns. code snippet:

    If Clipboard() <> "" Then
            If tab_detail.tabpage_adjustment.dw_adjustment.ImportClipboard(1, li_rows, 1, 7, 3) <= 0 Then
                MessageBox("Invalid Data", "Unable to paste!", StopSign!)
                Return -1
            End If 
... process data further

Is there a way I can intercept the data between the ImportClipboard() function and the automatic validation in order to add a DD/ to the front of the date field so it passes validation? Maybe in the process data further section of the code above.

Alternatively is there a better way to do it?

Thanks.

I am using PowerBuilder Classic 12.5, Application originally developed in PB8.

EDIT: The use of a Data Store was suggested, looking into it. That appears to be what I am after. However I have been unable to get it to work for me.

here is what I have done:

datastore ids_Adjustment
ids_Adjustment = CREATE DATASTORE
ids_Adjustment.DataObject = "tab_detail.tabpage_adjustment.dw_adjustment"
ids_Adjustment.SetTransObject( SQLCA )

li_test = ids_Adjustment.ImportClipboard(1, li_rows, 1, 7, 3)
messagebox("test", "Here: "+String(li_test))

    If ids_Adjustment.ImportClipboard(1, li_rows, 1, 7, 3) <= 0 Then
        MessageBox("Invalid Data", "Unable to paste the return Adjustment! "+String(ids_Adjustment.ImportClipboard(1, li_rows, 1, 7, 3)), StopSign!)
        Return -1
    End If

Neither message box appear, but when I remove the import clipboard stuff the message boxes display normally. I am unable to determine why they are not working..

when I change the line:

ids_Adjustment.DataObject = "tab_detail.tabpage_adjustment.dw_adjustment"

to

ids_Adjustment.DataObject = "d_agentreturn_detail_adjustment"

(which is the name of the DW object)

the messageboxes return error code -4, which according to the documentation means invalid input. I am copy/pasting the same rows and data that I always have so not really sure why it is doing this.

EDIT2/Solution:

As suggested I created a new DataWindow Object (richtext) selecting an external data source and adding the columns in, this time making the required date field a string. I then created a DataStore as above referencing the new dataobject and performing an importClipboard on it. I then proceeded to add a day component to the date string:

ids_Adjustment.SetItem(li_idx, 'adjustment_period', String("01/"+ids_Adjustment.GetItemString(li_idx, 'adjustment_period')))

and then made the DataWindow Objects equal the DataStore values.

tab_detail.tabpage_adjustment.dw_adjustment.Object.adjustment_period [li_idx] = date(ids_Adjustment.GetItemString(li_idx, 'adjustment_period'))

thanks for your input and ideas.

Was it helpful?

Solution

You could paste the data into a data store with the date field as a string, fix the format of the date, and then move the rows into the data window.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top