AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Online Function Library

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Rajat



Joined: 28 Mar 2004
Posts: 1718

PostPosted: Fri May 27, 2005 3:05 pm    Post subject: Online Function Library Reply with quote

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
View user's profile Send private message
ahkuser



Joined: 27 May 2005
Posts: 9

PostPosted: Fri May 27, 2005 3:06 pm    Post subject: Reply with quote

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
View user's profile Send private message
Titan



Joined: 11 Aug 2004
Posts: 5390
Location: /b/

PostPosted: Sat May 28, 2005 10:44 pm    Post subject: Reply with quote

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

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 Smile

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

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
View user's profile Send private message Visit poster's website
Rajat



Joined: 28 Mar 2004
Posts: 1718

PostPosted: Sun May 29, 2005 12:41 am    Post subject: Reply with quote

i needed that sometime ago! by the way i think u should also link your cmd functions topic in this thread.
_________________
Back to top
View user's profile Send private message
Titan



Joined: 11 Aug 2004
Posts: 5390
Location: /b/

PostPosted: Wed Jun 08, 2005 1:31 pm    Post subject: Reply with quote

I put up a winfx function script.

Should I bump this topic everytime I post a new function Question
Back to top
View user's profile Send private message Visit poster's website
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10480

PostPosted: Wed Jun 08, 2005 1:59 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Ace_NoOne



Joined: 10 Oct 2005
Posts: 333
Location: Germany

PostPosted: Fri Feb 03, 2006 11:07 pm    Post subject: Reply with quote

Very nice collection - I'll try to add it to the Functions page of the AHK wiki over the weekend.
Back to top
View user's profile Send private message
Jon



Joined: 28 Apr 2004
Posts: 373

PostPosted: Sun Mar 26, 2006 2:11 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Titan



Joined: 11 Aug 2004
Posts: 5390
Location: /b/

PostPosted: Sun Mar 26, 2006 2:16 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Jon



Joined: 28 Apr 2004
Posts: 373

PostPosted: Sun Mar 26, 2006 2:24 pm    Post subject: Reply with quote

I didn't notice that Embarassed

I wondered why I couldn't find an existing function to do it Smile
Back to top
View user's profile Send private message Send e-mail
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Sun Mar 26, 2006 2:34 pm    Post subject: Reply with quote

Question
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
View user's profile Send private message Visit poster's website
Laszlo



Joined: 14 Feb 2005
Posts: 4078
Location: Pittsburgh

PostPosted: Sun Mar 26, 2006 3:28 pm    Post subject: Reply with 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:
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
View user's profile Send private message
Titan



Joined: 11 Aug 2004
Posts: 5390
Location: /b/

PostPosted: Sun Mar 26, 2006 3:34 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Jon



Joined: 28 Apr 2004
Posts: 373

PostPosted: Sun Mar 26, 2006 4:29 pm    Post subject: Reply with quote

Quote:
Code:
dec := hex+0 ; dec = hex converted to decimal


I didn't expect it to be that simple Shocked

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 Embarassed


Thanks for your comments and corrections.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group