Jump to content

help creating a function


ACalcutt
 Share

Recommended Posts

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)

EndIf

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

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

EndIf

EndFunc

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

but $checkbox needs to pass a variable name....so 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

Http://www.Vistumbler.net

Http://www.TechIdiots.net

Its not an error, its a undocumented feature

Link to comment
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"
_MyFunc($x,"Bar")

Exit

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

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).

Dale

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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...