Console tricksAuthor: 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) |
About Me More Blogs Main Site
|
|||||||||||||||||||||||||||||||||