Leaderboard
Popular Content
Showing content with the highest reputation on 04/28/2013 in all areas
-
The documentation tells you all you need. The ASP example translated to AutoIt to return the city for a hostname: Global $oGeoIp = ObjCreate("GeoIPCOMEx.GeoIPEx") $oGeoIp.set_db_path("C:\Program Files\GeoIP\") $oGeoIp.find_by_name($sHostname) $sCity = $oGeoIp.cityUntested!1 point
-
Check GeoIP_doc.txt. There you'll find how to register the DLL. In the examples directory you'll find the ASP example that show how to create the object and then use the properties and methods.1 point
-
Rickname, When you reply, please use the "Reply to this topic" button at the top of the thread or the "Reply to this topic" editor at the bottom rather than the "Quote" button - I know what I wrote and it just pads the thread unneccessarily. No, AutoIt does not "autofind" anything - it is just an aide-memoire for the coder. M231 point
-
Rickname, Here we go: ByRef: When you pass parameters to a function you can do it in 2 ways: - By value (the default) where the function makes a copy of the variable to use and destroys it at then end of the function leaving the original unchanged. - By reference (ByRefwhere the function is told where the original variable is located. Any changes to this original made by the function remain after the function ends. If you look at the Variables - using Global, Local and ByRef tutorial in the Wiki, you will see some examples showing this in action. Letter after the $: You can call your variables whatever you like (as long as you use alphanumeric characters and underscores) but as AutoIt is not a typed language, coders often use the first letter to indicate what type variable is being held in that particular name. My personal usage is: $a = Array $b = Binary $c = ControlID $f = Boolean flag (True/False) $h = Handle $i - Integer number $m = Menu item $n = Floating point number $p = Pointer $s = String %t = Struct $v = Undefinedbut you can obviously vary this according to you personal preference. You do not need to do it at all, but experience has shown that it is a good idea. Tidying up: Autoit is extremely well-behaved and does a lot of housekeeping after a script ends to make sure that most of the mess (such as open handles) is tidied away. However it behoves the careful coder to do as much clearing up as possible within the script - not only is this good practice, but it prepares you for when you move on to less-forgiving languages. In certain cases, such as when you use AutoIt to create very complex items like DLL callbacks and GDI handles, AutoIt will not correctly clear up when it is shut down and it is imperative that the coder tidies up the code. If not the system could become unstable or exhibit memory leaks. Functions: There are no problems with your second example, although there is with the first! Most of the Help file examples have the code within a function - this is done deliberately to reduce the number of Global variables, which is generally regarded as good coding practice. In longer more complex scripts you will certainly need functions - in small scripts you can often do without. Does that make it all clearer? Please ask if you have any more (or indeed any supplementary) questions. M231 point
-
Rickname, Please do not bump your own threads within 24 hours. Remember this is not a 24/7 support forum - those who answer are only here because they like helping others and have some time to spare. You just have to wait until someone who knows something about your particular problem, and is willing to help, comes online. Be patient and someone will answer eventually. M231 point
-
AutoIT3 Virtualization UDF
mesale0077 reacted to prazetto for a topic
New function and change core API Please take a look to VirtualFlex.Memory.au3 and you will notice some significan change. ; New Function ; Virtual_ProcessOption ; Virtual_VirtualGate ; Virtual_VirtualChild ; Virtual_VirtualDeamon -> Correct usage Virtual_ProcessOption on sample Sample.InternetExplorer^.au3 -> Add precompiled binary and Library API and also how to usage in VB6 @davidkim #do not running x64 compile... #why..not running? Not Now! #Java VM virtualization? What you want with Java/Java Executable File. Like something run without installing Java Run Time Environment in machine? or maybe other. What you thinking? At least please more detailed and specified. @legend #How would you run any other app, than a .net app? with "Sample.ExecuteDotNet.au3" #If I try to use it with another application, that hasn't been written in .net, it gives an error, that it needs .net #no reply, will it only work for .net files? Virtual_ExecuteDotNetA/W only execute dot net app See example on attached link Sample.LaunchEmbeddedExe^.zip Thats use ShellExecute which execute executable created with AutoIt31 point -
Yes, that first is true, so I'm always careful with other people's code, and unless it's an Include/UDF, tend to modify it to my conventions ... giving credit of course where due. I'm not sure you are right about memory release, unless you null it ... and even then ..... If I remember right, nothing is fully released until the script closes or perhaps when each portion of code completes execution ... I presume so anyway? For instance, declaring a Dim or Local in your main section of script, that then calls other functions etc, would stay alive until the main section of code exits. Not sure about instances in the functions, etc ... perhaps they stay alive until the full script exits? No doubt the wise informed ones here will comment on all that, so we know.1 point
-
Good coding practices in AutoIt
Wombat reacted to DicatoroftheUSA for a topic
Notable mention is using prefix to indicate the type of expected variable. . $aStuff ;array $sStuff ;string $oStuff; object $hStuff; handle $bStuff ; binary, true/false $iStuff ; integer $nStuff ;number $g*stuff ; global variable $c*stuff ; constant If there is a more complete list, a link would be appreciated. I think there is a name for that syntax after some old school programmer, but for the life of me can't remember. I used to be really bad at doing that, and still revert to bad syntax when throwing out examples. I don't know what is a normal prefix for static, I never saw that keyword before perusing this thread. At first I didn't even get why people put those prefixes in, then once I got it I thought it would slow me down. Now I can't see myself doing anything halfway serious without it.1 point -
czardas, Here you are >> #include <Array.au3> Global $aArray[2] = [1, 2] SomeFunc() Func SomeFunc() ReDim $aArray[3] ; Re-size the array and keep its content. _ArrayDisplay($aArray) Global $aArray[2] ; Erase the contents of $aArray and re-size it. _ArrayDisplay($aArray) EndFunc ;==>SomeFunc1 point
-
ok, what I said is a little bit wrong. Here is my example : Global $var Local $var ;these vars are declared in the global scope, no matter of their statement, it's Global. ;to avoid any ambiguity, use only the Global statement. Global $aArray[2] = [1, 2] ;just an array. Func _myFunc() Local $var ;only use the local statement inside functions, if you want to declare a Global var, ;it's better to first initialize it in the global scope. ReDim $aArray[3] ;resize the array and keep its content. Dim $aArray[2] ;erases the content of the array. [and resizes it] ;it's better to use Dim/ReDim to edit an array, otherwise use Local or Global to declare a var. EndFunc Of course I don't say it's right nor I'm the one to follow and I'm opened to criticisms. @czardas If you declare a non existing var with the Dim statement, then It will be declared according to the current scope, otherwise it will take the scope of the declared var.1 point
-
Good examples The Dim statement should be only used to erase the content of a globally declared array, so ReDim only to resize it. Everything out of functions should be declared as Global, and inside them as Local. But this is only notes.1 point
-
Declaring variables in loops (For, While, Do etc..) can have an affect on efficiency: #include <MsgBoxConstants.au3> ; Declaring variables inside loops should be avoided as the variable is re-declared on each repetition. For $i = 1 To 10 ; $i is in 'loop scope.' Local $iInt = $i Next MsgBox($MB_SYSTEMMODAL, '', $iInt) ; This will display 10. #include <MsgBoxConstants.au3> ; Declaring variables outside of loops is more efficent in the long run. Local $iInt = 0 For $i = 1 To 10 ; $i is in 'loop scope.' $iInt = $i Next MsgBox($MB_SYSTEMMODAL, '', $iInt) ; This will display 10.1 point
-
Declaring Global variables in a Function is never a good idea: #include <MsgBoxConstants.au3> ; Calling Example() first will initialise the Global variable $vVariableThatIsGlobal and therefore calling SomeFunc() won't return an error. ; Now look at Example 2. Example() Func Example() ; Declaring a variable in a function can cause serious problems, hence why all Global variables should be declared at the top of a script. Global $vVariableThatIsGlobal = 'This is a variable that has ''File Scope'' aka Global.' SomeFunc() EndFunc ;==>Example Func SomeFunc() MsgBox($MB_SYSTEMMODAL, '', $vVariableThatIsGlobal) ; As the variable was initialised this will not return an error. EndFunc ;==>SomeFuncExample 2: #include <MsgBoxConstants.au3> ; Calling SomeFunc() first will bypass the Global variable $vVariableThatIsGlobal being initialised and therefore AutoIt has no idea of what data the variable ; $vVariableThatIsGlobal contains. SomeFunc() Func Example() ; Declaring a variable in a function can cause serious problems, hence why all Global variables should be declared at the top of a script. Global $vVariableThatIsGlobal = 'This is a variable that has ''File Scope'' aka Global.' SomeFunc() EndFunc ;==>Example Func SomeFunc() MsgBox($MB_SYSTEMMODAL, '', $vVariableThatIsGlobal) ; As the variable wasn't initialised this will return an error of "variable used without being declared." EndFunc ;==>SomeFunc Question: What if I want to retain variable data once returned from a Function and only use that variable in that particular Function, can't it be declared as Global then? Answer: Static variables. #include <MsgBoxConstants.au3> Example() Func Example() SomeFunc() ; This will display a message box of 1, 1. SomeFunc() ; This will display a message box of 1, 2. SomeFunc() ; This will display a message box of 1, 3. EndFunc ;==>Example Func SomeFunc() ; This initialises a Static variable in Local scope. When a variable is declared just in Local scope (within a Function,) ; it's destroyed when the Function ends/returns. This isn't the case for a Static variable. The variable can't be ; accessed from anywhere else in the script apart from the Function it was declared in. Local Static $vVariableThatIsStatic = 0 Local $vVariableThatIsLocal = 0 $vVariableThatIsLocal += 1 ; This will always be 1 as it was destroyed once returned from SomeFunc. $vVariableThatIsStatic += 1 ; This will increase by 1. MsgBox($MB_SYSTEMMODAL, $vVariableThatIsLocal, $vVariableThatIsStatic) EndFunc ;==>SomeFunc1 point