AutoHotkey Community

It is currently May 26th, 2012, 8:24 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 42 posts ]  Go to page Previous  1, 2, 3
Author Message
 Post subject:
PostPosted: January 1st, 2008, 6:45 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
Thanks it's been fixed.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 1st, 2008, 9:19 pm 
bmcclure wrote:
Can't the first parameter be removed since it doesn't matter what was in the variable before and it's returned by the function?
Titan wrote:
Thanks it's been fixed.

...I'm surprised Titan...no complaints, just "ok!"...if you are going for 100% compatibility (same syntax for command & function), I think it should be...

Code:
;//Command Syntax: IniRead, OutputVar, Filename, Section, Key[, Default]
IniRead(ByRef OutputVar, Filename, Section, Key, Default = "") {
   IniRead, OutputVar, %Filename%, %Section%, %Key%, %Default%
   return, OutputVar
}

...I would expect you to think that command & function syntax should match...

Actually that might complain too much about the ByRef, so maybe this would be better...

Code:
;//Command Syntax: IniRead, OutputVar, Filename, Section, Key[, Default]
IniRead(p_OutputVar, Filename, Section, Key, Default = "") {
   IniRead, OutputVar, %Filename%, %Section%, %Key%, %Default%
   %p_OutputVar%:=OutputVar
   return, OutputVar
}

...then you could call it with an OutputVar name or just "" for blank...I don't think ByRef's can be the emtpy string, so that workaround would allow it...testing code...

Code:
ret:=IniRead(OutputVar, Filename, Section, Key, Default)
ret:=IniRead("", Filename, Section, Key, Default)
ret:=IniRead("OutputVar", "123.ini", "Section", "Key", "Default")
ret:=IniRead("", "123.ini", "Section", "Key", "Default")
IniRead(OutputVar, "123.ini", "Section", "Key", "Default")

...ret & OutputVar should match if both are specified, otherwise return value is in ret only or OutputVar only...


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 1st, 2008, 9:35 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
JSLover wrote:
I would expect you to think that command & function syntax should match
No I don't. My intentions with this library since the beginning was to make a function of every command that had an OutputVar which would return its value rather than saving it to a variable. This provides greater flexibility with use in expressions, and makes your code that little bit shorter. Multiple output commands are obviously an exception and I only implemented them on a whim since they break consistency.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 1st, 2008, 9:51 pm 
Offline

Joined: November 24th, 2007, 9:07 pm
Posts: 774
I agree with Titan also. The great part about these functions is that you can chain them together in many cases, since they return the result directly.

If you used a ByRef, or asked for the OutputVar as a parameter, you would have to keep it to one IniRead (or whatever command) per line.

It would just be redundant to keep the 'v' parameter in there, since it's not and doesn't need to be a ByRef, and the function doesn't care what the value of the output var is since it gets overwritten anyway.

And I do completely agree with the ByRefs on the string commands since it avoids re-reading the whole string as it's passed to each function, especially helpful for really long strings.

I'm happy with the changes :)

_________________
Ben

My Trac projects
My Wiki
[Broken] - My music


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 26th, 2008, 8:32 am 
Offline

Joined: April 18th, 2008, 7:57 am
Posts: 1390
Location: The Interwebs
Having a problem with Run()...

The Error Message wrote:
Error in #include file "C:\[censored]\Lib\CommandFunctions.ahk": This dynamic variable is blank. If this variable was not intended to be dynamic, remove the % symbols from it.

Specifically: %v%

