Jump to content
Sign in to follow this  
Chimaera

Setting Limits on Progress bar?

Recommended Posts

Chimaera

Ok i have a script with a load of input boxes and as the numbers are added i need a way of showing a simple graph of sorts.

I cannot use excel it has to be within the program itself because they may or may not have installed excel

so i looked at progress bars

$test8 = GUICtrlCreateProgress(130, 70, 40, 500, $PBS_VERTICAL)

Now i want a way to specify that the progress limit will be "0" to "10,000" for eg

now in the loops section it updates the bar with

GUICtrlSetData($test8, $nIncome_Sub0); income sub is the subtotal of the page

But because the bar is physically 500 long as soon as you surpass 500 at the subtotal its maxed the bar

So is there a way to set the limit of the progress bar more than its physical limitations?

Thanks for any help

Chimaera

Edited by Chimaera

Share this post


Link to post
Share on other sites
Melba23

Chimaera,

As far as I know you can only set a Progress control between 0 and 100. So you will have to do some basic maths to get your value in that range. It is basically the percentage of the max value you set:

Max = 5000 ... Value = 1500 ... Setting = 1500 / 5000 * 100 = 30

So GUICtrlSetData($hProgress, 30) would get you a suitably sized bar.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
Chimaera

Thanks M23 i had tried a similar thing but not taken the math far enough to make a difference

$income_down = $nIncome_Sub0 /10000 * 100 
ConsoleWrite($income_down & @CRLF) 
GUICtrlSetData($test8, $income_down)

This seems to work quite nicely thanks again

I had origanally wanted to do it using a button but could not find a way to make it refresh the height parameter on the create button so i switched to progress

Chimaera

Edited by Chimaera

Share this post


Link to post
Share on other sites
JoHanatCent

I had origanally wanted to do it using a button but could not find a way to make it refresh the height parameter on the create button so i switched to progress

One way to do it with a button:

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Dim $Button1, $Button2, $Minimum = 0, $Maximum = 10000
Example1()
Func Example1()
    Local $msg
    GUICreate("Progress", @DesktopWidth / 4, @DesktopHeight, @DesktopWidth / 4, 0, $WS_POPUP)
    $Button1 = GUICtrlCreateButton("", 0, @DesktopHeight, 50, 1)
    GUICtrlSetBkColor(-1, 0xff0000)
    $Button2 = GUICtrlCreateButton("Start", 50, 10, 50, 50)
    GUISetState(@SW_SHOW)
    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $Button1
                MsgBox(0, '', 'You clicked on the progress button', 5)
            Case $Button2
                _Progressing()
        EndSwitch
    WEnd
    GUIDelete()
EndFunc   ;==>Example1

Func _Progressing()
    For $2 = $Minimum  To $Maximum
        $1 = (@DesktopHeight / $Maximum) * $2
        GUICtrlSetData($Button1, $2)
        GUICtrlSetPos($Button1, 0, @DesktopHeight - $1, 50, $1)
        ;Sleep(20)
    Next
EndFunc   ;==>_Progressing

Share this post


Link to post
Share on other sites
Chimaera

Interesting JoHanatCent, thanks for that

@M23

I resolved the progress sizing for unpredictable amounts of numbers like this in the end

