How to get long text from the clipboard into Navision variable

Hello everyone
I have read some discussions on this forum but i didn't find solution.

I need to take long text from clipboard into variables.
I read on this forum about this OCX:
http://www.mibuso.com/dlinfo.asp?FileID=149
and I tried to use it but it work fine only when the text length in clipboard is less than 255 characters.
(I would split the clipboard text to couples text variables or use one text variable with couples dimensions - that’s not a problem)

Example:
Code below works fine where in my clipboard contain text till 254 characters.
i := STRLEN(Clipboard.TextFromClipboard);

If I copy to clipboard 255 characters (or more) the line above gives an error:
The length of the text string exceeds the size of the string buffer.
Thanks for any suggestion. Maybe I could you some different OCX /solution ?

Answers

  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    Hi,

    I've had similar problem and solved it using Excel and Excel Buffer.

    This is a simple code skeleton:
    CREATE(XlApp, FALSE);
    XlApp.Visible(FALSE);
    XlWrkBk := XlApp.Workbooks.Add;
    XlWrkSht := XlWrkBk.Worksheets.Add;
    XlWrkSht.Paste; //this inserts your clipboard into A1 cell
    MyText := COPYSTR(FORMAT(XlWrkSht.Range('A1').Value), 1, 1024);
    XlWrkBk.Close;
    CLEAR(XlApp);
    

    There are certain problems with this approach, if your text in clipboard includes tabs pasted text will be spread among columns, if your text in clipboard includes new lines pasted text will be spread across some rows.

    But at least it is a starting point.

    NB: XL* variables are copied from Excle Buffer table.

    Slawek
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • intronintron Member Posts: 3
    Thank you for your answer Sławek.

    That’s quite clever solution of this topic but as you mention, there are some disadvantages of such approach.
    As I think, to use this solution, client has to have Excel installed on local computer. In my case, Excel can’t be installed (for some reasons).
    I will think more how to “adjust” your idea. Thanks once again.

    BTW.
    It could be added one more line:
    XlApp.DisplayAlerts(FALSE);
    before closing workbook. That will hide Excel question window if you want to save workbook.

    Any other ideas ? :)

    Piotr
  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    It's not exact code I'm using, it was just a skeleton, to show what's possible.

    I'd rather try to stay away from 3rd party OCX or dlls as they also needs to be installed on client's PC, and that's often harder to get installed than the Excel.

    Another idea? What about writting your own small DLL reading from and/or writting to clipboard? There are a few templates around of dlls which can be seen by Classic Client.

    Slawek
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • intronintron Member Posts: 3
    I did not figure better solution out. I will go forward with your Excel solution.
    Thank you Sławek.
  • Remco_ReinkingRemco_Reinking Member Posts: 74
    Why not use a dotnet variable for this:
    Clipboard msdn
  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    Why not use a dotnet variable for this:
    Clipboard msdn
    Because the question it posted in NAV/Navision Classic Client forum?
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • Remco_ReinkingRemco_Reinking Member Posts: 74
    Why not use a dotnet variable for this:
    Clipboard msdn
    Because the question it posted in NAV/Navision Classic Client forum?

    Yeah, makes sense :#
Sign In or Register to comment.