Line#
161: Return,v
162: }
163: {
164: RegRead,v,%RootKey%,%SubKey%,%ValueName%
165: Return,v
166: }
167: {
---> 168: Run,%Target%,%WorkingDir%,%Mode%,%v%
169: Return,v
170: }
171: {
172: SoundGet,v,%ComponentType%,%ControlType%,%DeviceNumber%
173: Return,v
174: }
175: {

---------------------------
OK
---------------------------


...Errr. Don't really know what to do with this? x_x

Edit: Nvm, found the problem... thought it was referring to %target%, just noticed it was actually %v%, removed the %'s and it worked fine. So, if anyone else has this problem.. just remove the %'s... yea..


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 23rd, 2008, 8:46 pm 
Offline

Joined: March 11th, 2008, 11:36 pm
Posts: 291
i thought it was in the library already

Code:
If ProcExist("Notepad.exe")
    WinClose,% "ahk_pid " Errorlevel

Code:
ProcExist(PID_or_Name=""){
    Process, Exist, % (PID_or_Name="") ? DllCall("GetCurrentProcessID") : PID_or_Name
    Return Errorlevel
}

_________________
Easy WinAPI - Dive into Windows API World
Benchmark your AutoHotkey skills at PlayAHK.com


Report this post
Top
 Profile  
Reply with quote  
PostPosted: September 10th, 2009, 8:45 am 
There is a problem with GetKeyState() function. It returns "U" or "D" as GetKeyState command does. But there is a built-in function with the same name which returns true or false. It is confusing and the following code may not work properly depending on Functions.ahk being or not being installed:

Code:
if GetKeyState("Shift")
{
   ;some code


I suggest removing GetKeyState() from the library.


Report this post
Top
  
Reply with quote  
 Post subject: a patch
PostPosted: October 29th, 2009, 1:47 pm 
Offline

Joined: September 23rd, 2009, 6:33 pm
Posts: 19
Titan, thank you for the useful library. I found few bugs and fixed them and added few missing functions.

Andrej

Code:
Index: Functions.ahk
===================================================================
--- Functions.ahk   (revision 56)
+++ Functions.ahk   (working copy)
@@ -67,6 +67,16 @@
    EnvGet, v, %EnvVarName%
    Return, v
 }
+EnvAdd(Var, Value, TimeUnits) {
+   v:= Var
+   EnvAdd, v, %Value%, %TimeUnits%
+   Return, v
+}   
+EnvSub(Var, Value, TimeUnits) {
+   v:= Var
+   EnvSub, v, %Value%, %TimeUnits%
+   Return, v
+}   
 FileGetAttrib(Filename = "") {
    FileGetAttrib, v, %Filename%
    Return, v
@@ -148,7 +158,7 @@
    Return, v
 }
 Run(Target, WorkingDir = "", Mode = "") {
-   Run, %Target%, %WorkingDir%, %Mode%, %v%
+   Run, %Target%, %WorkingDir%, %Mode%, v
    Return, v   
 }
 SoundGet(ComponentType = "", ControlType = "", DeviceNumber = "") {
@@ -167,43 +177,44 @@
    SplitPath, InputVar, OutFileName, OutDir, OutExtension, OutNameNoExt, OutDrive
 }
 StringGetPos(ByRef InputVar, SearchText, Mode = "", Offset = "") {
-   StringGetPos, v, %InputVar%, %SearchText%, %Mode%, %Offset%
+   StringGetPos, v, InputVar, %SearchText%, %Mode%, %Offset%
    Return, v
 }
 StringLeft(ByRef InputVar, Count) {
-   StringLeft, v, %InputVar%, %Count%
+   StringLeft, v, InputVar, %Count%
    Return, v
 }
 StringLen(ByRef InputVar) {
-   StringLen, v, %InputVar%
+   StringLen, v, InputVar
    Return, v
 }
 StringLower(ByRef InputVar, T = "") {
-   StringLower, v, %InputVar%, %T%
+   StringLower, v, InputVar, %T%
    Return, v
 }
 StringMid(ByRef InputVar, StartChar, Count , L = "") {
-   StringMid, v, %InputVar%, %StartChar%, %Count%, %L%
+   StringMid, v, InputVar, %StartChar%, %Count%, %L%
    Return, v
 }
-StringReplace(ByRef InputVar, SearchText, ReplaceText = "", All = "") {
-   StringReplace, v, %InputVar%, %SearchText%, %ReplaceText%, %All%
+StringReplace(inputStr, SearchText, ReplaceText = "", All = "") {
+   InputVar:= inputStr
+   StringReplace, v, InputVar, %SearchText%, %ReplaceText%, %All%
    Return, v
 }
 StringRight(ByRef InputVar, Count) {
-   StringRight, v, %InputVar%, %Count%
+   StringRight, v, InputVar, %Count%
    Return, v
 }
 StringTrimLeft(ByRef InputVar, Count) {
-   StringTrimLeft, v, %InputVar%, %Count%
+   StringTrimLeft, v, InputVar, %Count%
    Return, v
 }
 StringTrimRight(ByRef InputVar, Count) {
-   StringTrimRight, v, %InputVar%, %Count%
+   StringTrimRight, v, InputVar, %Count%
    Return, v
 }
 StringUpper(ByRef InputVar, T = "") {
-   StringUpper, v, %InputVar%, %T%
+   StringUpper, v, InputVar, %T%
    Return, v
 }
 SysGet(Subcommand, Param3 = "") {



Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 25th, 2010, 12:53 pm 
Offline

Joined: November 7th, 2006, 9:47 pm
Posts: 1933
Location: Germany
Is it somehow me orwhy do that not work?
Code:
; #Include Functions.ahk
#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%

; Call this once, if the library is not explicitly included.
Functions()
MsgBox % StringReplace(var := "hello world!", "!", "?", True)


The source for this function is
Code:
StringReplace(ByRef InputVar, SearchText, ReplaceText = "", All = "") {
   StringReplace, v, %InputVar%, %SearchText%, %ReplaceText%, %All%
   Return, v
}

Is it really correct? Are all functions tested? Why is InputVar made dynamic??? I think you made a mistake by all those commands where the inputvar is the name of the variable.

_________________
{1:"ahkstdlib", 2:"my libs", 3:"my apps", 4:"my license"}
--> Don't feed the troll! <--


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 25th, 2010, 2:53 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
Fixed, thank you both Andrej and Tuncay.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 26th, 2010, 12:29 am 
Offline

Joined: October 18th, 2007, 9:21 pm
Posts: 343
Location: Saarland, Germany
Topic 1: Run() is not working

It has been reported twice before by Krogdor in May 2008, and also by Andrej in Oct 2009. Maybe it got fixed in a previous version, but now it is broken again.
Please try this demonstration code:
Code:
If Not Functions() ; make sure the stdlib gets loaded
    ExitApp
Run, notepad.exe,,, PID ; this is working
Gosub, ShowPID
PID := Run("notepad.exe") ; this is _not_ working
Gosub, ShowPID   
ExitApp

ShowPID:
    WinWaitActive, Untitled ahk_class Notepad
    WinClose, Untitled ahk_class Notepad
    MsgBox, Process ID was:`n%PID%
Return

It will work with the following change: (replace %v% in the second line with v)
Code:
Run(Target, WorkingDir = "", Mode = "") {
   Run, %Target%, %WorkingDir%, %Mode%, %v%
   Return, v   
}

Code:
Run(Target, WorkingDir = "", Mode = "") {
   Run, %Target%, %WorkingDir%, %Mode%, v
   Return, v   
}


Topic 2: Please consider renaming the "Boolean" functions
This is not really a request, but I would like to propose the following changes:
  • rename IfBetween() to Between()
  • rename IfContains() to Contains()
  • rename IfIs() to IsType()
  • remove IfIn() and all negative "Boolean" functions
I believe this would make code look and feel more natural (personal opinion). Also removing redundant functions would steamline the library. E.g. instead of writing this:
Code:
If IfBetween(var, 1, 5)
If IfNotContains(var, MatchList)
If IfIs(var, "integer")
If IfNotIn(var, MatchList)

One could write this:
Code:
If Between(var, 1, 5)
If Not Contains(var, MatchList)
If IsType(var, "integer")
If Not Contains(var, MatchList)

Just a thought, what do you think?


Wolf

_________________
Wolf

Schön wär's, wenn's schön wär!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 26th, 2010, 9:38 am 
Offline

Joined: November 7th, 2006, 9:47 pm
Posts: 1933
Location: Germany
I agree with previous poster. What about compatibility then? And may be a complete review for functionality is needed.

_________________
{1:"ahkstdlib", 2:"my libs", 3:"my apps", 4:"my license"}
--> Don't feed the troll! <--


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 42 posts ]  Go to page Previous  1, 2, 3

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users 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