我有一个问题,我希望有人比我更聪明,可以帮助我。
我有一段代码,我正在努力去工作。
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数据库(这样它就可以拥有0到10,000,000条或更多的记录)。
如果有人能在这方面帮助我,我会非常感激,因为我花了整个周末的时间,但仍然无法使它正确地工作。我得到溢出错误或进度条超过8-10行在屏幕上。
谢谢你能提供的任何帮助。
发布于 2022-05-27 02:45:29
屏幕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&https://stackoverflow.com/questions/71729942
复制相似问题