AutoHotkey Community

It is currently May 26th, 2012, 1:14 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 14 posts ] 
Author Message
 Post subject: Online Function Library
PostPosted: May 27th, 2005, 4:05 pm 
Offline

Joined: March 28th, 2004, 3:53 pm
Posts: 1870
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.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 27th, 2005, 4:06 pm 
Offline

Joined: May 27th, 2005, 3:52 pm
Posts: 9
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 June 22nd, 2005, 6:53 am, edited 8 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 28th, 2005, 11:44 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
--------------------------------------------------

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 polyethene on June 19th, 2005, 11:52 pm, edited 5 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 29th, 2005, 1:41 am 
Offline

Joined: March 28th, 2004, 3:53 pm
Posts: 1870
i needed that sometime ago! by the way i think u should also link your cmd functions topic in this thread.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 8th, 2005, 2:31 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
I put up a winfx function script.

Should I bump this topic everytime I post a new function :?:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 8th, 2005, 2:59 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 4th, 2006, 12:07 am 
Offline

Joined: October 10th, 2005, 10:44 am
Posts: 299
Location: Germany
Very nice collection - I'll try to add it to the Functions page of the AHK wiki over the weekend.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 26th, 2006, 3:11 pm 
Offline

Joined: April 28th, 2004, 1:12 pm
Posts: 349
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
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 26th, 2006, 3:16 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
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

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 26th, 2006, 3:24 pm 
Offline

Joined: April 28th, 2004, 1:12 pm
Posts: 349
I didn't notice that :oops:

I wondered why I couldn't find an existing function to do it :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 26th, 2006, 3:34 pm 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
:?:
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.

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 26th, 2006, 4:28 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 26th, 2006, 4:34 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
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.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 26th, 2006, 5:29 pm 
Offline

Joined: April 28th, 2004, 1:12 pm
Posts: 349
Quote:
Code:
dec := hex+0 ; dec = hex converted to decimal


I didn't expect it to be that simple :shock:

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 :oops:


Thanks for your comments and corrections.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: IsNull, Yahoo [Bot] and 18 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group