Share this post

Link to post

Share on other sites

Melba23 2,898

Melba23 2,898

Using a Switch/Select structure within an infinite loop is the "normal" way to check for button presses on a GUI when using AutoIt in GetMessage mode. So if you have 8/10 buttons you would need 8/10 Case elements within the structure (or possibly less if some buttons do the same thing! ).

All this does run the subsequently declared function called _Install. Some programmers prefer nearly all script activity to occur in functions, others are less concerned. One for the main reasons for wanting to keep activity in functions is that it effectively limits the scope of variables - although it can mean a lot of parameter passing between the various functions.

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort---- Sort arrays on multiple columnsChooseFileFolder---- Single and multiple selections from specified path treeview listingDate_Time_Convert-- Easily convert date/time formats, including the language usedExtMsgBox--------- A highly customisable replacement for MsgBoxGUIExtender-------- Extend and retract multiple sections within a GUIGUIFrame---------- Subdivide GUIs into many adjustable framesGUIListViewEx------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx------ Check/clear parent and child checkboxes in a TreeViewMarquee----------- Scrolling tickertape GUIsNoFocusLines------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify------------- Small notifications on the edge of the displayScrollbars----------Automatically sized scrollbars with a single commandStringSize---------- Automatically size controls to fit textToast-------------- Small GUIs which pop out of the notification area

Here the whole script is actually in the 2 functions Example1 and Example2. Study the example script and you will see that everything from GUI creation to the GUIGetMsg loop for each example is contained within the relevant function. Now this is an extreme case of the "everything in a function" programming style that I mentioned earlier, but it is perfectly valid.

In your case I imagine you have your GUI creation code earlier in your script, so there is little to be gained by passing the GUIGetMsg return value to a function which only contains the Switch structure. What you might think of doing is to make a function for each of the install selections - something along these lines:

That way you keep your GUIGetMsg loop nice and tidy and put all the messy code in a function. I am a great believer in trying to keep code as tidy as possible - I find it helps in debugging if you keep things nice and clear. Besides, you often find you can reuse functions in other scripts (even if they do require a little tweaking for different variable names at times) - this is known as modular coding where you use generic functions to do standard things, a bit like the UDFs if you like.

But all this is just a matter of coding style. If you look at the scripts posted by those members who have been here a while you will see that they tend to use the sort of methods I have mentioned above. No-one has the perfect solution - a lot depends on exactly what the script is for and how the particular coder likes to set up his code.

I hope that helps explain a bit more.

M23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort---- Sort arrays on multiple columnsChooseFileFolder---- Single and multiple selections from specified path treeview listingDate_Time_Convert-- Easily convert date/time formats, including the language usedExtMsgBox--------- A highly customisable replacement for MsgBoxGUIExtender-------- Extend and retract multiple sections within a GUIGUIFrame---------- Subdivide GUIs into many adjustable framesGUIListViewEx------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx------ Check/clear parent and child checkboxes in a TreeViewMarquee----------- Scrolling tickertape GUIsNoFocusLines------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify------------- Small notifications on the edge of the displayScrollbars----------Automatically sized scrollbars with a single commandStringSize---------- Automatically size controls to fit textToast-------------- Small GUIs which pop out of the notification area

Link to post

Share on other sites

Melba23 2,898

Melba23 2,898

"A function is a section of code that can be called from the script to perform a certain "function"."

So when you call a function you are asking for this section of code to be run at that point in the script. Regardless of what that section of code does, you always return to that same point in the script at some point - unless the script comes across an "Exit" command beforehand.

Perhaps this will help to clarify:

; Some code Func Function_1
Function_1()---------------------------------------------> ; Code for Function_1
; Some more code for Function_1
; We restart the main script with this code <------------- ; Even more code for Function_1
; And yet more code EndFunc
; [...]
; Even more code Func Function_2
Function_2()---------------------------------------------> ; Code for Function_2
; Some more code for Function_2
; And return to the main script here <-------------------- ; Even more code for Function_2
; And continue with more code EndFunc
; And even more code

