Jump to content

Global Variables


bourny
 Share

Recommended Posts

I need to create a bunch of global variables to assign to a load of progress bars. Issue is I dont know how many I will need and this number will change depending on the situaton.

I have an array that holds entries for applications names app1, app2, app3 etc. I want to create a progress bar for each app.

The way I am trying to go about this is to read the array containing the list of apps and assign a global variable to it based on the name of the app.

Example would be the progress bar global variable for app1 would be $progressBar_App1

I am moving down the array reading the first column containing the app name and planning to put the name of the variable in a second column along side that. I am not asking for help creating a multi row array as this is not the issue. My issue is getting my gead around how I decalre a variable that is stored in the array next to the app it belongs to to allow me to update the progress bar belonging to that app.

Hope this makes sense.

Link to comment
Share on other sites

  • Moderators

bourny,

Why declare a new name at all? Just use the array to hold the app name and the progressbar ControlID: :)

; Declare the app
Global $aApps[4][2] =[[3, 0], ["App 1", 0],["App 2", 0], ["App 3", 0]]

; Then create the progress controls
For $i = 1 To $aApps[0][0]
    $aApps[$i][[1] = GUICtrlCreateProgress(....)
Next

; And to update a progress - use a function and pass the index and position as parameters
_Update_Progress(1, 50)

Func _Update_Progress($iIndex, $iPosition)
    GUICtrlSetData($aApps[$iIndex][1], $iPosition)
EndFunc

Does that make sense? :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

It sorts of makes sense. I was using my array to hopefully hold the controlID however I was trying to create a one and feed it into the array position. Your way makes sense however I need to try and apply what you have suggested into my working model.

BTW the script I am writing is to create BITS file transfer jobs that write the bits file transfer progress intlo the registry via powershell commands. Works really well . I am however using a gui called Toasts to serve up the interface with progress bars etc. Heard of that script by any chance. (Thanks for both the above suggestion and the toasts gui.)

Link to comment
Share on other sites

  • Moderators

bourny,

Correct. Post the code and I will happily take a look. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I have attached Test which Is a part of the script that concentrates on the creation of the progress bars and calling the toasts GUI.

I have created the $Aapps in the same way my master array is built in the main scriot which is using 4 rows and 4 colums for the 4 test apps. (Obviously the array grows dynamically based on the number of applications it is fed)

I have also uploaded an ammended copy of your toasts.au3 that I have set to always display in the Top center as well as adding an autogrow Gui height feature to it using the $HeightOfGui Variable called in the test script.

(I will be tidying the script up and removing the multiple loops)

test.au3

Toast.au3

Link to comment
Share on other sites

  • Moderators

bourny,

You are trying to create the progressbars before there is a GUI to hold them. ;)

Move the GUICtrlCreateProgress section after the _Toast_Show and you will get them created on the Toast. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Excellent.

Thanks, This works. I have moved that loop around so many times in that function. I am so used to using Gui create it completely escaped me that this is being carried out in your toast functions.

I will hopefully now be on my way to a very nice Bits transfer program using Powershell BITS cmdlets, that can dynamically display the correct ammount of progress bars for each download and reflect the status of each download direct from powershell output.

Link to comment
Share on other sites

Melba23:

I have it all working apart from 2 things I would like to do.

I would like to be able to change the colour of the progress bar to red if the download fails. I have tried GuiCtrlSetColor($aApps[$i][1], 0x00ff00)

I also tried GuiCtrlSetbkColor and this does not work either.

The second thing I would like to do is place a minimize / Minimize undo to allow the gui to shrink back up to the top of the screen with the title bar still visible to allow it to be maximized.

Thanks for all your help and code especially the toast code.

Link to comment
Share on other sites

You have to turn off windows themes on the progress bar(s) if you want to change their color.

This function, written by guinness makes it easy to do.

; #FUNCTION# =========================================================================================================
; Name...........:  _GUICtrlSetTheme
; Description ...:  Sets a 'themed' Control with the ability to change the color of the control
; Syntax.........:  _GUICtrlSetTheme($iControl = -1, $bThemeColor = 0x24D245)
; Parameters ....:  $iControl - [optional] A valid control ID. Default = -1 (last control ID)
;                   $hHandle - [optional] A valid Hex color value. Default = 0x24D245
; Requirement(s).:  v3.3.0.0 or higher
; Return values .:  Success - Returns a value from the 'SetWindowTheme' DLL call.
;                   Failure - Returns 0 with @extended set as 1.
; Author ........:  guinness.
; Example........;  Yes
;=====================================================================================================================
Func _GUICtrlSetTheme($iControl = -1, $bThemeColor = 0x24D245)
     If Not IsHWnd($iControl) Then $iControl = GUICtrlGetHandle($iControl)
     Local $aReturn = DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", $iControl, "wstr", 0, "wstr", 0)
     If @error Then Return SetError(1, 1, 0)
     GUICtrlSetColor($iControl, $bThemeColor)
     Return $aReturn[0]
EndFunc   ;==>_GUICtrlSetTheme

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 Gude
How 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.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • Moderators

BrewManNH

You have to turn off windows themes on the progress bar(s) if you want to change their color

Not so - you can set a normal progress to red, yellow or green using the $PBM_SETSTATE message: ;)

#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>

Const $PBST_NORMAL = 0x0001
Const $PBST_ERROR = 0x0002
Const $PBST_PAUSED = 0x0003

$hGUI = GUICreate("Progress Test", 500, 130)

$hProg_Theme = GUICtrlCreateProgress(10, 10, 480, 30)
GUICtrlSetData(-1, 100)

$hProg_NoTheme = GUICtrlCreateProgress(10, 50, 480, 30)
GUICtrlSetData(-1, 100)
; Remove the theme
DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle($hProg_NoTheme), "wstr", 0, "wstr", 0)
GUICtrlSetColor(-1, 0x00FF00)

$hProgressButton = GUICtrlCreateButton("Progress", 10, 90, 80, 30)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hProgressButton
            ; GUICtrlSendMsg($hProg_Theme, $PBM_SETSTATE, $PBST_NORMAL, 0) ; Just to show the green message
            For $i = 100 To 1 Step -1
                GUICtrlSetData($hProg_Theme, $i)
                GUICtrlSetData($hProg_NoTheme, $i)
                Sleep(50)
                Switch $i
                    Case 60
                        GUICtrlSendMsg($hProg_Theme, $PBM_SETSTATE, $PBST_PAUSED, 0)
                        GUICtrlSetColor($hProg_NoTheme, 0xFFFF00)
                    Case 30
                        GUICtrlSendMsg($hProg_Theme, $PBM_SETSTATE, $PBST_ERROR, 0)
                        GUICtrlSetColor($hProg_NoTheme, 0xFF0000)
                EndSwitch
            Next
            ; For some reason Vista requries a double whammy to set it to zero!
            GUICtrlSetData($hProg_Theme, 0)
            GUICtrlSetData($hProg_Theme, 0)
            GUICtrlSetData($hProg_NoTheme, 0)
            GUICtrlSetData($hProg_NoTheme, 0)
            Sleep(50)
    EndSwitch

WEnd

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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