Subscribe for automatic updates: RSS icon RSS

Login icon Sign in for full access | Help icon Help
Advanced search

Pages: [1]
  Reply  |  Print  
Author Topic: Paste clipboard data into screen array  (Read 12095 times)
Mark W.
Posts: 17


« on: June 27, 2018, 11:23:42 am »

I want to know if there is some way of copying data from a spreadsheet and pasting it en bloc into a genero screen array. When I try it it only pastes a single cell. Backend program is a simple INPUT ARRAY without any BEFORE FIELD, AFTER FIELD, BEFORE ROW, AFTER ROW, &c.
Reuben B.
Four Js
Posts: 1046


« Reply #1 on: June 27, 2018, 12:47:56 pm »

You'll need to state what client, what version etc you are using.

I am pretty sure that 10+ years ago before I joined 4Js, what you described work, as we looked to use this as a means for Accountants to determine their budgets etc in Excel, and then copy and paste their account codes and values into an INPUT ARRAY,  or similarly for data migration purposes.  The key being that the INPUT ARRAY has to be vanilla with no code to do NEXT FIELDs etc.  Any validation can only be in the AFTER INPUT.

A quick test using GDC on my Mac suggests that it pastes into the next field correctly ie handles the ASCII(9), but doesn't do the next row ASCII(13)correctly.  I'll have to have a longer play on some old versions and see if my memory is correct.  Using GBC it looks like ASCII(9) is pasted as a literal tab

You should also note that with GDC you could use the cbget front-call to read the clipboard buffer and base.StringTokenizer using ASCII(13) and ASCII(9) e.g.

Code
  1. DEFINE s STRING
  2. DEFINE tok1, tok2 base.StringTokenizer
  3. DEFINE line STRING
  4.  
  5.    CALL ui.Interface.frontCall("standard","cbget",[], s)
  6.    LET tok1 = base.StringTokenizer.createEXt(s,ASCII(13), NULL, TRUE)
  7.    WHILE tok1.hasMoreTokens()
  8.        DISPLAY "New Row ..."
  9.        LET line = tok1.nextToken()
  10.        LET tok2 = base.StringTokenizer.createExt(line,ASCII(9), NULL, TRUE)
  11.        WHILE tok2.hasMoreTokens()
  12.            DISPLAY tok2.nextToken()
  13.        END WHILE
  14.    END WHILE

so you could get something that will work if you were prepared to add an ON ACTION pastespecial, and explicitly parse the clipboard into the array variable



Reuben

Product Consultant (Asia Pacific)
Developer Relations Manager (Worldwide)
Author of https://4js.com/ask-reuben
Contributor to https://github.com/FourjsGenero
Mark W.
Posts: 17


« Reply #2 on: June 27, 2018, 01:35:53 pm »

You'll need to state what client, what version etc you are using.
Hi Reuben, thanks for the reply. Unfortunately we're using the HTML client & Genero version 2.50. It seems the cbget option doesn't work with the HTML client?
Reuben B.
Four Js
Posts: 1046


« Reply #3 on: June 27, 2018, 11:57:13 pm »

You'll need to state what client, what version etc you are using.
Hi Reuben, thanks for the reply. Unfortunately we're using the HTML client & Genero version 2.50. It seems the cbget option doesn't work with the HTML client?
Correct, as documented http://4js.com/online_documentation/fjs-fgl-manual-html/#fgl-topics/c_fgl_frontcalls_standard.html.  Historically Web Browsers don't allow javascript to access the clipboard.

Product Consultant (Asia Pacific)
Developer Relations Manager (Worldwide)
Author of https://4js.com/ask-reuben
Contributor to https://github.com/FourjsGenero
Mark W.
Posts: 17


« Reply #4 on: July 02, 2018, 09:26:03 am »

Problem solved by doing the following:--

1. Paste data from spreadsheet into a text box.
2. Store data from text box in a string variable.
3. Use string tokenizers to separate cells and lines (ASCII (9) between cells; new line ASCII (10)).
4. Store data in program array.
Reuben B.
Four Js
Posts: 1046


« Reply #5 on: November 19, 2019, 04:17:50 am »

You'll need to state what client, what version etc you are using.

I am pretty sure that 10+ years ago before I joined 4Js, what you described work, as we looked to use this as a means for Accountants to determine their budgets etc in Excel, and then copy and paste their account codes and values into an INPUT ARRAY,  or similarly for data migration purposes.  The key being that the INPUT ARRAY has to be vanilla with no code to do NEXT FIELDs etc.  Any validation can only be in the AFTER INPUT.

