String to number Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
jekko1976
Posts: 97
Joined: 10 Oct 2014, 07:03

String to number

16 Apr 2018, 08:29

Howdy,

I have to retrieve a number from a string.
I have to retrieve another number from another string.
In my country the decimal sign is , and not .
I have to subtract second number by first number
my code does not work
here is my code

Code: Select all

SetFormat, float, 0.2
ControlGetText, testo, Edit2, Gestione Foglio
pos:= InStr(testo, "INTERESSI EURO")
intMutuo:=SubStr(testo,pos+15)
ControlGetText, addeb, Edit1, Scomponi riga
addebito:=ToNum(addeb)
interessi:=ToNum(intMutuo)
addNetto:= addebito - interessi
MsgBox, %addNetto% <--------------This shows me a blank space instead of the result expected
return

ToNum(stringa)
	{
		StringReplace, ToNum, stringa,%A_Space%,,All
		StringReplace, ToNum, ToNum,  ., , All
		StringReplace, ToNum, ToNum, `,,., All
		MsgBox, % ToNum   <---------------this shows me correctly the number in format 1234.56
	}
MaxAstro
Posts: 557
Joined: 05 Oct 2016, 13:00

Re: String to number

16 Apr 2018, 08:36

If you put MsgBox, %addebito% and MsgBox, %interessi% in your code, what do those messageboxes display?
gregster
Posts: 9111
Joined: 30 Sep 2013, 06:48

Re: String to number  Topic is solved

16 Apr 2018, 08:43

Your function ToNum() doesn't return anything - add return ToNum at the end of it.
jekko1976
Posts: 97
Joined: 10 Oct 2014, 07:03

Re: String to number

16 Apr 2018, 09:05

gregster was right!
I added the return and now all works like a charm!
Thank you very much!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Kodakku and 370 guests