Select
                    Case $nIncome_Sub0 <= 1000
                        $income_down = $nIncome_Sub0 / 1100 * 100
                        $global_down = $nIncome_Total_2 / 1100 * 100
                    Case $nIncome_Sub0 <= 2000
                        $income_down = $nIncome_Sub0 / 2100 * 100
                        $global_down = $nIncome_Total_2 / 2100 * 100
                    Case $nIncome_Sub0 <= 3000
                        $income_down = $nIncome_Sub0 / 3100 * 100
                        $global_down = $nIncome_Total_2 / 3100 * 100
                    Case $nIncome_Sub0 <= 4000
                        $income_down = $nIncome_Sub0 / 4100 * 100
                        $global_down = $nIncome_Total_2 / 4100 * 100
                    Case $nIncome_Sub0 <= 5000
                        $income_down = $nIncome_Sub0 / 5100 * 100
                        $global_down = $nIncome_Total_2 / 5100 * 100
                    Case $nIncome_Sub0 <= 6000
                        $income_down = $nIncome_Sub0 / 6100 * 100
                        $global_down = $nIncome_Total_2 / 6100 * 100
                    Case $nIncome_Sub0 <= 7000
                        $income_down = $nIncome_Sub0 / 7100 * 100
                        $global_down = $nIncome_Total_2 / 7100 * 100
                    Case $nIncome_Sub0 <= 8000
                        $income_down = $nIncome_Sub0 / 8100 * 100
                        $global_down = $nIncome_Total_2 / 8100 * 100
                    Case $nIncome_Sub0 <= 9000
                        $income_down = $nIncome_Sub0 / 9100 * 100
                        $global_down = $nIncome_Total_2 / 9100 * 100
                    Case $nIncome_Sub0 <= 10000
                        $income_down = $nIncome_Sub0 / 10100 * 100
                        $global_down = $nIncome_Total_2 / 10100 * 100
                    Case Else
                        $income_down = $nIncome_Sub0 / 10500 * 100
                        $global_down = $nIncome_Total_2 / 10500 * 100
                EndSelect
                    GUICtrlSetData($income_prog, $income_down)
                    GUICtrlSetData($expend_prog, $global_down)

Basically so it adjusts itself to accommodate more data

Thanks for the help

Chimaera

Share this post


Link to post
Share on other sites
Melba23

Chimaera,

You could simplify that quite a bit - try running this and you will see that the results are the same: :)

; Set a HotKey to exit
HotKeySet("{ESC}", "On_Exit")

; Set a value equal to the max for $nIncome_Sub0
Global $nIncome_Total_2 = 20000

While 1

    ; Pick a random value for nIncome_Sub0
    $nIncome_Sub0 = Random(100, 10000, 1)

    ; Chimaera's code
    Select
        Case $nIncome_Sub0 <= 1000
            $income_down = $nIncome_Sub0 / 1100 * 100
            $global_down = $nIncome_Total_2 / 1100 * 100
        Case $nIncome_Sub0 <= 2000
            $income_down = $nIncome_Sub0 / 2100 * 100
            $global_down = $nIncome_Total_2 / 2100 * 100
        Case $nIncome_Sub0 <= 3000
            $income_down = $nIncome_Sub0 / 3100 * 100
            $global_down = $nIncome_Total_2 / 3100 * 100
        Case $nIncome_Sub0 <= 4000
            $income_down = $nIncome_Sub0 / 4100 * 100
            $global_down = $nIncome_Total_2 / 4100 * 100
        Case $nIncome_Sub0 <= 5000
            $income_down = $nIncome_Sub0 / 5100 * 100
            $global_down = $nIncome_Total_2 / 5100 * 100
        Case $nIncome_Sub0 <= 6000
            $income_down = $nIncome_Sub0 / 6100 * 100
            $global_down = $nIncome_Total_2 / 6100 * 100
        Case $nIncome_Sub0 <= 7000
            $income_down = $nIncome_Sub0 / 7100 * 100
            $global_down = $nIncome_Total_2 / 7100 * 100
        Case $nIncome_Sub0 <= 8000
            $income_down = $nIncome_Sub0 / 8100 * 100
            $global_down = $nIncome_Total_2 / 8100 * 100
        Case $nIncome_Sub0 <= 9000
            $income_down = $nIncome_Sub0 / 9100 * 100
            $global_down = $nIncome_Total_2 / 9100 * 100
        Case $nIncome_Sub0 <= 10000
            $income_down = $nIncome_Sub0 / 10100 * 100
            $global_down = $nIncome_Total_2 / 10100 * 100
        Case Else
            $income_down = $nIncome_Sub0 / 10500 * 100
            $global_down = $nIncome_Total_2 / 10500 * 100
    EndSelect

    ; M23's code
    $iFactor = 1 + Int($nIncome_Sub0 / 1000)
    $income_down_M23 = $nIncome_Sub0 / (($iFactor * 1000) + 100) * 100
    $global_down_M23 = $nIncome_Total_2 / (($iFactor * 1000) + 100) * 100
    
    ; Compare the results of the 2 calculations
    ConsoleWrite($nIncome_Sub0 & ": [" & $income_down & " - " & $income_down_M23 & "] - [" & $global_down & " - " & $global_down_M23 & "]" & @CRLF)

    ; Time to see them
    Sleep(500)

