Console tricks


Author: Dave
Date: 09.26.19 - 9:27am



I never had the occasion to write a console progress bar until today. Was actually really easy..
Global blocks As Long 
Global block As Long
Global curPBVal As Long

Con.Write "["
for block = 0 to blocks
  'do stuff
  progressCallBack
next
Con.Write "]"

Sub progressCallBack()
    On Error Resume Next
    Dim curOf20 As Long
    
    'we display progress scale 1-20
     curOf20 = (20 * block) / blocks
     If curOf20 > curPBVal Then
        Con.WriteLine String(curOf20 - curPBVal, "-"), False
        curPBVal = curOf20
     End If
  
End Sub


From some old C code, I did have a % complete that would constantly update:

printf("Percent Complete:    ");

for(i=opts.offset; i < opts.size ; i++){
   if(i%10==0){
      int pcent = (100*i)/opts.size;
      printf("\b\b\b%02d%%", pcent);
      fflush(stdout);
   }
}


Somewhere I even have of those -\|/- console star spinners in C but I cant remember where I used it. here is one i ripped from the web for storage (untested)

void
spinner(int spin_seconds) {
    static char const spin_chars[] = "/-\|";
    unsigned long i, num_iterations = (spin_seconds * 10);
    for (i=0; i<num_iterations; ++i) {
        putchar(spin_chars[i % sizeof(spin_chars)]);
        fflush(stdout);
        usleep(100000);
        putchar('\b');
    }
}





Comments: (0)

 
Leave Comment:
Name:
Email: (not shown)
Message: (Required)
Math Question: 11 + 67 = ? followed by the letter: O 



About Me
More Blogs
Main Site
Posts: (All)
2024 ( 1 )
2023 ( 9 )
2022 ( 4 )
2021 ( 2 )
2020 ( 4 )
2019 (5)
     Console tricks
     FireFox temp dir
     OCX License
     Extract substring
     VB6 Console Apps
2018 (6)
     VB6 UDTs
     VB6 Debugger View As Hex tooltips
     VB6 - C Share registry data
     VB6 Addin Missing Menus
     VB6 Class Init Params
     VB6 isIn function
2017 (6)
     Python and VB6
     Python pros and cons
     download web Dir
     vc rand in python
     VB6 Language Enhancement
     Register .NET as COM
2016 ( 22 )
2015 ( 15 )
2014 ( 25 )
2013 ( 4 )
2012 ( 10 )
2011 ( 7 )
2010 ( 11 )
2009 ( 3 )