查看: 78  |  回复: 0
  VB6 原来取Text1.txt这种属性值就算 Visible = False 还是比较耗费时间的
楼主
发表于 2025年6月10日 20:25

modTimeStampToStr.bas这个文件在本网站下载


新建From1(窗体),新建Text1(TextBox,MultiLine选True,ScrollBars选3),Command1-2(按钮CommandButton),代码:

Private i&, strA$, lngTickStartTime&, lngTickEndTime&

Private Sub Command1_Click()
    Text1.Text = "a"

    Text1.Visible = False
    lngTickStartTime = GetTickCount    '获取开始时间 ----------------需要计算时间的代码 V----------------

    For i = 1 To 10000
        Text1.Text = Text1.Text & "a"
    Next
    lngTickEndTime = GetTickCount    '获取结束时间 ----------------需要计算时间的代码 A----------------

    strShow = f_TimeStampToStr(lngTickEndTime - lngTickStartTime, 0)
    Text1.Visible = True
    
    MsgBox "1 使用了" & strShow, vbInformation, "提示"
End Sub

Private Sub Command2_Click()
    Text1.Text = "a"
    strA = Text1.Text

    lngTickStartTime = GetTickCount    '获取开始时间 ----------------需要计算时间的代码 V----------------
    For i = 1 To 10000
        strA = strA & "a"
    Next

    Text1.Text = strA
    lngTickEndTime = GetTickCount    '获取结束时间 ----------------需要计算时间的代码 A----------------
    strShow = f_TimeStampToStr(lngTickEndTime - lngTickStartTime, 0)

    Text1.Visible = True

    MsgBox "2 使用了" & strShow, vbInformation, "提示"
End Sub

Command1_Click运行结果:

34秒656毫秒

Command2_Click运行结果:

78毫秒


您需要登录后才可以回帖 登录 | 立即注册
【本版规则】请勿发表违反国家法律的内容,否则会被冻结账号和删贴。
用户名: 立即注册
密码:
2020-2025 MaNongKu.com