Sign in to follow this  
Followers 0

help creating a function

4 posts in this topic

#1 ·  Posted (edited)

I am a beginner to autoit. the script i am writing is to prepare a computer to be imaged by installing all normal programs and setting computer settings

I have my program finished but i am trying to cut down on code

i would like to create a funtion for the gui controls. Is there a way to pass a variable name?

like for example.


Func _IniReadCheckbox($checkbox, $text, $run, $ran, $left, $top, $width, $height, $ranleft)

$checkbox = GUICtrlCreateCheckbox($text, 10, 15, 130, 15)

If IniRead($settings, "Script_Settings", $run, "") = 1 And IniRead($settings, "Program_Use_Only", $ran, "") = 0 Then

GUICtrlSetState($remuser, $GUI_CHECKED)


If IniRead($settings, "Program_Use_Only", $ran, "") = 1 Then

GUICtrlCreatePic($workingdir & "AutoIT\ran.bmp", $height, $top, $height, $height)




but $checkbox needs to pass a variable i can put something like

_IniReadCheckbox($installoffice, "Install Office", "Install Office", "Installed Office, 10, 15, 130, 15, 145)

_IniReadCheckbox($setvisstyle, "Set Visual Style", "Set_Visual_Settings", "Set_Visual_Settings, 10, 30, 130, 15, 145)

Edited by ACalcutt

Andrew Calcutt



Its not an error, its a undocumented feature

Share this post

Link to post
Share on other sites

The way you have it should work. It is easy to test... just write a script to test it.

$x = "Foo"


Func _MyFunc($p, $q)
    MsgBox(0,"Test", $p & $q)

I don't think you want byRef -- byRef variables share the same memory location both in the main program and in the function so that updates to the variable in the function immediately affect the variable in the main as well. You don't need this. By default, they pass byValue which means that the value of the variable at the time of the function call is copied to a new memory location and it works independantly of the variable in the main program (this is typically safer).


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post

Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
Followers 0