关于如何修复 QuickBASIC 中的进度条代码的建议

Advice on how to fix a Progress Bar code in QuickBASIC

我有一个问题,希望比我聪明的人能帮助我。

我有这段代码正试图开始工作

SUB ShowProgressBar (FileCount%, NCount%, BarWidth%, BarRow%, BarColum%)

percent = int((Ncount% / FileCount%) * 100)

Locate BarRow%, BarColumn%
Print String$(BarWidth%, Chr$(177))

Locate BarRow%, BarColumn%
Print String$((BarWidth% / 100 * percent), Chr$(178))

Locate BarRow%, (BarColumn% + 12)
Print percent + "%"

我想做的是在屏幕 0 中显示一个文本进度条

所以首先我会打印到屏幕▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒(用于背景)然后这个想法 就是用↓填充进度条,直到处理完成

我无法开始工作的是进度条的实际数学运算

我正在使用的是一个读取 CSV 文件并从中创建 ISAM 数据库的函数(所以它 有 10000000 条或更多条记录)

如果有人能帮我解决这个问题,我将不胜感激,因为我整个周末都在做这个 仍然无法使其正常工作(因为我遇到了流程错误或进度条在屏幕上超过 8-10 行 感谢您提供的任何帮助

安迪

您在屏幕 0 上只能使用 80 列。 如果BarWidth% > 80,你会看到问题。

随心所欲地进行调整,但这应该主要是随心所欲:

Sub ShowProgressBar (FileCount%, NCount%, BarWidth%, BarRow%, BarColumn%)

' Completed = NCount / FileCount
'   Percent = Int(100      * Completed)
'    Filled = Int(BarWidth * Completed)
'
' Filled/BarWidth represents 100% when FileCount/FileCount files have completed.
' Since Completed represents NCount/FileCount, we can mathematically calculate
'
'    Filled/BarWidth = NCount/FileCount
'             Filled = BarWidth * NCount / FileCount
'
' Then you just apply Fix(), Int(), CInt(), CLng(), etc. to get rid of fractions
' (or use a\b to perform integer division instead of regular division with a/b).
'
percent% = (NCount% * 100) \ FileCount%
filled% = (NCount% * BarWidth%) \ FileCount%

Locate BarRow%, BarColumn%
Print String$(filled%, Chr$(178))
Print String$(BarWidth% - filled%, Chr$(177))

' Assuming `BarWidth%=20`:
'
'     ▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒   9%
'     ▓▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒  50%
'     ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ 100%
'
' (Of course, this would be printed on BarRow% only, not multiple lines.
' This was just to illustrate what the line below does.)
'
Print Using " ###%"; percent%

End Sub

另外,一个一般提示:尝试在除法之前先乘法以避免舍入错误。 这并不总是可能的,但最好尽可能利用这个机会。

由于您提到了溢出错误,您可能希望从具有 % 后缀的 16 位整数切换到具有 & 后缀的 32 位长整数:

  • FileCount%FileCount&
  • NCount%NCount&