Zedna Posted August 12, 2005 Share Posted August 12, 2005 (edited) missing return values and other optimizationsoriginal code:Func _MouseTrap($i_left = 0, $i_top = 0, $i_right = 0, $i_bottom = 0) If @NumParams == 0 Then DllCall("user32.dll", "int", "ClipCursor", "int", 0) Else If @NumParams == 2 Then $i_right = $i_left + 1 $i_bottom = $i_top + 1 EndIf Local $Rect = "int;int;int;int", $left = 1, $top = 2, $right = 3, $bottom = 4, $r $r = DllStructCreate($Rect) If @error Then Return -1 DllStructSetData($r, $left, $i_left) DllStructSetData($r, $top, $i_top) DllStructSetData($r, $right, $i_right) DllStructSetData($r, $bottom, $i_bottom) DllCall("user32.dll", "int", "ClipCursor", "ptr", DllStructGetPtr($r)) DllStructDelete($r) EndIf EndFunc;==>_MouseTrapcorrected and optimized code:Func _MouseTrap($i_left = 0, $i_top = 0, $i_right = 0, $i_bottom = 0) If @NumParams == 0 Then DllCall("user32.dll", "int", "ClipCursor", "int", 0) Return 0 EndIf If @NumParams == 2 Then $i_right = $i_left + 1 $i_bottom = $i_top + 1 EndIf Local $r = DllStructCreate("int;int;int;int") If @error Then Return -1 DllStructSetData($r, 1, $i_left) DllStructSetData($r, 2, $i_top) DllStructSetData($r, 3, $i_right) DllStructSetData($r, 4, $i_bottom) DllCall("user32.dll", "int", "ClipCursor", "ptr", DllStructGetPtr($r)) DllStructDelete($r) Return 0 EndFunc;==>_MouseTrapEDIT: version 3.1.1.67 Edited August 12, 2005 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Developers Jos Posted August 12, 2005 Developers Share Posted August 12, 2005 Don't understand the Return addition since that is implicit nor the optimization ? SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Zedna Posted August 12, 2005 Author Share Posted August 12, 2005 (edited) Don't understand the Return addition since that is implicit nor the optimization ?<{POST_SNAPBACK}>Now looking at HelpFile - You are right.I'm sorry, I didn't know about that implicit return value 0 for user defined functions.So there are only my optimizations:variables with constants that are used only once...EDIT: --> Local $Rect = "int;int;int;int", $left = 1, $top = 2, $right = 3, $bottom = 4 Edited August 12, 2005 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
GaryFrost Posted August 13, 2005 Share Posted August 13, 2005 not a bug i'll look at the optimizations. SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
GaryFrost Posted August 13, 2005 Share Posted August 13, 2005 (edited) if your worried about returns this would be more appropriate. Func _MouseTrap($i_left = 0, $i_top = 0, $i_right = 0, $i_bottom = 0) If @NumParams == 0 Then DllCall("user32.dll", "int", "ClipCursor", "int", 0) Else If @NumParams == 2 Then $i_right = $i_left + 1 $i_bottom = $i_top + 1 EndIf Local $Rect = DllStructCreate("int;int;int;int") If @error Then Return 0 DllStructSetData($Rect, 1, $i_left) DllStructSetData($Rect, 2, $i_top) DllStructSetData($Rect, 3, $i_right) DllStructSetData($Rect, 4, $i_bottom) Local $ret = DllCall("user32.dll", "int", "ClipCursor", "ptr", DllStructGetPtr($Rect)) DllStructDelete($Rect) Return $ret[0] EndIf EndFunc ;==>_MouseTrap Edited August 13, 2005 by gafrost SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
GaryFrost Posted August 26, 2005 Share Posted August 26, 2005 help fileReturn Value@@ReturnValue@@Success: Returns a non zero valueFailure: Returns 0@@End@@ SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
w0uter Posted August 26, 2005 Share Posted August 26, 2005 @numparams = 0 always returns 0. so i think this would be better. Func _MouseTrap($i_left = 0, $i_top = 0, $i_right = 0, $i_bottom = 0) If @NumParams == 0 Then $av_Ret = DllCall("user32.dll", "int", "ClipCursor", "int", 0) Else If @NumParams == 2 Then $i_right = $i_left + 1 $i_bottom = $i_top + 1 EndIf Local $v_Rect = DllStructCreate("int;int;int;int") If @error Then Return 0 DllStructSetData($v_Rect, 1, $i_left) DllStructSetData($v_Rect, 2, $i_top) DllStructSetData($v_Rect, 3, $i_right) DllStructSetData($v_Rect, 4, $i_bottom) Local $av_Ret = DllCall("user32.dll", "int", "ClipCursor", "ptr", DllStructGetPtr($v_Rect)) DllStructDelete($v_Rect) EndIf Return $av_Ret[0] EndFunc ;==>_MouseTrap My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll Link to comment Share on other sites More sharing options...
GaryFrost Posted August 26, 2005 Share Posted August 26, 2005 (edited) Func _MouseTrap($i_left = 0, $i_top = 0, $i_right = 0, $i_bottom = 0) Local $av_ret If @NumParams == 0 Then $av_ret = DllCall("user32.dll", "int", "ClipCursor", "int", 0) Else If @NumParams == 2 Then $i_right = $i_left + 1 $i_bottom = $i_top + 1 EndIf Local $Rect = DllStructCreate("int;int;int;int") If @error Then Return 0 DllStructSetData($Rect, 1, $i_left) DllStructSetData($Rect, 2, $i_top) DllStructSetData($Rect, 3, $i_right) DllStructSetData($Rect, 4, $i_bottom) $av_ret = DllCall("user32.dll", "int", "ClipCursor", "ptr", DllStructGetPtr($Rect)) DllStructDelete($Rect) EndIf Return $av_ret[0] EndFunc ;==>_MouseTrap Edited August 26, 2005 by gafrost SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
w0uter Posted August 26, 2005 Share Posted August 26, 2005 ugh, silly error.btw you should follow the guide-lines on naming variabel'shttp://www.autoitscript.com/autoit3/scite/...F_Standards.htm My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll Link to comment Share on other sites More sharing options...
GaryFrost Posted August 26, 2005 Share Posted August 26, 2005 (edited) fixed, miss some once in awhile. Edited August 27, 2005 by gafrost SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
w0uter Posted August 26, 2005 Share Posted August 26, 2005 what should we name this: $Rect = DllStructCreate() i use $v_ but maby there should be a new one like $d_ ? My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll Link to comment Share on other sites More sharing options...
GaryFrost Posted August 26, 2005 Share Posted August 26, 2005 I've been leaving the Rect structures with name, describes what is in the name itself. Gary SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
jpm Posted August 27, 2005 Share Posted August 27, 2005 as it is not a bug I move it to developper forum so you can continue to post Link to comment Share on other sites More sharing options...
GaryFrost Posted August 27, 2005 Share Posted August 27, 2005 as it is not a bug I move it to developper forum so you can continue to post <{POST_SNAPBACK}>Thank you SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now