WEnd

Func On_Exit()
    Exit
EndFunc

Saves wear and tear on the typing fingers. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
Chimaera

Damn i thought i was doing good there, i was up till 2am doing that ..

Ill have a look at yours later, to me its complicated

You have to remember though my skills are limited, for me to come up with variable graphs in the first place was good lol

Thanks

Edited by Chimaera

Share this post


Link to post
Share on other sites
Melba23

Chimaera,

its complicated

Then let me explain a bit.

You are checking if the value against increasing thousands - that is what I am doing with the $iFactor = 1 + Int($nIncome_Sub0 / 1000) line, getting the number of thousands within it. Then you do the calculations using [successive thousands + 100] as part of the formula - all I do is use the factor calculated above to work out which [thousand + 100] we should use:

$nIncome_Sub0  $nIncome_Sub0 / 1000   Int($nIncome_Sub0 / 1000)   1 + Int($nIncome_Sub0 / 1000)   ($iFactor * 1000) + 100
                                                                        ( = $iFactor)

500            0.5                    0                           1                               (1 * 1000) + 100 = 1100

1500           1.5                    1                           2                               (2 * 1000) + 100 = 2100

2500           2.5                    2                           3                               (3 * 1000) + 100 = 3100

Does that make it easier to follow? :)

Top Tip: If you find yourself coding multiple repeated lines of code with only a simple difference in the numbers used, there is nearly always a way to make it shorter using an algorithm of some sort. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
Chimaera

With a bit of tweaking i ended up with this so it shows lower amounts more clearly, ie higher bar and changes up more often.

$iFactor = 1 + Int($nIncome_Sub0 / 250)
    $income_down = $nIncome_Sub0 / (($iFactor * 250) + 50) * 100
    $global_down = $nIncome_Total_2 / (($iFactor * 250) + 50) * 100

At least thats what it seems to do one question though

The graph bars are related one income the other expenditure

As it stands now if income moves to for eg 250 it then lowers the bar which is right

But if Expenditure reaches 250 it doesn't reduce the bar

$iFactor = 1 + Int($nIncome_Sub0 / 250)
$iFactor2 = 1 + Int($nIncome_Total_2 / 1000)
    $income_down = $nIncome_Sub0 / (($iFactor * 250) + 50) * 100
    $global_down = $nIncome_Total_2 / (($iFactor2 * 250) + 50) * 100

This example lowers them correctly but on their own

This is because they work from different calculations as per this eg

Is there a way to make it reduce both bars together from either side that hits the 250 limit?

Chimaera

Edited by Chimaera

Share this post


Link to post
Share on other sites
Melba23

Chimaera,

On first glance you are guaranteed to have a problem with the code you posted as you are getting the factor for $nIncome_Total_2 based on a divisor of 1000 - and then making the calculation of the percentage using a multiplicand of 250. Try adjusting that first. ;)

$iFactor = 1 + Int($nIncome_Sub0 / 250)
$iFactor2 = 1 + Int($nIncome_Total_2 / 1000)
    $income_down = $nIncome_Sub0 / (($iFactor * 250) + 50) * 100
    $global_down = $nIncome_Total_2 / (($iFactor2 * 250) + 50) * 100 ; Change the 250 to 1000 <<<<<<<<<<<<<<<<<<<<<<<<<

Expenditure reaches 250 it doesn't reduce the bar

I can only see 2 variables with Income in their titles - where does Expenditure come into the equation. :)

If you want more focused help, I would suggest posting a reproducer script with some data to make it (mis)behave - it is almost impossible to make sensible suggestions with only a few lines to go on. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.