Page 1 of 1

AHK commands for Excel =MID() & =VALUE()

Posted: 20 Mar 2017, 22:01
by WeThotUWasAToad
Hello,

What AHK commands mimic the following two Excel functions?

=MID()
Syntax: MID(text, start_num, num_chars)

=VALUE()
Syntax: VALUE(text)

For example, the following formula extracts a string of 3 characters beginning with character #2:
=MID("W369A4KM",2,3) = "369"

And this formula converts a text string (of numbers) to a numeric value:
=VALUE("369") = 369

So combined,
=VALUE(MID("W369A4KM",2,3)) = 369

Can someone post the equivalent AHK formulas, both individually and combined?

Thanks

Re: AHK commands for Excel =MID() & =VALUE()  Topic is solved

Posted: 21 Mar 2017, 12:28
by FanaticGuru

Code: Select all

X := SubStr("W369A4KM", 2, 3)
MsgBox % X
X := X / 3 + 5
MsgBox % X
There is not really much use for a command like "Value" in AHK. AHK does not have variable types and pretty much treats a variable like a string or a number as needed.

FG

Re: AHK commands for Excel =MID() & =VALUE()

Posted: 22 Mar 2017, 22:34
by WeThotUWasAToad
FanaticGuru wrote:There is not really much use for a command like "Value" in AHK. AHK does not have variable types and pretty much treats a variable like a string or a number as needed.
Thanks FG. That's really helpful (including the comment re variables). I need to find/create a chart showing equivalent functions because I am far more comfortable with Excel formulas than with AHK.

Re: AHK commands for Excel =MID() & =VALUE()

Posted: 23 Mar 2017, 01:01
by FanaticGuru
WeThotUWasAToad wrote:Thanks FG. That's really helpful (including the comment re variables). I need to find/create a chart showing equivalent functions because I am far more comfortable with Excel formulas than with AHK.
It is best to use AHK functions when possible but if you really need to use an Excel function in AHK you can, assuming Excel is installed on the computer.
https://autohotkey.com/boards/viewtopic ... 83#p133783

It allows stuff like this.

Code: Select all

Xl := ComObjCreate("Excel.Application") ; This only needs to be done once in the script (basically starts a hidden Excel running)
Payment := Xl.WorksheetFunction.Pmt(5 / 1200, 6 * 12,  -10000) ; Monthly Payment for $10,000 loan at 5% for 6 years.
MsgBox % Payment
Xl.Quit() ; Close your hidden Excel before ending your script, could make this an OnExit routine
Which is useful for accessing the vast number of specialized functions available in Excel.

FG