Looking for some advice to shorten/cleanup script

Recommended Posts

Elephant007 0

Elephant007 0

Lengthy script that I need some help cleaning up, there are a lot of repetitiveness in the script and I have no idea how to make it shorter if it can be made shorter which I'm sure it can I just don't know how

I'm not asking for someone to rewrite the whole thing, unless you want to, I'm just asking for some guidance on how to shorten it...

I tried posting the script and my browser crashed, so instead I'm going to provide it as an attachment. It requires you to be using it from a domain, I removed that part so you can run it on your local computer

This gives me the same results as your script when I test it - although I have not been through every possible combination. I have commented the script liberally so I hope you can follow it without problem, but please do ask if you have any questions.

And thanks for filling in an empty morning while the wife had friends around for coffee.

M23

Edited October 27, 2012 by Melba23Tinkering!

1

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

Share this post

Link to post

Share on other sites

Elephant007 0

Elephant007 0

PheonixXL; Nightmare of a script huh? Wouldn't doubt it at all, this is why I'm asking for some help! HAHA I was hesitant at first to post it, then thought, this is a help forum so what the heck.. haha, thanks for being gentle though. The button that grays out is used as a "back" feature to get back to the previous menu. Thank you for your advice

Melba23; Wow, just wow, thank you for taking the time to write what you did... It's cool that the data can be called from an ini file, could I essentially add the ini using FileInstall()? Thank you so much for laying the foundation of this program, I can take it from here and hopefully keep it as clean as you gave it to me...

Thank you everyone for looking and giving me direction on how you best thing to solve this messy nightmare!

It would mean another code change where we extract the matching computer codename sections, but that is easy to do. What do you think?

M23

1

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

It would mean another code change where we extract the matching computer codename sections, but that is easy to do. What do you think?

M23

Yes we have 10,000 computers on our domain and we would like for users in specific security groups to be able to change a computer when it is moved to a different location. Our plan is to have this program available on all 10,000 computers so at anytime any computer that is moved can be renamed to try to help identify where the computer is located

Thank you for all the help you given me, you've made my headache go away! I should also let you know that I plan to include netdom and dsquery in the script too... makes it a little meater but I can't guarantee that all computers will have the required files to rename the computer on active directory

Share this post

Link to post

Share on other sites

Melba23 2,865

Melba23 2,865

Then I would definitely go for FileInstalling the ini file - then all you need to do to update the various elements would be to amend/overwrite that single file.

Delighted I could help - as I said it helped pass a morning when I was confined to my study. Do come back if you run into any problems with it.

M23

1

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

Share this post

Link to post

Share on other sites

Elephant007 0

Elephant007 0

Excellent! One last question I have for now. It's possible that the room number can be alpha and numeric. How can I enable it so that the room number can be alphanumeric and not allow any special characters?

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

Look for the <<<<<<<<<<<<<<<<<<<<<<<< lines - these explain what I have done and why. I hope it is all self-explanatory, but do not hesitate to ask if anything is unclear.

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

Share this post

Link to post

Share on other sites

Elephant007 0

Elephant007 0

I'm testing what you've provided and it seems the GUICtrlRead($Username) isn't passing to the CheckPermissions function. I put a MsgBox in that function with GUICtrlRead($Username) in it and it comes up blank.

I really like the explainations you've provided for me and I can see my logic isn't logical at all, don't worry... I've been accused more than once of 'thinking outside the box'

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

Share this post

Link to post

Share on other sites

Melba23 2,865

Melba23 2,865

I thought that a variable within a function could only be seen by that function and not any other functions. I guess this thought is incorrect?

No, you are correct - a Local variable is only visible within that function. But in this case we are passing the variable as a parameter to the next function - in that case the function creates its own variable with that value. I suggest reading the Variables - using Global, Local and ByRef tutorial in the Wiki to learn more.

And as i said, when you have read all the comments please do ask if anything I have done or ths reasons for my doing it are unclear.

M23

P.S. And please add a Local in front of $sUsername in line #548 of that script - I really should have done so myself when coding it.

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

Share this post

Link to post

Share on other sites

Melba23 2,865

Melba23 2,865

As far as I know you can only set one DEFBUTTON as you create the script - you cannot change it "on the fly". What I suggest is setting "ENTER" to act as an Accelerator key and linking it to each button as they are activated. Take a look at the <<<<<< lines in this version of the script:

Accelerator keys are like HotKeys - except that they only fire when your GUI is active. I use them a lot - they have to be linked to a control, but it is easy to create a dummy if necessary. And unlike HotKeys they not not upset other apps running at the same time.

Any more questions?

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