A quick test using GDC on my Mac suggests that it pastes into the next field correctly ie handles the ASCII(9), but doesn't do the next row ASCII(13)correctly.  I'll have to have a longer play on some old versions and see if my memory is correct.  Using GBC it looks like ASCII(9) is pasted as a literal tab

You should also note that with GDC you could use the cbget front-call to read the clipboard buffer and base.StringTokenizer using ASCII(13) and ASCII(9) e.g.

Code
  1. DEFINE s STRING
  2. DEFINE tok1, tok2 base.StringTokenizer
  3. DEFINE line STRING
  4.  
  5.    CALL ui.Interface.frontCall("standard","cbget",[], s)
  6.    LET tok1 = base.StringTokenizer.createEXt(s,ASCII(13), NULL, TRUE)
  7.    WHILE tok1.hasMoreTokens()
  8.        DISPLAY "New Row ..."
  9.        LET line = tok1.nextToken()
  10.        LET tok2 = base.StringTokenizer.createExt(line,ASCII(9), NULL, TRUE)
  11.        WHILE tok2.hasMoreTokens()
  12.            DISPLAY tok2.nextToken()
  13.        END WHILE
  14.    END WHILE

so you could get something that will work if you were prepared to add an ON ACTION pastespecial, and explicitly parse the clipboard into the array variable



Reuben

Re-reading this, reason the above example didn't work as intended was I was using ASCII(13) and not ASCII(10).  Replace ASCII(13) with ASCII(10) in the example

Readers should also note that technique using StringTokenizer does not handle case where the delimiter is inside a quoted string and you want to ignore it the delimiter in that case.

« Last Edit: November 19, 2019, 04:19:48 am »

Product Consultant (Asia Pacific)
Developer Relations Manager (Worldwide)
Author of https://4js.com/ask-reuben
Contributor to https://github.com/FourjsGenero
Reuben B.
Four Js
Posts: 1046


« Reply #6 on: November 25, 2019, 10:12:35 pm »

You'll need to state what client, what version etc you are using.

I am pretty sure that 10+ years ago before I joined 4Js, what you described work, as we looked to use this as a means for Accountants to determine their budgets etc in Excel, and then copy and paste their account codes and values into an INPUT ARRAY,  or similarly for data migration purposes.  The key being that the INPUT ARRAY has to be vanilla with no code to do NEXT FIELDs etc.  Any validation can only be in the AFTER INPUT.

A quick test using GDC on my Mac suggests that it pastes into the next field correctly ie handles the ASCII(9), but doesn't do the next row ASCII(13)correctly.  I'll have to have a longer play on some old versions and see if my memory is correct.  Using GBC it looks like ASCII(9) is pasted as a literal tab

You should also note that with GDC you could use the cbget front-call to read the clipboard buffer and base.StringTokenizer using ASCII(13) and ASCII(9) e.g.

Code
  1. DEFINE s STRING
  2. DEFINE tok1, tok2 base.StringTokenizer
  3. DEFINE line STRING
  4.  
  5.    CALL ui.Interface.frontCall("standard","cbget",[], s)
  6.    LET tok1 = base.StringTokenizer.createEXt(s,ASCII(13), NULL, TRUE)
  7.    WHILE tok1.hasMoreTokens()
  8.        DISPLAY "New Row ..."
  9.        LET line = tok1.nextToken()
  10.        LET tok2 = base.StringTokenizer.createExt(line,ASCII(9), NULL, TRUE)
  11.        WHILE tok2.hasMoreTokens()
  12.            DISPLAY tok2.nextToken()
  13.        END WHILE
  14.    END WHILE

so you could get something that will work if you were prepared to add an ON ACTION pastespecial, and explicitly parse the clipboard into the array variable



Reuben

Re-reading this, reason the above example didn't work as intended was I was using ASCII(13) and not ASCII(10).  Replace ASCII(13) with ASCII(10) in the example

Readers should also note that technique using StringTokenizer does not handle case where the delimiter is inside a quoted string and you want to ignore it the delimiter in that case.



Disregard my last comment, my original example was OK.  The buffer content uses  ASCII(13), ASCII(10) as the row delimiter.  Either ASCII(13) or ASCII(10) would effectively delimit the Excel row, although both equally suffer if the character used as delimiter is inside a quoted string in the Excel cell (we can't instruct the tokenizer to ignore this).  As this is more likely to be an ASCII(10), then using ASCII(13) as per my original comment is probably the better option. 

Product Consultant (Asia Pacific)
Developer Relations Manager (Worldwide)
Author of https://4js.com/ask-reuben
Contributor to https://github.com/FourjsGenero
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.21 | SMF © 2015, Simple Machines