Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
楼主: 兰色幻想

[分享] 类模块实例3: 可看到计算过程的计算器

  [复制链接]
发表于 2010-6-19 01:03 | 显示全部楼层

以为会有很长的代码,没想到这么短几句就完成了。

兰版

[em17][em17][em17]
回复

使用道具 举报

发表于 2010-8-24 16:07 | 显示全部楼层

Public WithEvents che As MSForms.CommandButton
Public WithEvents frm As MSForms.UserForm
Private Sub che_click()
    Dim index As Long
    With UserForm3.TextBox1
         index = Val(Mid(che.Name, 14, 10))  '取出checkboxN中的数字N
         If index <> 12 Then
           If dd = True And index < 11 Then
            MsgBox "再次运算需要输入运算符号"
           Else
            mystr = mystr & frm.Controls("CommandButton" & index).Caption
           .Text = mystr
           dd = False
           End If
         End If
    End With
End Sub

兰版,上面这段代码中

mystr = mystr & frm.Controls("CommandButton" & index).Caption

这一句,我改成了这样子,但是没有成功,是不是不支持这种写法呢?

mystr = mystr & frm.che.Caption

我看che和frm都是声明过的啊。

回复

使用道具 举报

 楼主| 发表于 2010-8-25 18:53 | 显示全部楼层

QUOTE:
以下是引用wbzxz在2010-8-24 16:07:00的发言:

Public WithEvents che As MSForms.CommandButton
Public WithEvents frm As MSForms.UserForm
Private Sub che_click()
    Dim index As Long
    With UserForm3.TextBox1
         index = Val(Mid(che.Name, 14, 10))  '取出checkboxN中的数字N
         If index <> 12 Then
           If dd = True And index < 11 Then
            MsgBox "再次运算需要输入运算符号"
           Else
            mystr = mystr & frm.Controls("CommandButton" & index).Caption
           .Text = mystr
           dd = False
           End If
         End If
    End With
End Sub

兰版,上面这段代码中

mystr = mystr & frm.Controls("CommandButton" & index).Caption

这一句,我改成了这样子,但是没有成功,是不是不支持这种写法呢?

mystr = mystr & frm.che.Caption

我看che和frm都是声明过的啊。

che和frm虽然一个是按钮一个是窗体,但他们并没有隶属关系,所以frm.che是错误的。

如果要改,可以这样

mystr = mystr & che.Caption  ‘把frm去掉

回复

使用道具 举报

发表于 2010-8-25 19:01 | 显示全部楼层

越是学得多,越是觉得懂得少。

回复

使用道具 举报

发表于 2010-8-25 23:02 | 显示全部楼层

QUOTE:
以下是引用兰色幻想在2010-8-25 18:53:00的发言:

che和frm虽然一个是按钮一个是窗体,但他们并没有隶属关系,所以frm.che是错误的。

如果要改,可以这样

mystr = mystr & che.Caption  ‘把frm去掉

哦,原来在类模块里面,虽然一个是窗体,一个是按钮,但是它们的隶属关系已经不存在了,是吧,兰版。

回复

使用道具 举报

发表于 2010-9-1 21:25 | 显示全部楼层

下来学习!
回复

使用道具 举报

发表于 2010-9-18 22:09 | 显示全部楼层

vbcbcbc
回复

使用道具 举报

发表于 2010-9-20 18:45 | 显示全部楼层

牛!
回复

使用道具 举报

发表于 2010-10-14 10:40 | 显示全部楼层

好东西,学习!
回复

使用道具 举报

发表于 2010-10-17 21:13 | 显示全部楼层

在这里学习是件快乐的事!
回复

使用道具 举报

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

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-4-27 21:58 , Processed in 0.258836 second(s), 6 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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