0
votes

I am developing a desktop application using perl Win32::GUI. In that I am using Progress Bar for status identification. I have set maximum level of progress bar as 100. In that I am step up the value as per the length. I have written the sample code below. I am calculating the step up value by dividing 100 to the input length. In that, if the input length is odd number the step value will be float. Hence the progress bar not completed its maximum level completely. For an example, if the length is 11, the step up value will be 9.09. The progress bar takes it as 9 only. So, the progress level completing only 99 segments. Not 100. please share your suggestions.

use strict;
use Win32;
use Win32::GUI;

my $DOS = Win32::GUI::GetPerlWindow();                   
Win32::GUI::Hide($DOS);

my $Upload_win=Win32::GUI::Window->new(
        -name => 'UploadWindow',
        -text => 'SVN-CHIP-Upload-Tool-V2-HurixSystems',
        -left => 375,
        -top  => 400,
        -width =>520,#370,
        -height =>520,
        #-menu =>$Menu,
        -background => [190,190,190],
        -dialogui   => 1,
        -maximizebox => 0,
);

my $ProcessButton=$Upload_win->AddButton(
        -text => 'Upload',
        -name =>  'uploadbut',
        -size => [90,25],
        -pos  =>  [200,360],
        -background =>  [190,190,190],
        -foreground => [],
        -tabstop => 1,
);
my $Progress_bars=$Upload_win->AddProgressBar(
  -pos=>[20,400],
  -background=>[0,255,85],
  -smooth   => 1,
  -size=>[470,20],

);

$Upload_win->Show();
Win32::GUI::Dialog();
Win32::GUI::Hide($DOS);

sub uploadbut_Click{

  $Progress_bars->SetRange(0,100);
  my $x=11;
  my $y=100/$x;
  for(1..$x){
  Win32::GUI::DoEvents() >= 0;
   $Progress_bars->SetStep($y);
   $Progress_bars->StepIt();
   sleep 1;
  }
}
1

1 Answers

2
votes

You could set the length of the progress bar to product of your steps and the step size:

#!perl

use strict;
use Win32;
use Win32::GUI();

my $DOS = Win32::GUI::GetPerlWindow();                   
Win32::GUI::Hide($DOS);

my $Upload_win=Win32::GUI::Window->new(
    -name => 'UploadWindow',
    -text => 'SVN-CHIP-Upload-Tool-V2-HurixSystems',
    -left => 375,
    -top  => 400,
    -width => 520,
    -height =>520,
    -background => [190,190,190],
    -dialogui   => 1,
    -maximizebox => 0,
);

my $ProcessButton=$Upload_win->AddButton(
    -text => 'Upload',
    -name =>  'uploadbut',
    -size => [90,25],
    -pos  =>  [200,360],
    -background =>  [190,190,190],
    -foreground => [],
    -tabstop => 1,
);
my $Progress_bars=$Upload_win->AddProgressBar(
    -pos=>[20,400],
    -background=>[0,255,85],
    -smooth   => 1,
    -size=>[470,20],
);

$Upload_win->Show();
Win32::GUI::Dialog();
Win32::GUI::Hide($DOS);

sub uploadbut_Click{
    my $intended_max = 100;
    my $x = 11;
    my $y = int($intended_max/$x);

    $Progress_bars->SetRange(0,$x*$y);

    for(1 .. $x){
        Win32::GUI::DoEvents();
        $Progress_bars->SetStep($y);
        $Progress_bars->StepIt();
        Win32::Sleep(1000);
    }
}