| View previous topic :: View next topic |
| Author |
Message |
Rajat
Joined: 28 Mar 2004 Posts: 1718
|
Posted: Fri May 27, 2005 3:05 pm Post subject: Online Function Library |
|
|
Use this thread as an Online Function Library. Everyone is allowed to post their functions for general use. Just like Jon's attempt to catalogue all most useful scripts at one place, this is mine for the functions. The difference is that you can yourself add your own functions here. You can link to the forum post relating to your function, or directly to the script file hosted anywhere. The next post is editable by anyone. Just login using the credentials given below and add your functions there.
ahkuser:ahkuser
It'd be nice for users if u categorize your functions. _________________
 |
|
| Back to top |
|
 |
ahkuser
Joined: 27 May 2005 Posts: 9
|
Posted: Fri May 27, 2005 3:06 pm Post subject: |
|
|
Post Functions here.
ControlGetHWND
=====================
DecToHex(In_Val) here
RGBtoHex(R,G,B) here
GetRelPos(In_X,In_Y,In_Angle,In_Radius,Byref Tx, Byref Ty) here
LeapYear(In_Year) here
StringDelete(In_String,In_Start,In_Count) here
StringFlip(In_String) here
StringGetChar(In_String,In_Posi,Param3) here
StringInsert(In_String,In_Posi,In_Insert) here
StringReplaceChar(ByRef In_String,In_Posi,New_Char) here
Swap_Values(Byref val1, ByRef Val2) here
DegToRad(In_Deg) here
RadToDeg(In_Rad) here
=====================
Pixel Matrix Search here
Last edited by ahkuser on Wed Jun 22, 2005 5:53 am; edited 8 times in total |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5390 Location: /b/
|
Posted: Sat May 28, 2005 10:44 pm Post subject: |
|
|
--------------------------------------------------
Simple function, returns path of default browser so you can open links in new windows (with the system's default browser ofcourse).
| Code: | ; The next line is an example (function below)
Run, % Web() "http://www.google.com/ig"
Web()
{
RegRead, htmlOpenPath, HKCR, htmlfile\shell\open\command
Return, %htmlOpenPath%
} |
--------------------------------------------------
I posted this somewhere else but for anybody who needs it...
This makes vars you might've got from FileRead/RegRead/IniRead that have escaped variables into real variables, see the example in the script.
Download
--------------------------------------------------
Commands Function Collection - functionized all comands that have an outputvar
--------------------------------------------------
WinFX! - Some gui window effects/animations.
Download Functions
Download Example
--------------------------------------------------
Last edited by Titan on Sun Jun 19, 2005 10:52 pm; edited 5 times in total |
|
| Back to top |
|
 |
Rajat
Joined: 28 Mar 2004 Posts: 1718
|
Posted: Sun May 29, 2005 12:41 am Post subject: |
|
|
i needed that sometime ago! by the way i think u should also link your cmd functions topic in this thread. _________________
 |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5390 Location: /b/
|
Posted: Wed Jun 08, 2005 1:31 pm Post subject: |
|
|
I put up a winfx function script.
Should I bump this topic everytime I post a new function  |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10480
|
Posted: Wed Jun 08, 2005 1:59 pm Post subject: |
|
|
| It probably depends on how often you add them. If it's only once a week, a bump is probably justified. If more often, perhaps you could update the post every time but only bump once a week. |
|
| Back to top |
|
 |
Ace_NoOne
Joined: 10 Oct 2005 Posts: 333 Location: Germany
|
Posted: Fri Feb 03, 2006 11:07 pm Post subject: |
|
|
| Very nice collection - I'll try to add it to the Functions page of the AHK wiki over the weekend. |
|
| Back to top |
|
 |
Jon
Joined: 28 Apr 2004 Posts: 373
|
Posted: Sun Mar 26, 2006 2:11 pm Post subject: |
|
|
Returns the Factorial of a number-
| Code: | Factorial(number)
{
sum=%number%
loop
{
if ((number-a_index) <= 1)
break
sum:=sum*(number-a_index)
}
return sum
}
|
Converts Hexadecimal to Decimal-
(positive and negative is not taken into account as I wrote it for colour conversion.)
| Code: | HEXtoDEC(HEX)
{
StringUpper, HEX, HEX
loop, % StrLen(HEX)
{
StringMid, Col, HEX, % (StrLen(HEX)+1)-a_index, 1
if Col is integer
DEC1:=Col*16**(a_index-1)
Else
DEC1:=(Asc(Col)-55)*16**(a_index-1)
DEC+=%DEC1%
}
return DEC
} |
|
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5390 Location: /b/
|
Posted: Sun Mar 26, 2006 2:16 pm Post subject: |
|
|
| Jon wrote: | | Converts Hexadecimal to Decimal- |
| SetFormat wrote: | To convert an integer from decimal to hexadecimal, use this example (the converse can be used to convert in the opposite direction):
SetFormat, integer, hex
VariableContainingAnInteger += 0
SetFormat, integer, d |
_________________
 |
|
| Back to top |
|
 |
Jon
Joined: 28 Apr 2004 Posts: 373
|
Posted: Sun Mar 26, 2006 2:24 pm Post subject: |
|
|
I didn't notice that
I wondered why I couldn't find an existing function to do it  |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Sun Mar 26, 2006 2:34 pm Post subject: |
|
|
 | Code: | Hex2Dec(_hex)
{
local intFormat, dec
intFormat = %A_FormatInteger%
SetFormat Integer, D
dec += "0x" . _hex
SetFormat Integer, %intFormat%
Return dec
}
|
The function may be used if you are not sure if the SetFormat was set to hex before calling the function... Actually, no need for function if you never set it:
d := 0
d += "0x" . hexDigits
The topic is old, but I believe such useful list should go to the Wiki, easier to maintain than a list of messages. _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4078 Location: Pittsburgh
|
Posted: Sun Mar 26, 2006 3:28 pm Post subject: |
|
|
Strictly speaking, the Factorial function is not correct, because it returns 0 for 0!, but the right value is 1. Here it is corrected: | Code: | MsgBox % "0!="Factorial(0)", 1!="Factorial(1)", 2!="Factorial(2)", 5!="Factorial(5)
Factorial(n) {
f = 1
loop %n%
f *= A_Index
return f
} |
As PhiLho said, if your current integer format is decimal (the default), you don't need a function to convert a hex number to decimal form. Just add 0 to the hex number and AHK converts it to decimal: | Code: | hex = 0xFF
dec := hex+0 ; dec = hex converted to decimal
MsgBox % hex+0 ; can be used in output w/o assigning to vars |
|
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5390 Location: /b/
|
Posted: Sun Mar 26, 2006 3:34 pm Post subject: |
|
|
| PhiLho wrote: | | Code: | | local intFormat, dec |
| I'm curious as to why you define the local variables when there is no need to: | Functions wrote: | | All variables referenced or created inside a function are local by default (except built-in variables such as Clipboard, ErrorLevel, and A_TimeIdle). |
| PhiLho wrote: | | The function may be used if you are not sure if the SetFormat was set to hex before calling the function... | You can use A_FormatInteger and A_FormatFloat. _________________
 |
|
| Back to top |
|
 |
Jon
Joined: 28 Apr 2004 Posts: 373
|
Posted: Sun Mar 26, 2006 4:29 pm Post subject: |
|
|
| Quote: | | Code: | | dec := hex+0 ; dec = hex converted to decimal |
|
I didn't expect it to be that simple
| Quote: | | Strictly speaking, the Factorial function is not correct, because it returns 0 for 0!, but the right value is 1. Here it is corrected: |
I didn't notice that. Thanks for the amended version.
I was actually using that function for a Permutation script that I was writing yesterday (just to see if I could write one). After a couple hours of writing it, I found one you had written already that worked a hundred times faster
Thanks for your comments and corrections. |
|
| Back to top |
|
 |
|