Can you change a progress bars total from 100 to something else?

PharCyDeD

Active Member
Licensed User
Longtime User
Basically, as the title states...is it possible to change the progressbar's total from 100 to something high or lower? For instance, if I run a 60 second timer with a progress bar it starts at 60 of 100 when I want it to be "full" at 60.
 

timwil

Active Member
Licensed User
Longtime User
you can do the adjustment to make 60 = 100

ie


100 x n /60 where n = current value so when n = 60 then (100 x 60 / 60 = 100)
 
Last edited:
Upvote 0

PharCyDeD

Active Member
Licensed User
Longtime User
Hm, I don't understand how to use this within my program? :confused:

If I am using a progress bar as a visual timer then how would this work?
 
Upvote 0

timwil

Active Member
Licensed User
Longtime User
B4X:
   for n = 0 to 60
      progressbar1.value = (100 * n) / 60
   next

This should show the progress bar going from 0 to 100%
 
Upvote 0

joseluis

Active Member
Licensed User
Longtime User
This is a practical application of the rule of three.
You have a timer that goes from 0 to 60, and you want to represent that in a bar that goes from 0 to 100. So you apply the rule like this:

If 60 (your max original value) is translated to 100 (the max progressbar value), then original value X is translated to X*100/60. (check it. For example, If X is 30, it should give 50 in the bar)

EDIT: Also, what timwil says with less words :)
 
Upvote 0

PharCyDeD

Active Member
Licensed User
Longtime User
Thanks for helping a :sign0104:. If I want it to tick backwards would I do this:

B4X:
Sub Timer1_tick
 
for n = 60 to 0
      progressbar1.value = (100 * n) / 60
 next

End Sub
 
Upvote 0

timwil

Active Member
Licensed User
Longtime User
Thanks for helping a :sign0104:. If I want it to tick backwards would I do this:

B4X:
Sub Timer1_tick
 
for n = 60 to 0 [COLOR="Red"]step -1[/COLOR]
      progressbar1.value = (100 * n) / 60
 next

End Sub

you left out the step -1 to make it count backwards
 
Upvote 0

PharCyDeD

Active Member
Licensed User
Longtime User
Just in case someone comes along to seek this answer and find this thread this is how I worked it out (with the help of the above posters!)

Globals:

B4X:
Dim TheTime as Int
TheTime = 60 'or whatever you want the time to be set at but make sure to set it again when needed throughout the program

Timer:
B4X:
Sub Timer_Tick
pbTimeLeft.Progress = (100 * TheTime) / 60
TheTime = TheTime - 1
End Sub



**Edit: or open the nice sample NJ provided :)
 
Last edited:
Upvote 0

NJDude

Expert
Licensed User
Longtime User
To avoid doing that, you could also define a Max variable, so, you only change 1 value, something like this:
B4X:
Dim TheTime As Int
Dim tMax As Int

TheTime = 60
tMax = TheTime

...
...
Sub Timer_Tick

    pbTimeLeft.Progress = (100 * TheTime) / tMax
    TheTime = TheTime - 1

End Sub

I forgot to add that to my sample code.
 
Last edited:
Upvote 0
Top