# Arithmetic operations on data copied to the clipboard from a spreadsheet.

## Recommended Posts

I often work on the data copied to the clipboard from a spreadsheet.

I often work on the data copied to the clipboard from a spreadsheet.

For the purpose of performing arithmetic operations made a simple set of functions.

It may be useful to someone.

```_Number_Example()

Func _Number_Example()
MsgBox(0, '_Number_Example() 1', _NumberFromString('12 394,41'))
MsgBox(0, '_Number_Example() 2', _NumberToString(_NumberFromString('11.494')))
EndFunc   ;==>_Number_Example

Func _NumberFromString(\$sNumberAsString)
Local \$sTrailing = _RegExpFirstMatch(\$sNumberAsString, '.+?[.,](\d\d|\d)\z')
Local \$vValueToReturn = 0
If \$sTrailing <> '' Then
If StringLen(\$sTrailing) = 1 Then \$sTrailing &= '0'
Local \$sLeading = StringRegExpReplace(\$sNumberAsString, '(.+?)(\D\d\d|\D\d)\z', '\$1')
\$vValueToReturn = \$sLeading & '.' & \$sTrailing
Else
\$vValueToReturn = StringRegExpReplace(\$sNumberAsString, '(\D)', '') & '.00'
EndIf
Return \$vValueToReturn
EndFunc   ;==>_NumberFromString

Func _NumberToString(\$vNumber)
Return StringReplace(String(\$vNumber), '.', ',')
EndFunc   ;==>_NumberToString

Return Number(\$v1 + \$v2)

Return _NumberToString(_NumberFromString(\$sValue1) + _NumberFromString(\$sValue2))

Func _RegExpFirstMatch(\$sData, \$sPattern)
Local \$aResult = StringRegExp(\$sData, \$sPattern, 3)
Local \$iError = @error
Local \$iExtended = @extended
If \$iError Then
Return SetError(\$iError, \$iExtended, '')
Else
Return \$aResult[0]
EndIf
EndFunc   ;==>_RegExpFirstMatch```
Best regards,

mLipok

Edited by mLipok

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
*
How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
, be   and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2019-10-01

##### Share on other sites

I often work on the data copied to the clipboard from a spreadsheet.

I often work on the data copied to the clipboard from a spreadsheet.
For the purpose of performing arithmetic operations made a simple set of functions.
It may be useful to someone.
`_RegExpFirstMatch`

Best regards,

mLipok

Missing.

Monkey's are, like, natures humans.

##### Share on other sites

Fixed

Look in OP again.

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
*
How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
, be   and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2019-10-01

## Create an account

Register a new account

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...