And you most certainly cannot use $_Install1 - again from the Help file:

"Function names must start with either a letter or an underscore, and the remainder of the name can contain any combination of letters and numbers and underscores.".

Only variables begin with $:

"Each variable [...] must start with the $ character and may only contain letters, numbers and the underscore _ character".

Of course, another of the advantages of using functions is the ability to use the same code at several points in your script - saves a lot of wear on your typing fingers.

Clearer now?

M23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort---- Sort arrays on multiple columnsChooseFileFolder---- Single and multiple selections from specified path treeview listingDate_Time_Convert-- Easily convert date/time formats, including the language usedExtMsgBox--------- A highly customisable replacement for MsgBoxGUIExtender-------- Extend and retract multiple sections within a GUIGUIFrame---------- Subdivide GUIs into many adjustable framesGUIListViewEx------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx------ Check/clear parent and child checkboxes in a TreeViewMarquee----------- Scrolling tickertape GUIsNoFocusLines------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify------------- Small notifications on the edge of the displayScrollbars----------Automatically sized scrollbars with a single commandStringSize---------- Automatically size controls to fit textToast-------------- Small GUIs which pop out of the notification area

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort---- Sort arrays on multiple columnsChooseFileFolder---- Single and multiple selections from specified path treeview listingDate_Time_Convert-- Easily convert date/time formats, including the language usedExtMsgBox--------- A highly customisable replacement for MsgBoxGUIExtender-------- Extend and retract multiple sections within a GUIGUIFrame---------- Subdivide GUIs into many adjustable framesGUIListViewEx------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx------ Check/clear parent and child checkboxes in a TreeViewMarquee----------- Scrolling tickertape GUIsNoFocusLines------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify------------- Small notifications on the edge of the displayScrollbars----------Automatically sized scrollbars with a single commandStringSize---------- Automatically size controls to fit textToast-------------- Small GUIs which pop out of the notification area

Link to post

Share on other sites

Melba23 2,898

Melba23 2,898

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort---- Sort arrays on multiple columnsChooseFileFolder---- Single and multiple selections from specified path treeview listingDate_Time_Convert-- Easily convert date/time formats, including the language usedExtMsgBox--------- A highly customisable replacement for MsgBoxGUIExtender-------- Extend and retract multiple sections within a GUIGUIFrame---------- Subdivide GUIs into many adjustable framesGUIListViewEx------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx------ Check/clear parent and child checkboxes in a TreeViewMarquee----------- Scrolling tickertape GUIsNoFocusLines------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify------------- Small notifications on the edge of the displayScrollbars----------Automatically sized scrollbars with a single commandStringSize---------- Automatically size controls to fit textToast-------------- Small GUIs which pop out of the notification area

This puts your button checks inside the While...Wend loop where it belongs, so that the buttons are continuously monitored, and still allows you to exit the script.

Edited November 2, 2010 by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

As you are obviously very new to scripting (and we all started at that point ) have you read the Help file (at least the first few sections - Using AutoIt, Tutorials and the first couple of References)? This will help you enormously to get an idea of how AutoIt scripts are structured. You should also look at the excellent tutorials that you will find here and here.

Given the problems you are having with such fundamental concepts as functions and the idle loop, I feel that it would be time well spent.

M23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort---- Sort arrays on multiple columnsChooseFileFolder---- Single and multiple selections from specified path treeview listingDate_Time_Convert-- Easily convert date/time formats, including the language usedExtMsgBox--------- A highly customisable replacement for MsgBoxGUIExtender-------- Extend and retract multiple sections within a GUIGUIFrame---------- Subdivide GUIs into many adjustable framesGUIListViewEx------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx------ Check/clear parent and child checkboxes in a TreeViewMarquee----------- Scrolling tickertape GUIsNoFocusLines------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify------------- Small notifications on the edge of the displayScrollbars----------Automatically sized scrollbars with a single commandStringSize---------- Automatically size controls to fit textToast-------------- Small GUIs which pop out of the notification area