[Solved] [Calc] Text to number

Creating a macro - Writing a Script - Using the API

[Solved] [Calc] Text to number

Postby grahamn » Thu Jun 11, 2020 6:27 am

I have the following code in a calc macro

Cell = Sheet.getCellByPosition(16,RowNo)
Cost = Cell.String
NewCost = Cost - 6
Cell = Sheet.getCellByPosition(16,RowNo)
Cell.String = NewCost

The result is a number expressed as a string, as expected, but I need a number to be able to carry out further calculations.
I have tried converting to a number using Cell.string = VAL(NewCost) and Cell.String = CSng(NewCost) but the result is still a string
Apparently I am doing something wrong but cannot find an answer after several searches.

Using Windows 10
Last edited by Hagar Delest on Thu Jun 11, 2020 8:27 am, edited 1 time in total.
Reason: tagged solved
OpenOffice 4.1.0 on windows 7
grahamn
 
Posts: 7
Joined: Sat Aug 16, 2014 4:15 am

Re: text to number

Postby FJCC » Thu Jun 11, 2020 6:42 am

If you want the cell value, use
Code: Select all   Expand viewCollapse view
Cost = Cell.Value

Also, there is no needto do
Cell = Sheet.getCellByPosition(16,RowNo)
twice
Windows 10 and Linux Mint, since 2017
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
FJCC
Moderator
 
Posts: 7680
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: text to number

Postby grahamn » Thu Jun 11, 2020 7:36 am

Thanks FJCC
I'll keep this in mind for the future
OpenOffice 4.1.0 on windows 7
grahamn
 
Posts: 7
Joined: Sat Aug 16, 2014 4:15 am


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 4 guests