viewpoint-particle

Author Topic: Can't ClipGet from Spreadsheet and use data as an integer  (Read 81 times)

kmccarr

  • Newbie
  • *
  • Posts: 1
Can't ClipGet from Spreadsheet and use data as an integer
« on: May 19, 2017, 08:30:21 am »
I'm probably doing something wrong that's really basic, but I am struggling and need help.

I'm copying numbers from a couple of Excel cells using the Sendkey ^c command. then, I'm using ClipPut to store the numbers into variables. I then want to add those together using the command AmtTotal=Amt1+Amt2

When I try this, Winbatch stops with the error "variable could not be converted to a valid number"

When I look in Winbatch Studio, I can see the numbers have @CRLF on the end of them, so the number 7.32 shows as 7.23@CRLF and the variable now shows as a String_Unicode

There are no line feeds in my spreadsheet. These are simple cells, formatted as numbers (I've also tried text, general, etc) with simple numbers in them.

What am I doing wrong?

Thanks

Keith

td

  • Tech Support
  • *****
  • Posts: 2024
    • WinBatch
Re: Can't ClipGet from Spreadsheet and use data as an integer
« Reply #1 on: May 19, 2017, 09:12:52 am »
Without getting into a discussion of the wisdom of using key strokes to do something when better alternative may exist,  the carriage-return and line-feed are placed in the clipboard by either Excel or the Windows clipboard service.  You simply need to remove them:

Code: Winbatch
nVar = StrReplace(nVar, @CRLF, '')  
 
"DON'T PANIC”
The Hitchhiker's Guide to the Galaxy, Douglas Adams


stanl

  • Pundit
  • *****
  • Posts: 602
Re: Can't ClipGet from Spreadsheet and use data as an integer
« Reply #2 on: May 19, 2017, 10:33:22 am »
Why do you even need the clipboard. If your script has Excel opened, a simple amt = Application.Worksheetfunction.Sum(cell1,cell2,celln...) where Application is your Excel Object.

td

  • Tech Support
  • *****
  • Posts: 2024
    • WinBatch
Re: Can't ClipGet from Spreadsheet and use data as an integer
« Reply #3 on: May 19, 2017, 01:29:11 pm »
I don't think anyone said the OP needs to us the clipboard. 
"DON'T PANIC”
The Hitchhiker's Guide to the Galaxy, Douglas Adams


stanl

  • Pundit
  • *****
  • Posts: 602
Re: Can't ClipGet from Spreadsheet and use data as an integer
« Reply #4 on: May 20, 2017, 04:59:15 am »
I'm sorry, I thought ClipGet was a clipboard function.

td

  • Tech Support
  • *****
  • Posts: 2024
    • WinBatch
Re: Can't ClipGet from Spreadsheet and use data as an integer
« Reply #5 on: May 20, 2017, 10:30:15 am »
Swoosh.
"DON'T PANIC”
The Hitchhiker's Guide to the Galaxy, Douglas Adams