Sign in to follow this  
Followers 0
Chimaera

What is the best way to proceed?

5 posts in this topic

#1 ·  Posted (edited)

Hi all just got started again on some code

And im creating a silent installer for a set of programs we use at work.

Now its the button and program checking im doing atm like this

GUICtrlCreateLabel ( "AVG", 170, 135 , 60 , 30)
            $install_avg = GUICtrlCreateButton(" ", 120, 120, 45, 40)
                $avg_test = FileExists("C:\Program Files (x86)\AVG\AVG10\avgtray.exe");<<<<<<<<<<< checks install on pc
                $install_ver = FileGetVersion("C:\Program Files (x86)\AVG\AVG10\avgtray.exe");<<<<<<<<<<<<<< version on pc
                $pen_ver = FileGetVersion(@ScriptDir & "\file_includes\install\install_avg_32.exe");<<<<<<<< version on pendrive

                If $avg_test = 1 And $install_ver = $pen_ver Then
                    GUICtrlSetImage($install_avg, @ScriptDir & "\images\good.ico");<<<<<<<<< if up to date then disable the button
                        GUICtrlSetState(-1, $GUI_disable)
                ElseIf GUICtrlSetImage($install_avg, @ScriptDir & "\images\maybe.ico") Then ;<<<<<<<<< installed but not upto date so button active with different pic

                Else
                    GUICtrlSetImage($install_avg, @ScriptDir & "\images\cross.ico");<<<< not installed
                EndIf

I have three diferent icon depending on the state of the install see the comments

The same three button icons are used for all the program

Now i have also done it like this in my attempts to make it better

Select
    Case $avg_test = 1 And $install_ver = $pen_ver
        GUICtrlSetImage($install_avg, @ScriptDir & "\images\good.ico")
            GUICtrlSetState(-1, $GUI_disable)
    Case $avg_test = 1 And $install_ver <> $pen_ver
        GUICtrlSetImage($install_avg, @ScriptDir & "\images\maybe.ico")
    Case Else
        GUICtrlSetImage($install_avg, @ScriptDir & "\images\cross.ico")
EndSelect

So to the question, is there a better way to do this? this is just one button and i have a lot more to do.

So is there a way to reduce the size of this cos it sems an awful lot of code for one button

eg: Is there a way to combine this?

$avg_test = FileExists("C:\Program Files (x86)\AVG\AVG10\avgtray.exe")
                $install_ver = FileGetVersion("C:\Program Files (x86)\AVG\AVG10\avgtray.exe")

and which is the best using the IF else or the Case method?

Last question

On the button the graphic im using is just a small icon 32 x 32 and the button is 45 x 45 so it sits nicely inside it but

this line causes a problem

$install_avg = GUICtrlCreateButton(" ", 120, 120, 45, 40)

because the space " " causes the graphic to be of centre as it pushes it across

Now ive tried lots of different ways and if i dont have the space in the create button bit the icon dosent appear, so how do i get the icon back into the middle of the button?

Many thanks for any help

Jez

Edited by Chimaera

Share this post


Link to post
Share on other sites



Ideal situation for using functions

GUICtrlCreateLabel("AVG", 170, 135, 60, 30)
$install_avg = GUICtrlCreateButton(" ", 120, 120, 45, 40)
SetButtonImage($install_avg, _ 
                "C:\Program Files (x86)\AVG\AVG10\avgtray.exe", _
                @ScriptDir & "\file_includes\install\install_avg_32.exe")

GUICtrlCreateLabel("VLC", 170, 175, 60, 30)
$install_vlc = GUICtrlCreateButton(" ", 120, 160, 45, 40)
SetButtonImage($install_vlc, _ 
                "C:\Program Files (x86)\VideoLan\VLC\vlc.exe", _
                @ScriptDir & "\file_includes\install\install_vlc_32.exe")

; ...

Func SetButtonImage($button_id, $install_exe, $pen_exe)
    $exists = FileExists($install_exe);<<<<<<<<<<< checks install on pc
    $install_ver = FileGetVersion($install_exe);<<<<<<<<<<<<<< version on pc
    $pen_ver = FileGetVersion($pen_exe);<<<<<<<< version on pendrive
    
    Select
        Case $exists = 1 And $install_ver = $pen_ver
            GUICtrlSetImage($button_id, @ScriptDir & "\images\good.ico")
            GUICtrlSetState($button_id, $GUI_disable)
        Case $exists = 1 And $install_ver <> $pen_ver
            GUICtrlSetImage($button_id, @ScriptDir & "\images\maybe.ico")
        Case Else
            GUICtrlSetImage($button_id, @ScriptDir & "\images\cross.ico")
    EndSelect
EndFunc

Share this post


Link to post
Share on other sites

Thanks for the help but im a little confused

SetButtonImage($install_avg, _
                "C:\Program Files (x86)\AVG\AVG10\avgtray.exe", _
                @ScriptDir & "\file_includes\install\install_avg_32.exe")

The SetButtonImage i guess is to call the function from lower down the script, sort of look for the details here?

but what does this bit apply to?

($install_avg, _
                "C:\Program Files (x86)\AVG\AVG10\avgtray.exe", _
                @ScriptDir & "\file_includes\install\install_avg_32.exe")

I understand its the 2 paths but why combine them?, the two versions are different as the installed one is generally less up to date and the pen is updated often

And on this one

Func SetButtonImage($button_id, $install_exe, $pen_exe)
    $exists = FileExists($install_exe);<<<<<<<<<<< checks install on pc
    $install_ver = FileGetVersion($install_exe);<<<<<<<<<<<<<< version on pc
    $pen_ver = FileGetVersion($pen_exe);<<<<<<<< version on pendrive

Why are these three added to the start of the function?, what benifit does this have?

($button_id, $install_exe, $pen_exe) and where do these variables come from?, or am i supposed to change them for the actual ones?

Sorry for seeming a bit dim but ive never seen this way before and for me to make use i have to understand the extra bits that have been added.

Many thanks

Jez

Share this post


Link to post
Share on other sites

I made my own function

SetButtonImage()

which contains repetitive task.

So I only write i once in this function and later I can call it like any other functions many times with diferent parameters.

Parameters of function are declared in first line and inside function are like local variables.

Please read Autoit's helpfile for these basic information about functions.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Another good source (I found anyway) is looking through the UDF's in the Include Folder, normally located in 'C:\Program Files\AutoIt\Include.' This is how I learnt about the benefits/meaning of ByRef which is sometimes overlooked (Array.au3 has a good Example of ByRef) You also see how to structure Functions properly.

Plus I suggest using #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 at the top of the AU3 File to see if Variables are declared correctly, because Variables declared in a Function without the use of Local/Global can become tricky to debug.

Edited by guinness

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

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