WinBatch Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: kmccarr on May 19, 2017, 08:30:21 am

Title: Can't ClipGet from Spreadsheet and use data as an integer
Post by: kmccarr 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
Title: Re: Can't ClipGet from Spreadsheet and use data as an integer
Post by: td 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, '')  
 
Title: Re: Can't ClipGet from Spreadsheet and use data as an integer
Post by: stanl 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.
Title: Re: Can't ClipGet from Spreadsheet and use data as an integer
Post by: td on May 19, 2017, 01:29:11 pm
I don't think anyone said the OP needs to us the clipboard. 
Title: Re: Can't ClipGet from Spreadsheet and use data as an integer
Post by: stanl on May 20, 2017, 04:59:15 am
I'm sorry, I thought ClipGet was a clipboard function.
Title: Re: Can't ClipGet from Spreadsheet and use data as an integer
Post by: td on May 20, 2017, 10:30:15 am
Swoosh.