excel - 为什么类型转换不能解决这个 VBA 溢出错误
问题描述
我已经阅读了许多关于 VBA 溢出错误的帖子,但仍然遇到问题。寻求帮助。以下代码片段中的最后一行生成溢出错误。我尝试了很多类型转换,但没有任何效果。
我怀疑的是这在很长一段时间内都很好用。突然之间,它开始失败。可能是由于其他地方发生了变化。我正在努力查看我是否只是有编码错误,或者我的程序是否以某种方式破坏了内存。是否有可能我以错误的方式使用用户类型?我已经使用 VBA 很长时间了,但是自从我使用用户类型以来已经有一段时间了。
最后,我可以在有问题的代码行之前放置一个断点,并在即时窗口中使用 debug.print 执行这个确切的代码。它工作正常。进入代码失败。
希望您能提供任何帮助。谢谢。
顺便说一句,我在 Mac 上运行 MSOffice。
Sub create_3d_data()
Dim iPt As Integer ' point counter
Dim iPoly As Integer ' poly counter
Dim iKeystone As Integer 'keystone counter
Dim theta As Single 'segment angle as we sweep the ring circle
Dim segment_angle As Single, temp As Single
iPt = 0: iPoly = 0: iKeystone = 0
For iRing = 0 To user_ring_count - 1
temp = CSng(User_Rings(iRing).number_of_segments)
segment_angle = 3.14159 * 2# / temp <----- Overflow Error
以下是一些其他定义代码片段:
'in a separate Module in this VBAProject
Type User_Ring
bottom_elevation As Single
thickness As Single
inside_radius As Single
outside_radius As Single
number_of_segments As Integer
offset As Single
edge_length As Single
pattern As String
spacer_size As Single
spacer_color As Long
End Type
和
'in the Declarations section of the same workbook as the troubling code above
Dim User_Segments(10) As User_Segment
Dim User_Rings(30) As User_Ring
Dim user_ring_count as Integer
解决方案
推荐阅读
- json - Spring boot - 如果响应状态为 500/503,用户没有收到响应正文
- apache - Htaccess - 将 Google bot 图像重定向到正确的图像 URL
- reactjs - 为什么 TypeScript 判断 'a' | 'b' 串起来?
- excel - Excel(非VBA):将公式限制在某一行并继续下一列
- jquery - FullCalendar 不会自动呈现日历(JQUERY 向导)?
- mqtt - 在构建时启用了 TLS v1.3 的 mosquitto_pub 上的运行时错误
- python - Python在某些字符串后提取数字
- linux - 如何引用或链接 git 存储库中的文件和文件夹以匹配这些条件?
- javascript - A-frame 不跟踪自定义图像
- java - 如何在 Grails 3.3.11 中访问 src/main/java 中的域类?