ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
12
返回列表 发新帖
楼主: xiamen168

[原创] [EXCEL VBA]给VBA加速之Integer和Long的使用技巧

[复制链接]

TA的精华主题

TA的得分主题

发表于 2013-11-14 23:07 | 显示全部楼层
本帖已被收录到知识树中,索引项:数据类型和基本语句
有点将VBA学术研究了,推荐VBA版的DataBus的精华贴

TA的精华主题

TA的得分主题

发表于 2014-4-1 09:32 | 显示全部楼层
Sub Doint()

Const myMAX As Integer = 32767
Const myMIN As Integer = -32768
Dim i As Integer
Dim 加法 As Integer
Dim 减法 As Integer
Dim 乘法 As Integer
Dim 除法 As Integer
Dim 求余 As Integer
Dim cnt As Integer
Dim start As Double
start = Timer

'循环100次
For cnt = 1 To 1000
For i = myMIN + 1 To myMAX - 1
加法 = i + 1
减法 = i - 1
乘法 = i * 1
除法 = i / 1
求余 = i Mod 1
Next i
Next cnt
MsgBox "程序运行时间为:   " & Format(Timer - start, "0.00") & "  秒"
End Sub

Sub Dolong()
Const myMAX As Long = 32767
Const myMIN As Long = -32768
Dim i As Long
Dim 加法 As Long
Dim 减法 As Long
Dim 乘法 As Long
Dim 除法 As Long
Dim 求余 As Long
Dim cnt As Long
Dim start As Double
start = Timer


'循环100次
For cnt = 1 To 1000
For i = myMIN - 1 To myMAX - 1
加法 = i + 1
减法 = i - 1
乘法 = i * 1
除法 = i / 1
求余 = i Mod 1
Next i
Next cnt
MsgBox "程序运行时间为:   " & Format(Timer - start, "0.00") & "  秒"

End Sub
本人实测在64位Win8情况下运行1000次分别为3.22秒和3.19秒,区别不大

TA的精华主题

TA的得分主题

发表于 2015-3-16 11:14 | 显示全部楼层
win7-64  office-64 lint/long=1.5左右

TA的精华主题

TA的得分主题

发表于 2017-3-9 13:35 | 显示全部楼层
本帖最后由 mooncold 于 2017-3-9 13:36 编辑

Sub Doint()

Const myMAX As Integer = 32767
Const myMIN As Integer = -32768
Dim i As Integer
Dim 加法 As Integer
Dim 减法 As Integer
Dim 乘法 As Integer
Dim 除法 As Integer
Dim 求余 As Integer
Dim cnt As Integer
Dim start As Double
start = Timer

'循环100次
For cnt = 1 To 1000
For i = myMIN + 1 To myMAX - 1
加法 = i + 1
减法 = i - 1
乘法 = i * 1
除法 = i / 1
求余 = i Mod 1
Next i
Next cnt
MsgBox "程序运行时间为:   " & Format(Timer - start, "0.00") & "  秒"
End Sub

Sub Dolong()
Const myMAX As Long = 32767
Const myMIN As Long = -32768
Dim i As Long
Dim 加法 As Long
Dim 减法 As Long
Dim 乘法 As Long
Dim 除法 As Long
Dim 求余 As Long
Dim cnt As Long
Dim start As Double
start = Timer


'循环100次
For cnt = 1 To 1000
For i = myMIN - 1 To myMAX - 1
加法 = i + 1
减法 = i - 1
乘法 = i * 1
除法 = i / 1
求余 = i Mod 1
Next i
Next cnt
MsgBox "程序运行时间为:   " & Format(Timer - start, "0.00") & "  秒"

End Sub

=============================================
win10 64位, office 365 32位,运行的结果:
Int : 3.96sec
Long: 3.47sec
差别不明显啊,14%左右吧。

TA的精华主题

TA的得分主题

发表于 2018-7-14 15:30 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
win7-64  office-32
1000
Int = 2.66sec
long=2.76sec
10000
Int = 26.09sec
long=27.35sec

TA的精华主题

TA的得分主题

发表于 2020-10-4 10:21 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
xpsp3 office2010
Doint 2.34
Dolong 2.45
Donone 2.63

Sub Doint()

Const myMAX As Integer = 32767
Const myMIN As Integer = -32768
Dim i As Integer
Dim 加法 As Integer
Dim 减法 As Integer
Dim 乘法 As Integer
Dim 除法 As Integer
Dim 求余 As Integer
Dim cnt As Integer
Dim start As Double
start = Timer

'循环100次
For cnt = 1 To 1000
For i = myMIN + 1 To myMAX - 1
加法 = i + 1
减法 = i - 1
乘法 = i * 1
除法 = i / 1
求余 = i Mod 1
Next i
Next cnt
MsgBox "程序运行时间为:   " & Format(Timer - start, "0.00") & "  秒"
End Sub

Sub Dolong()
Const myMAX As Long = 32767
Const myMIN As Long = -32768
Dim i As Long
Dim 加法 As Long
Dim 减法 As Long
Dim 乘法 As Long
Dim 除法 As Long
Dim 求余 As Long
Dim cnt As Long
Dim start As Double
start = Timer


'循环100次
For cnt = 1 To 1000
For i = myMIN - 1 To myMAX - 1
加法 = i + 1
减法 = i - 1
乘法 = i * 1
除法 = i / 1
求余 = i Mod 1
Next i
Next cnt
MsgBox "程序运行时间为:   " & Format(Timer - start, "0.00") & "  秒"

End Sub


Sub Donone()
myMAX = 32767
myMIN = -32768
Dim i As Long
Dim 加法 As Long
Dim 减法 As Long
Dim 乘法 As Long
Dim 除法 As Long
Dim 求余 As Long
Dim cnt As Long
Dim start As Double
start = Timer


'循环100次
For cnt = 1 To 1000
For i = myMIN - 1 To myMAX - 1
加法 = i + 1
减法 = i - 1
乘法 = i * 1
除法 = i / 1
求余 = i Mod 1
Next i
Next cnt
MsgBox "程序运行时间为:   " & Format(Timer - start, "0.00") & "  秒"

End Sub

TA的精华主题

TA的得分主题

发表于 2021-4-21 14:41 | 显示全部楼层
hqswww 发表于 2012-7-9 19:47
Private Sub CommandButton1_Click()
Const ma As Long = 30000
Const mi As Long = -30000

Dim p%
感觉这个变量会溢出呢

TA的精华主题

TA的得分主题

发表于 2023-2-8 10:12 | 显示全部楼层
VB 中 integer 范围是-32768 ~ 32767

dd.jpg

  1. '''
  2. Sub deldel11()
  3.    

  4.    Dim oNum As Integer, oSum As Integer
  5.    
  6.    Dim ii, jj, Kk
  7.    Dim TabRow, TabCol, sTabRow, sTabCol     ''
  8.         sTabRow = 1
  9.         sTabCol = 1
  10.         TabRow = 20
  11.         TabCol = 2
  12.         oSum = sTabCol
  13.         ''
  14.         ''
  15.         For Kk = 1 To 60
  16.             For ii = sTabRow To sTabRow + TabRow
  17.                  For jj = sTabCol To TabCol + sTabCol
  18.                        oNum = oNum + 1
  19.                        oSum = oSum + oNum
  20.                        Debug.Print oNum, Kk, ii, jj, oSum
  21.                  Next jj
  22.             Next ii
  23.         Next Kk

  24. End Sub
复制代码



您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-11-19 10:29 , Processed in 0.035873 second(s), 8 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表