cancel
Showing results for 
Search instead for 
Did you mean: 

get data from clipboard onto a user form

Former Member
0 Kudos

Hi all,

i would like to get barcode data (ean-code/serial no.) from the clipboard onto a user form.

this is the coding in vb.net i used to create the form:


Private Sub DisplayScannerForm()
Dim scannerForm As SAPbouiCOM.Form
Dim tmpItem As SAPbouiCOM.Item
scannerForm = SBO_Application.Forms.Add("ScannerForm", SAPbouiCOM.BoFormTypes.ft_Fixed)
scannerForm.Height = 150
scannerForm.Top = SBO_Application.Desktop.Height / 2 - scannerForm.Height
scannerForm.Width = 250
scannerForm.Left = SBO_Application.Desktop.Width / 4 - scannerForm.Width / 2
scannerForm.Visible = True
scannerForm.Title = "Scanner Form"
tmpItem = scannerForm.Items.Add("results", SAPbouiCOM.BoFormItemTypes.it_EDIT)
tmpItem.Height = 120
tmpItem.Top = 1
tmpItem.Width = 220
tmpItem.Left = scannerForm.Width / 2 - tmpItem.Width / 2
tmpItem.Visible = True
...

to get the data from the clipboard onto the form i tried this unsuccessfully(in Private Sub DisplayScannerForm()):


...
Dim idata As IDataObject
idata = Clipboard.GetDataObject()
If idata.GetDataPresent(DataFormats.Text) Then
tmpItem.Value = CStr(idata.GetData(DataFormats.Text))
else...
end if
end sub

when debugging this line by line, after compiling the code and loading the scanner form, it keeps showing that

iData = Nothing. Can anyone tell me why ?

the code for the item event on which the scanner form is loaded looks like this:


Public Sub SBO_Application_ItemEvent(ByVal FormUID As String, ByRef pVal As SAPbouiCOM.ItemEvent, ByRef BubbleEvent As Boolean) Handles SBO_Application.ItemEvent
If pVal.FormType = 25 And pVal.EventType =       SAPbouiCOM.BoEventTypes.et_FORM_LOAD Then
DisplayScannerForm()
End If

Can anyone help me with this ? coding samples would be very helpful.

Thanks very much in advance.

Message was edited by: Daniel Lobotzki

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Daniel,

I have executed your code and it works for me. Are you sure you've got something in the clipboard? My code is as follows:

        Dim idata As IDataObject
        Dim s As String
        idata = Clipboard.GetDataObject()
        If idata.GetDataPresent(DataFormats.Text) Then
            s = CStr(idata.GetData(DataFormats.Text))
            MessageBox.Show(s)
        Else
            MessageBox.Show("Nothing")
        End If

What happens if you paste whatever is in the clipboard in another application, say notepad?

Hope it helps,

Adele

Former Member
0 Kudos

Hi Adele,

displaying the clipboard data in a windows message box works fine for me too. the problem is displaying the clipboard data on the scanner form in SAP BO.

i created tmpItem on the scanner form as you can see in the code snippet above, but cannot assign the clipboard data to it like this:


tmpItem.value = CStr(idata.GetData(DataFormats.Text))

Any suggestion on how to do this differently.

Thanks

Daniel

former_member201110
Active Contributor
0 Kudos

Hi Daniel,

Have you bound a user datasource to the textbox before you attempt to assign the value from the clipboard? I can get a version of your code to run by adding the following code:

...

Dim tmpEdit As SAPbouiCOM.EditText

...

'Create user datasource to hold textbox value

scannerForm.DataSources.UserDataSources.Add("ClipBoard", SAPbouiCOM.BoDataType.dt_SHORT_TEXT, 50) 'note: assign correct datatype and length, as required

...

...

'Bind user datasource to textbox

tmpEdit = tmpItem.Specific

tmpEdit.DataBind.SetBound(True, "", "ClipBoard")

The code to assign the value to the textbox should now be:

idata = Clipboard.GetDataObject()

If idata.GetDataPresent(DataFormats.Text) Then

tmpEdit.Value = CStr(idata.GetData(DataFormats.Text))

End If

You'll need to validate the data you are putting in (against the datatype and length of the user datasource) or use try/catch to trap 'Bad Value' errors.

This code works for me.

Hope this helps,

Owen

Former Member
0 Kudos

Hi Owen,

thanks for your suggestion. I added your code to my program but am still not able to display the clipboard data on the scanner form. The clipboard data consists of 13-digit EAN-Code(-numbers) or as the case may be of a 7-digit serial-no.

Could you elaborate on the two comments you made referring to assigning the correct datatype and length as required and respectively the need to "validate the data you are putting in (against the datatype and length of the user datasource) or use try/catch to trap 'Bad Value' errors".

How can i implement this in vb.net ?

with kind regards,

Daniel

Former Member
0 Kudos

Hi Daniel,

if the standard clipboard object in VB.net is the same as the clipboard object for C#, then you won't be able to use it on a standard SAP form, as the standard clipboard object won't work in a multi-threaded program, which is what a standard SAP add-on is. I had to use the Windows API clipboard methods to succesfully obtain the clipboard data, look on the Microsoft website to get the method calls.

Regards, Lita