首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >关于如何在QuickBASIC中修复进度条形码的建议

关于如何在QuickBASIC中修复进度条形码的建议
EN

Stack Overflow用户
提问于 2022-04-03 21:20:54
回答 1查看 34关注 0票数 1

我有一个问题,我希望有人比我更聪明,可以帮助我。

我有一段代码,我正在努力去工作。

代码语言:javascript
复制
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行在屏幕上。

谢谢你能提供的任何帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-05-27 02:45:29

屏幕0上只有80列可处理。如果是BarWidth% > 80,您将看到问题。

调整你想做的事情,但是这主要是做你想做的事情:

代码语言:javascript
复制
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&
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71729942

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档