Progress Bar Issue

Hi All

I have two text fields and one progress bar. I have a submit button with the following code:

  dim bottom as Double
  
  bottom = val(TextField1.Text)
  
  dim top as Double
  
  top = val(TextField2.Text)
  
  ProgressBar1.Maximum = top
  ProgressBar1.Value = bottom
  ProgressBar1.Refresh

i have used double as i assumed because i want to work with decimals i needed too.

I have an issue with how the progress bar is working:

If i set

Top as: 13.8
Bottom as 12.14

Then the progress bar works. If however i changed the bottom to 12.1 the progress bar doesn’t shirt at all - which i though it would.

Im trying to make a progress bar for weight. There are 14 pounds to 1 stone.

i’ve also tried this way (which i think is the long way of above)

  dim bottom as String
  dim bottomcalc as Integer
  
  bottom = TextField1.Text
  bottomcalc = CDbl (bottom)
  
  dim top as String
  dim topcalc as Integer
  
  top = TextField2.Text
  topcalc = CDbl (top)
  
  ProgressBar1.Maximum = topcalc
  ProgressBar1.Value = bottomcalc
  ProgressBar1.Refresh

even tried

  dim bottom as double
  
  bottom = val(TextField1.Text)
  
  dim top as Double
  
  top = val(TextField2.Text)
  
  dim theresult as double
  
  theresult = bottom/ top * 100
  
  ProgressBar1.Maximum = 100
  ProgressBar1.Value = theresult
  ProgressBar1.Refresh

Bottom 12.14 goes over top of 13.8

Your first example is doing what I would expect based on your code. What is it you are trying to accomplish? What do you expect to happen?

Hey Paul

  dim target as double
  
  target = val(TextField1.Text)  // 10.8 set text  (set value of 10 Stone, 8 lb)  The Target Weight The Person wants to be at
  
  
  
  dim startfat as Double
  
  startfat = val(TextField2.Text)  // 13.8 set text  (Set value of 13 stone,8 lb) The Start weight of the person
  
  
  
  dim currentweight as Double
  
  currentweight = val(TextField3.Text)  //13.4 set text (Set value of 13 stone, 4 lb) The Current weight of the person
  
  
  
  dim theresult as double
  
  
  theresult = startfat - currentweight //  13.8  - 13.4 (math)    Finding the Difference between the start weight and the current weight
  
  dim thesum as Double
  
  thesum = startfat - theresult  // 13.8 - 0.4 (math)  Taking the difference and removing it from the start weight
   
 
  
  ProgressBar1.Maximum = startfat // 13.8 (Math) - maximim value 13.8 (as this is the max weight)
  
  ProgressBar1.Value = thesum   //  13.4 (Math)  

/// Trying to make the progress bar go down to the target weight of 10.8
  
  ProgressBar1.Refresh
  

In a nut shell

Max weight set
Current weight entered
Target weight set

And all i want to do is make the progress bar show the correct percentage that the user is to their goal weight.

e.g. if they where 12.3 They would be 50% of the way to their goal

I don’t think you can use decimal values with Progressbar. Convert your numbers to a percent expressed as an integer between 0 and 100. You’ll have a lot better result.

That’s true: Value, Maximum and Minimum are all Integers.

Also, your stone/pound values are not decimal either, so you’ll want to convert them properly. For example 1 stone and 7 pounds is actually 1.5 stone, not 1.7 stone.

Hey Tim

  dim target as double
  
  target = val(TextField1.Text)  // 10.8 set text
  
  
  
  dim startfat as Double
  
  startfat = val(TextField2.Text)  // 13.8 set text
  
  
  
  dim currentweight as Double
  
  currentweight = val(TextField3.Text)  //13.4 set text
  
  
  
  dim theresult as double
  
  
  theresult = startfat - currentweight //  13.8  - 13.4 (math)
  
  dim thesum as Double
  
  thesum = startfat - theresult  // 13.8 - 0.4 (math)
  
  //// Setting the Percent
  
  dim overal as Double
  
  overal = thesum / startfat * 100
  
  ///////////////////
  
  ProgressBar1.Maximum = startfat // 13.8 (Math)
  
  ProgressBar1.Value = overal   //  13.4 (Math)
  
  ProgressBar1.Refresh
  

Overal (variable) works out at 97% but does not update the progress chart correct. Setting the Max to 100 fixes this, but then if you where to reach you 12.8 goal progress bar does not reach 0

There is NO Progressbar.Min or ProgressBar.Minimum that i can find

You can also just multiply the maximum and value of the progressbar by 10. Then you’ll have a max of 138 and value of 134. The conversion from double to integer is going to round the values and looks like I’m seeing a max of 13 and value of 13. (I would expect a max of 14?)

ProgressBar1.Maximum = startfat * 10 // 138

ProgressBar1.Value = thesum * 10 // 134

You’re right. That’ll teach me to go from memory.

is there anyway to declare the minimum?

I can only see the option for max

If i could declare the min as the target and the max as the starting weight then the percentage of the current weight should be easy to do….

Change ProgressBar1.Maximum = startfat to ProgressBar1.Maximum = 100

There is no minimum value. A progressbar goes from zero to the maximum you set.

Hey Tim

If i set a Min of say 3 and progress bar value returned was say 0.4 , can i safely assume that because it is not whole figure that it (progress bar value) is going to take that as a 0 and show nothing?

Cheers

I just put together a simple Progressbar Subclass that has a minimum and accepts doubles for the maximum and value… similar to something I’ve used in the past. If you like, I’ll share it. It simplifies your code to

ProgressBar1.Minimum = val(TextField1.Text) ProgressBar1.Maximum = val(TextField2.Text) ProgressBar1.Value = val(TextField3.Text)
It’s only a few lines of code, but something I wanted to have handy in the future.

In case anyone’s interested…
DoubleProgressBarWithMinimum.xojo_xml_code