Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Executing AHK Code inside a variable



  • Please log in to reply
2 replies to this topic
jploudre
  • Members
  • 25 posts
  • Last active: Jun 21 2014 03:20 PM
  • Joined: 24 Jan 2008
I'm storing AHK code at the end of a line of text in a listbox so I can make it do something when selected. Different lines will behave differently.

Line 1......... PickICD(111.1)
Line 2 ......... UpdateHx (Occupation)

The code is hidden with a tab in the listbox. So when I choose Line 1, the sumitted variable finds the code then I want to execute the PickICD(111.1) code. (I have that function in the script)

I've looked in the documentation and can't figure out how to do it.
--
Jonathan Ploudre
If this seem brief:
http://fivesentenc.es

gamax92
  • Members
  • 411 posts
  • Last active: Aug 06 2013 05:00 AM
  • Joined: 05 Dec 2010
You retrieve the String.
String := "FunctionA(Apples)"

Get the Name of the function with :
FunctName := SubStr(String,1,InStr(String,"(")-1)

Get the parameters for the function with :
Parameters := SubStr(String,InStr(String,"(")+1,(InStr(String,")"))-(InStr(String,"(")+1))

Then Run the Function like this
%FunctName%(Parameters)

-------------------

Reduce your Function parameters to 1 Parameter
FunctionA(Parameters)

Then insert this code to split the Parameters
StringSplit, Param, Parameters,`,

-------------------

When you want to use a Param:

If its a name of a variable, use it like this %Param1%
If its a number, use it normally

-------------------

Random, Apples, 0, 255
String := "FunctionA(Apples)"

FunctName := SubStr(String,1,InStr(String,"(")-1)
%FunctName%(SubStr(String,InStr(String,"(")+1,(InStr(String,")"))-(InStr(String,"(")+1)))
Return

FunctionA(Params)
{
	StringSplit, Param, Params,`,
	MsgBox, % %Param1% + 1
}


jploudre
  • Members
  • 25 posts
  • Last active: Jun 21 2014 03:20 PM
  • Joined: 24 Jan 2008
✓  Best Answer
I kept feeling like there was something built-in. Using Dynamic functions like that makes great sense.
--
Jonathan Ploudre
If this seem brief:
http://fivesentenc.es